diff options
-rw-r--r-- | src/sys/socket/addr.rs | 17 | ||||
-rw-r--r-- | test/sys/test_socket.rs | 5 |
2 files changed, 8 insertions, 14 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index f051d205..34138efc 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -886,25 +886,16 @@ impl UnixAddr { } /// Create a new `sockaddr_un` representing an "unnamed" unix socket address. + #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg_attr(docsrs, doc(cfg(all())))] pub fn new_unnamed() -> UnixAddr { - #[allow(unused)] - let mut ret = libc::sockaddr_un { + let ret = libc::sockaddr_un { sun_family: AddressFamily::Unix as sa_family_t, .. unsafe { mem::zeroed() } }; let sun_len: u8 = offset_of!(libc::sockaddr_un, sun_path).try_into().unwrap(); - #[cfg(any(target_os = "dragonfly", - target_os = "freebsd", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd"))] - { - ret.sun_len = sun_len; - } - unsafe { UnixAddr::from_raw_parts(ret, sun_len) } } @@ -965,6 +956,8 @@ impl UnixAddr { } /// Check if this address is an "unnamed" unix socket address. + #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg_attr(docsrs, doc(cfg(all())))] #[inline] pub fn is_unnamed(&self) -> bool { matches!(self.kind(), UnixAddrKind::Unnamed) diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 26ba9b2d..07ca4d34 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -223,7 +223,7 @@ pub fn test_addr_equality_abstract() { } // Test getting/setting abstract addresses (without unix socket creation) -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] pub fn test_abstract_uds_addr() { let empty = String::new(); @@ -245,6 +245,7 @@ pub fn test_abstract_uds_addr() { } // Test getting an unnamed address (without unix socket creation) +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] pub fn test_unnamed_uds_addr() { use crate::nix::sys::socket::SockaddrLike; @@ -256,7 +257,6 @@ pub fn test_unnamed_uds_addr() { assert!(addr.path().is_none()); assert_eq!(addr.path_len(), 0); - #[cfg(target_os = "linux")] assert!(addr.as_abstract().is_none()); } @@ -1544,6 +1544,7 @@ pub fn test_named_unixdomain() { } // Test using unnamed unix domain addresses +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] pub fn test_unnamed_unixdomain() { use nix::sys::socket::{getsockname, socketpair}; |