Skip to content

Commit 71b80e3

Browse files
committed
Work around Darwn (macOS) weirdness
It seems to return a length of 16 and an all zero address for unnamed Unix addresses.
1 parent 1c646e1 commit 71b80e3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/sys/unix/uds/listener.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
9696
});
9797

9898
let socket = socket.map(UnixStream::from_std)?;
99-
let path_len = socklen as usize - path_offset(&sockaddr);
99+
100+
#[allow(unused_mut)] // See below.
101+
let mut path_len = socklen as usize - path_offset(&sockaddr);
102+
// Darwin is being weird, it return a length of 16, but other an unnamed
103+
// (all zero) address. Map that to a length of 0 to match other OS.
104+
#[cfg(any(
105+
target_os = "ios",
106+
target_os = "macos",
107+
target_os = "tvos",
108+
target_os = "watchos",
109+
))]
110+
if socklen == 16 && sockaddr.sun_path[0] == 0 {
111+
path_len = 0;
112+
}
100113
let address = SocketAddr::from_pathname(Path::new(OsStr::from_bytes(unsafe {
101114
// SAFETY: going from i8 to u8 is fine in this context.
102115
&*(&sockaddr.sun_path[..path_len] as *const [libc::c_char] as *const [u8])

0 commit comments

Comments
 (0)