fn compare_sockname_peername(
    fd_sockname: libc::c_int,
    fd_peername: libc::c_int,
) -> Result<(), String> {
    let mut sockname_addr = libc::sockaddr_in {
        sin_family: 123u16,
        sin_port: 456u16.to_be(),
        sin_addr: libc::in_addr {
            s_addr: 789u32.to_be(),
        },
        sin_zero: [1; 8],
    };

    {
        let mut size = std::mem::size_of_val(&sockname_addr) as u32;
        let rv = unsafe {
            libc::getsockname(
                fd_sockname,
                &mut sockname_addr as *mut libc::sockaddr_in as *mut libc::sockaddr,
                &mut size as *mut libc::socklen_t,
            )
        };
        assert_eq!(rv, 0);
        assert_eq!(size, std::mem::size_of_val(&sockname_addr) as u32);
    }

    let mut peername_addr = libc::sockaddr_in {
        sin_family: 321u16,
        sin_port: 654u16.to_be(),
        sin_addr: libc::in_addr {
            s_addr: 987u32.to_be(),
        },
        sin_zero: [2; 8],
    };

    {
        let mut size = std::mem::size_of_val(&peername_addr) as u32;
        let rv = unsafe {
            libc::getpeername(
                fd_peername,
                &mut peername_addr as *mut libc::sockaddr_in as *mut libc::sockaddr,
                &mut size as *mut libc::socklen_t,
            )
        };
        assert_eq!(rv, 0);
        assert_eq!(size, std::mem::size_of_val(&peername_addr) as u32);
    }

    sockaddr_check_equal(
        &sockname_addr,
        &peername_addr,
        /* ignore_port= */ false,
    )
}
/// Run getsockname on one fd and getpeername on another fd, and make sure they match.
Run getsockname on one fd and getpeername on another fd, and make sure they match.
Run getsockname on one fd and getpeername on another fd and make sure they match .
fn compare_sockname_peername(
    fd_sockname: libc::c_int,
    fd_peername: libc::c_int,
) -> Result<(), String> {
    let mut sockname_addr = libc::sockaddr_in {
        sin_family: 123u16,
        sin_port: 456u16.to_be(),
        sin_addr: libc::in_addr {
            s_addr: 789u32.to_be(),
        },
        sin_zero: [1; 8],
    };
    {
        let mut size = std::mem::size_of_val(&sockname_addr) as u32;
        let rv = unsafe {
            libc::getsockname(
                fd_sockname,
                &mut sockname_addr as *mut libc::sockaddr_in as *mut libc::sockaddr,
                &mut size as *mut libc::socklen_t,
            )
        };
        assert_eq!(rv, 0);
        assert_eq!(size, std::mem::size_of_val(&sockname_addr) as u32);
    }
    let mut peername_addr = libc::sockaddr_in {
        sin_family: 321u16,
        sin_port: 654u16.to_be(),
        sin_addr: libc::in_addr {
            s_addr: 987u32.to_be(),
        },
        sin_zero: [2; 8],
    };
    {
        let mut size = std::mem::size_of_val(&peername_addr) as u32;
        let rv = unsafe {
            libc::getpeername(
                fd_peername,
                &mut peername_addr as *mut libc::sockaddr_in as *mut libc::sockaddr,
                &mut size as *mut libc::socklen_t,
            )
        };
        assert_eq!(rv, 0);
        assert_eq!(size, std::mem::size_of_val(&peername_addr) as u32);
    }
    sockaddr_check_equal(
        &sockname_addr,
        &peername_addr,
        /* ignore_port= */ false,
    )
}
fn compare_sockname_peername ( fd_sockname : libc :: c_int , fd_peername : libc :: c_int , ) -> Result < ( ) , String > { let mut sockname_addr = libc :: sockaddr_in { sin_family : 123u16 , sin_port : 456u16 . to_be ( ) , sin_addr : libc :: in_addr { s_addr : 789u32 . to_be ( ) , } , sin_zero : [ 1 ; 8 ] , } ; { let mut size = std :: mem :: size_of_val ( & sockname_addr ) as u32 ; let rv = unsafe { libc :: getsockname ( fd_sockname , & mut sockname_addr as * mut libc :: sockaddr_in as * mut libc :: sockaddr , & mut size as * mut libc :: socklen_t , ) } ; assert_eq ! ( rv 0 ) ; assert_eq ! ( size std mem size_of_val ( sockname_addr ) as u32 ) ; } let mut peername_addr = libc :: sockaddr_in { sin_family : 321u16 , sin_port : 654u16 . to_be ( ) , sin_addr : libc :: in_addr { s_addr : 987u32 . to_be ( ) , } , sin_zero : [ 2 ; 8 ] , } ; { let mut size = std :: mem :: size_of_val ( & peername_addr ) as u32 ; let rv = unsafe { libc :: getpeername ( fd_peername , & mut peername_addr as * mut libc :: sockaddr_in as * mut libc :: sockaddr , & mut size as * mut libc :: socklen_t , ) } ; assert_eq ! ( rv 0 ) ; assert_eq ! ( size std mem size_of_val ( peername_addr ) as u32 ) ; } sockaddr_check_equal ( & sockname_addr , & peername_addr , /* ignore_port= */ false , ) }
Run getsockname on one fd and getpeername on another fd, and make sure they match.
Run getsockname on one fd and getpeername on another fd and make sure they match .
fd_sockname
libc::c_int
fd_peername
libc::c_int
fd_sockname
libc::c_int
fd_peername
libc::c_int