pub(crate) unsafe fn read_sockaddr(
    storage: *const sockaddr,
    len: usize,
) -> io::Result<SocketAddrAny> {
    let offsetof_sun_path = super::offsetof_sun_path();

    if len < size_of::<linux_raw_sys::general::__kernel_sa_family_t>() {
        return Err(io::Error::INVAL);
    }
    match read_ss_family(storage).into() {
        linux_raw_sys::general::AF_INET => {
            if len < size_of::<linux_raw_sys::general::sockaddr_in>() {
                return Err(io::Error::INVAL);
            }
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in>();
            Ok(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 => {
            if len < size_of::<linux_raw_sys::general::sockaddr_in6>() {
                return Err(io::Error::INVAL);
            }
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in6>();
            Ok(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 => {
            if len < offsetof_sun_path {
                return Err(io::Error::INVAL);
            }
            if len == offsetof_sun_path {
                Ok(SocketAddrAny::Unix(SocketAddrUnix::new(&[][..])?))
            } 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
                );
                Ok(SocketAddrAny::Unix(SocketAddrUnix::new(
                    decode.sun_path[..len - 1 - offsetof_sun_path]
                        .iter()
                        .map(|c| *c as u8)
                        .collect::<Vec<u8>>(),
                )?))
            }
        }
        _ => Err(io::Error::NOTSUP),
    }
}
/// Read a socket address encoded in a platform-specific format.
///
/// # Safety
///
/// `storage` must point to valid socket address storage.
Read a socket address encoded in a platform-specific format.
Read a socket address encoded in a platform - specific format .
pub(crate) unsafe fn read_sockaddr(
    storage: *const sockaddr,
    len: usize,
) -> io::Result<SocketAddrAny> {
    let offsetof_sun_path = super::offsetof_sun_path();
    if len < size_of::<linux_raw_sys::general::__kernel_sa_family_t>() {
        return Err(io::Error::INVAL);
    }
    match read_ss_family(storage).into() {
        linux_raw_sys::general::AF_INET => {
            if len < size_of::<linux_raw_sys::general::sockaddr_in>() {
                return Err(io::Error::INVAL);
            }
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in>();
            Ok(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 => {
            if len < size_of::<linux_raw_sys::general::sockaddr_in6>() {
                return Err(io::Error::INVAL);
            }
            let decode = *storage.cast::<linux_raw_sys::general::sockaddr_in6>();
            Ok(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 => {
            if len < offsetof_sun_path {
                return Err(io::Error::INVAL);
            }
            if len == offsetof_sun_path {
                Ok(SocketAddrAny::Unix(SocketAddrUnix::new(&[][..])?))
            } 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
                );
                Ok(SocketAddrAny::Unix(SocketAddrUnix::new(
                    decode.sun_path[..len - 1 - offsetof_sun_path]
                        .iter()
                        .map(|c| *c as u8)
                        .collect::<Vec<u8>>(),
                )?))
            }
        }
        _ => Err(io::Error::NOTSUP),
    }
}
pub ( crate ) unsafe fn read_sockaddr ( storage : * const sockaddr , len : usize , ) -> io :: Result < SocketAddrAny > { let offsetof_sun_path = super :: offsetof_sun_path ( ) ; if len < size_of :: < linux_raw_sys :: general :: __kernel_sa_family_t > ( ) { return Err ( io :: Error :: INVAL ) ; } match read_ss_family ( storage ) . into ( ) { linux_raw_sys :: general :: AF_INET => { if len < size_of :: < linux_raw_sys :: general :: sockaddr_in > ( ) { return Err ( io :: Error :: INVAL ) ; } let decode = * storage . cast :: < linux_raw_sys :: general :: sockaddr_in > ( ) ; Ok ( 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 => { if len < size_of :: < linux_raw_sys :: general :: sockaddr_in6 > ( ) { return Err ( io :: Error :: INVAL ) ; } let decode = * storage . cast :: < linux_raw_sys :: general :: sockaddr_in6 > ( ) ; Ok ( 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 => { if len < offsetof_sun_path { return Err ( io :: Error :: INVAL ) ; } if len == offsetof_sun_path { Ok ( SocketAddrAny :: Unix ( SocketAddrUnix :: new ( & [ ] [ .. ] ) ? ) ) } 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 ) ; Ok ( SocketAddrAny :: Unix ( SocketAddrUnix :: new ( decode . sun_path [ .. len - 1 - offsetof_sun_path ] . iter ( ) . map ( | c | * c as u8 ) . collect :: < Vec < u8 > > ( ) , ) ? ) ) } } _ => Err ( io :: Error :: NOTSUP ) , } }
Read a socket address encoded in a platform-specific format.
Read a socket address encoded in a platform - specific format .
storage
*const sockaddr
len
usize
safety
`storage` must point to valid socket address storage.
` storage ` must point to valid socket address storage .