pub(crate) unsafe fn read_sockaddr_os(storage: *const sockaddr, len: usize) -> SocketAddrAny {
    let z = linux_raw_sys::general::sockaddr_un {
        sun_family: 0_u16,
        sun_path: [0; 108],
    };
    let offsetof_sun_path = (as_ptr(&z.sun_path) as usize) - (as_ptr(&z) as usize);

    assert!(len >= size_of::<linux_raw_sys::general::__kernel_sa_family_t>());
    match read_ss_family(storage).into() {
        linux_raw_sys::general::AF_INET => {
            assert!(len >= size_of::<linux_raw_sys::general::sockaddr_in>());
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in>();
            SocketAddrAny::V4(SocketAddrV4::new(
                Ipv4Addr::from(u32::from_be(decode.sin_addr.s_addr)),
                u16::from_be(decode.sin_port),
            ))
        }
        linux_raw_sys::general::AF_INET6 => {
            assert!(len >= size_of::<linux_raw_sys::general::sockaddr_in6>());
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in6>();
            SocketAddrAny::V6(SocketAddrV6::new(
                Ipv6Addr::from(decode.sin6_addr.in6_u.u6_addr8),
                u16::from_be(decode.sin6_port),
                u32::from_be(decode.sin6_flowinfo),
                decode.sin6_scope_id,
            ))
        }
        linux_raw_sys::general::AF_UNIX => {
            assert!(len >= offsetof_sun_path);
            if len == offsetof_sun_path {
                SocketAddrAny::Unix(SocketAddrUnix::new(&[][..]).unwrap())
            } else {
                let decode = *storage.cast::<linux_raw_sys::general::sockaddr_un>();
                assert_eq!(
                    decode.sun_path[len - 1 - offsetof_sun_path],
                    b'\0' as c::c_char
                );
                SocketAddrAny::Unix(
                    SocketAddrUnix::new(
                        decode.sun_path[..len - 1 - offsetof_sun_path]
                            .iter()
                            .map(|c| *c as u8)
                            .collect::<Vec<u8>>(),
                    )
                    .unwrap(),
                )
            }
        }
        other => unimplemented!("{:?}", other),
    }
}
/// Read a socket address returned from the OS.
///
/// # Safety
///
/// `storage` must point to a valid socket address returned from the OS.
Read a socket address returned from the OS.
Read a socket address returned from the OS .
pub(crate) unsafe fn read_sockaddr_os(storage: *const sockaddr, len: usize) -> SocketAddrAny {
    let z = linux_raw_sys::general::sockaddr_un {
        sun_family: 0_u16,
        sun_path: [0; 108],
    };
    let offsetof_sun_path = (as_ptr(&z.sun_path) as usize) - (as_ptr(&z) as usize);
    assert!(len >= size_of::<linux_raw_sys::general::__kernel_sa_family_t>());
    match read_ss_family(storage).into() {
        linux_raw_sys::general::AF_INET => {
            assert!(len >= size_of::<linux_raw_sys::general::sockaddr_in>());
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in>();
            SocketAddrAny::V4(SocketAddrV4::new(
                Ipv4Addr::from(u32::from_be(decode.sin_addr.s_addr)),
                u16::from_be(decode.sin_port),
            ))
        }
        linux_raw_sys::general::AF_INET6 => {
            assert!(len >= size_of::<linux_raw_sys::general::sockaddr_in6>());
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in6>();
            SocketAddrAny::V6(SocketAddrV6::new(
                Ipv6Addr::from(decode.sin6_addr.in6_u.u6_addr8),
                u16::from_be(decode.sin6_port),
                u32::from_be(decode.sin6_flowinfo),
                decode.sin6_scope_id,
            ))
        }
        linux_raw_sys::general::AF_UNIX => {
            assert!(len >= offsetof_sun_path);
            if len == offsetof_sun_path {
                SocketAddrAny::Unix(SocketAddrUnix::new(&[][..]).unwrap())
            } else {
                let decode = *storage.cast::<linux_raw_sys::general::sockaddr_un>();
                assert_eq!(
                    decode.sun_path[len - 1 - offsetof_sun_path],
                    b'\0' as c::c_char
                );
                SocketAddrAny::Unix(
                    SocketAddrUnix::new(
                        decode.sun_path[..len - 1 - offsetof_sun_path]
                            .iter()
                            .map(|c| *c as u8)
                            .collect::<Vec<u8>>(),
                    )
                    .unwrap(),
                )
            }
        }
        other => unimplemented!("{:?}", other),
    }
}
pub ( crate ) unsafe fn read_sockaddr_os ( storage : * const sockaddr , len : usize ) -> SocketAddrAny { let z = linux_raw_sys :: general :: sockaddr_un { sun_family : 0_u16 , sun_path : [ 0 ; 108 ] , } ; let offsetof_sun_path = ( as_ptr ( & z . sun_path ) as usize ) - ( as_ptr ( & z ) as usize ) ; assert ! ( len size_of linux_raw_sys general kernel_sa_family_t ( ) ) ; match read_ss_family ( storage ) . into ( ) { linux_raw_sys :: general :: AF_INET => { assert ! ( len size_of linux_raw_sys general sockaddr_in ( ) ) ; let decode = * storage . cast :: < linux_raw_sys :: general :: sockaddr_in > ( ) ; SocketAddrAny :: V4 ( SocketAddrV4 :: new ( Ipv4Addr :: from ( u32 :: from_be ( decode . sin_addr . s_addr ) ) , u16 :: from_be ( decode . sin_port ) , ) ) } linux_raw_sys :: general :: AF_INET6 => { assert ! ( len size_of linux_raw_sys general sockaddr_in6 ( ) ) ; let decode = * storage . cast :: < linux_raw_sys :: general :: sockaddr_in6 > ( ) ; SocketAddrAny :: V6 ( SocketAddrV6 :: new ( Ipv6Addr :: from ( decode . sin6_addr . in6_u . u6_addr8 ) , u16 :: from_be ( decode . sin6_port ) , u32 :: from_be ( decode . sin6_flowinfo ) , decode . sin6_scope_id , ) ) } linux_raw_sys :: general :: AF_UNIX => { assert ! ( len offsetof_sun_path ) ; if len == offsetof_sun_path { SocketAddrAny :: Unix ( SocketAddrUnix :: new ( & [ ] [ .. ] ) . unwrap ( ) ) } else { let decode = * storage . cast :: < linux_raw_sys :: general :: sockaddr_un > ( ) ; assert_eq ! ( decode sun_path [ len 1 offsetof_sun_path ] b'\0' as c c_char ) ; SocketAddrAny :: Unix ( SocketAddrUnix :: new ( decode . sun_path [ .. len - 1 - offsetof_sun_path ] . iter ( ) . map ( | c | * c as u8 ) . collect :: < Vec < u8 > > ( ) , ) . unwrap ( ) , ) } } other => unimplemented ! ( " " other ) , } }
Read a socket address returned from the OS.
Read a socket address returned from the OS .
storage
*const sockaddr
len
usize
safety
`storage` must point to a valid socket address returned from the OS.
` storage ` must point to a valid socket address returned from the OS .