Skip to content

Commit

Permalink
Work around Darwn (macOS) weirdness
Browse files Browse the repository at this point in the history
It seems to return a length of 16 and an all zero address for unnamed
Unix addresses.
  • Loading branch information
Thomasdezeeuw committed Dec 24, 2023
1 parent 1c646e1 commit 71b80e3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
});

let socket = socket.map(UnixStream::from_std)?;
let path_len = socklen as usize - path_offset(&sockaddr);

#[allow(unused_mut)] // See below.
let mut path_len = socklen as usize - path_offset(&sockaddr);
// Darwin is being weird, it return a length of 16, but other an unnamed
// (all zero) address. Map that to a length of 0 to match other OS.
#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
))]
if socklen == 16 && sockaddr.sun_path[0] == 0 {
path_len = 0;
}
let address = SocketAddr::from_pathname(Path::new(OsStr::from_bytes(unsafe {
// SAFETY: going from i8 to u8 is fine in this context.
&*(&sockaddr.sun_path[..path_len] as *const [libc::c_char] as *const [u8])
Expand Down

0 comments on commit 71b80e3

Please sign in to comment.