From 6cc90b31e23b0b98bd9fa194fed041f4c413077d Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 1 Dec 2019 16:08:54 -0700 Subject: ScmCredentials now wraps UnixCredentials instead of libc::ucred --- src/sys/socket/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/sys/socket/mod.rs') diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 5ecf088a..aa280747 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -190,7 +190,7 @@ cfg_if! { /// Unix credentials of the sending process. /// /// This struct is used with the `SO_PEERCRED` ancillary message for UNIX sockets. - #[repr(C)] + #[repr(transparent)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct UnixCredentials(libc::ucred); @@ -368,7 +368,7 @@ pub enum ControlMessageOwned { /// Received version of /// [`ControlMessage::ScmCredentials`][#enum.ControlMessage.html#variant.ScmCredentials] #[cfg(any(target_os = "android", target_os = "linux"))] - ScmCredentials(libc::ucred), + ScmCredentials(UnixCredentials), /// A message of type `SCM_TIMESTAMP`, containing the time the /// packet was received by the kernel. /// @@ -496,7 +496,7 @@ impl ControlMessageOwned { #[cfg(any(target_os = "android", target_os = "linux"))] (libc::SOL_SOCKET, libc::SCM_CREDENTIALS) => { let cred: libc::ucred = ptr::read_unaligned(p as *const _); - ControlMessageOwned::ScmCredentials(cred) + ControlMessageOwned::ScmCredentials(cred.into()) } (libc::SOL_SOCKET, libc::SCM_TIMESTAMP) => { let tv: libc::timeval = ptr::read_unaligned(p as *const _); @@ -584,10 +584,8 @@ pub enum ControlMessage<'a> { /// /// For further information, please refer to the /// [`unix(7)`](http://man7.org/linux/man-pages/man7/unix.7.html) man page. - // FIXME: When `#[repr(transparent)]` is stable, use it on `UnixCredentials` - // and put that in here instead of a raw ucred. #[cfg(any(target_os = "android", target_os = "linux"))] - ScmCredentials(&'a libc::ucred), + ScmCredentials(&'a UnixCredentials), /// Set IV for `AF_ALG` crypto API. /// @@ -655,7 +653,7 @@ impl<'a> ControlMessage<'a> { }, #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::ScmCredentials(creds) => { - creds as *const libc::ucred as *const u8 + &creds.0 as *const libc::ucred as *const u8 } #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::AlgSetIv(iv) => { -- cgit v1.2.3