pub fn bind(addr: VsockAddr, backlog: std::os::raw::c_int) -> io::Result<Self> {
        let fd = unsafe { libc::socket(libc::AF_VSOCK, libc::SOCK_STREAM, 0) };
        if fd < 0 {
            return Err(io::Error::last_os_error());
        }

        let mut sa = libc::sockaddr_vm {
            svm_family: libc::AF_VSOCK as libc::sa_family_t,
            svm_cid: addr.cid,
            svm_port: addr.port,
            svm_reserved1: 0,
            svm_zero: [0u8; 4],
        };
        let mut rc = unsafe {
            libc::bind(
                fd,
                &mut sa as *mut _ as *mut libc::sockaddr,
                size_of::<libc::sockaddr_vm>() as u32,
            )
        };
        if rc < 0 {
            let err = io::Error::last_os_error();
            unsafe { libc::close(fd) };
            return Err(err);
        }
        rc = unsafe { libc::listen(fd, backlog) };
        if rc < 0 {
            let err = io::Error::last_os_error();
            unsafe { libc::close(fd) };
            return Err(err);
        }
        Ok(Self { fd })
    }
/// Create and return a VsockListener that is bound to `addr` and ready to
/// accept client connections.
Create and return a VsockListener that is bound to `addr` and ready to
accept client connections.
Create and return a VsockListener that is bound to ` addr ` and ready to accept client connections .
pub fn bind(addr: VsockAddr, backlog: std::os::raw::c_int) -> io::Result<Self> {
        let fd = unsafe { libc::socket(libc::AF_VSOCK, libc::SOCK_STREAM, 0) };
        if fd < 0 {
            return Err(io::Error::last_os_error());
        }
        let mut sa = libc::sockaddr_vm {
            svm_family: libc::AF_VSOCK as libc::sa_family_t,
            svm_cid: addr.cid,
            svm_port: addr.port,
            svm_reserved1: 0,
            svm_zero: [0u8; 4],
        };
        let mut rc = unsafe {
            libc::bind(
                fd,
                &mut sa as *mut _ as *mut libc::sockaddr,
                size_of::<libc::sockaddr_vm>() as u32,
            )
        };
        if rc < 0 {
            let err = io::Error::last_os_error();
            unsafe { libc::close(fd) };
            return Err(err);
        }
        rc = unsafe { libc::listen(fd, backlog) };
        if rc < 0 {
            let err = io::Error::last_os_error();
            unsafe { libc::close(fd) };
            return Err(err);
        }
        Ok(Self { fd })
    }
pub fn bind ( addr : VsockAddr , backlog : std :: os :: raw :: c_int ) -> io :: Result < Self > { let fd = unsafe { libc :: socket ( libc :: AF_VSOCK , libc :: SOCK_STREAM , 0 ) } ; if fd < 0 { return Err ( io :: Error :: last_os_error ( ) ) ; } let mut sa = libc :: sockaddr_vm { svm_family : libc :: AF_VSOCK as libc :: sa_family_t , svm_cid : addr . cid , svm_port : addr . port , svm_reserved1 : 0 , svm_zero : [ 0u8 ; 4 ] , } ; let mut rc = unsafe { libc :: bind ( fd , & mut sa as * mut _ as * mut libc :: sockaddr , size_of :: < libc :: sockaddr_vm > ( ) as u32 , ) } ; if rc < 0 { let err = io :: Error :: last_os_error ( ) ; unsafe { libc :: close ( fd ) } ; return Err ( err ) ; } rc = unsafe { libc :: listen ( fd , backlog ) } ; if rc < 0 { let err = io :: Error :: last_os_error ( ) ; unsafe { libc :: close ( fd ) } ; return Err ( err ) ; } Ok ( Self { fd } ) }
Create and return a VsockListener that is bound to `addr` and ready to
accept client connections.
Create and return a VsockListener that is bound to ` addr ` and ready to accept client connections .
addr
VsockAddr
backlog
std::os::raw::c_int
addr
VsockAddr
backlog
std::os::raw::c_int