diff options
author | Alan Somers <asomers@gmail.com> | 2021-08-06 20:15:24 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2021-08-10 17:57:32 -0600 |
commit | 0d3bc089d53a126716b4ed8f6b629c5b8c76964a (patch) | |
tree | 9ec5a162143216cd7daa3dc1fe6c8d61a9bbcba6 /src/sys/socket/mod.rs | |
parent | ba42d04aa8d3e23ba7aaa5cd4675e906a3d8bdfb (diff) | |
download | nix-0d3bc089d53a126716b4ed8f6b629c5b8c76964a.zip |
Add support for LOCAL_PEER_CRED
On FreeBSD and its derivatives, this socket option gets the credentials
of the connected peer.
Diffstat (limited to 'src/sys/socket/mod.rs')
-rw-r--r-- | src/sys/socket/mod.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 0f54ef0c..733bd660 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -358,6 +358,38 @@ cfg_if! { } } +cfg_if!{ + if #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "ios" + ))] { + /// Return type of [`LocalPeerCred`](crate::sys::socket::sockopt::LocalPeerCred) + #[repr(transparent)] + #[derive(Clone, Copy, Debug, Eq, PartialEq)] + pub struct XuCred(libc::xucred); + + impl XuCred { + /// Structure layout version + pub fn version(&self) -> u32 { + self.0.cr_version + } + + /// Effective user ID + pub fn uid(&self) -> libc::uid_t { + self.0.cr_uid + } + + /// Returns a list of group identifiers (the first one being the + /// effective GID) + pub fn groups(&self) -> &[libc::gid_t] { + &self.0.cr_groups + } + } + } +} + /// Request for multicast socket operations /// /// This is a wrapper type around `ip_mreq`. |