diff options
author | Steven Engler <opara@cs.georgetown.edu> | 2022-11-07 15:17:29 -0500 |
---|---|---|
committer | Steven Engler <opara@cs.georgetown.edu> | 2022-11-21 12:03:11 -0500 |
commit | 8884ea38ec80d838138070e941c080b0b573575a (patch) | |
tree | b926ab0b59900c90af4364531e59e90fb098d525 /src | |
parent | 33b5f928ea8e691c89d4b7242d44bdb2c1a62167 (diff) | |
download | nix-8884ea38ec80d838138070e941c080b0b573575a.zip |
Added better support for unnamed unix socket addrs
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/socket/addr.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index c7b5f29e..f051d205 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -885,6 +885,29 @@ impl UnixAddr { } } + /// Create a new `sockaddr_un` representing an "unnamed" unix socket address. + pub fn new_unnamed() -> UnixAddr { + #[allow(unused)] + let mut 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) } + } + /// Create a UnixAddr from a raw `sockaddr_un` struct and a size. `sun_len` /// is the size of the valid portion of the struct, excluding any trailing /// NUL. @@ -941,6 +964,12 @@ impl UnixAddr { } } + /// Check if this address is an "unnamed" unix socket address. + #[inline] + pub fn is_unnamed(&self) -> bool { + matches!(self.kind(), UnixAddrKind::Unnamed) + } + /// Returns the addrlen of this socket - `offsetof(struct sockaddr_un, sun_path)` #[inline] pub fn path_len(&self) -> usize { |