diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 003db4c3d3..ea87ae5ef1 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1189,6 +1189,9 @@ impl SockaddrLike for SockaddrStorage { libc::AF_ALG => unsafe { AlgAddr::from_raw(addr, l).map(|alg| Self { alg }) }, + libc::AF_UNIX => unsafe { + UnixAddr::from_raw(addr, l).map(|su| Self { su }) + }, #[cfg(feature = "net")] libc::AF_INET => unsafe { SockaddrIn::from_raw(addr, l).map(|sin| Self { sin }) @@ -2389,6 +2392,19 @@ mod tests { assert_eq!(ss.len(), ua.len()); } + #[test] + fn from_sockaddr_un_named_no_length() { + let ua = UnixAddr::new("/var/run/mysock").unwrap(); + assert!( + UnixAddr::size() + <= mem::size_of::() + as libc::socklen_t + ); + let ptr = ua.as_ptr().cast(); + let ss = unsafe { SockaddrStorage::from_raw(ptr, None) }.unwrap(); + assert_eq!(ss.len(), ua.len()); + } + #[cfg(linux_android)] #[test] fn from_sockaddr_un_abstract_named() {