diff options
Diffstat (limited to 'src/sys/socket/mod.rs')
-rw-r--r-- | src/sys/socket/mod.rs | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 00c90560..ab7495ed 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -4,19 +4,22 @@ #[cfg(target_os = "linux")] #[cfg(feature = "uio")] use crate::sys::time::TimeSpec; +#[cfg(not(target_os = "redox"))] #[cfg(feature = "uio")] use crate::sys::time::TimeVal; use crate::{errno::Errno, Result}; use cfg_if::cfg_if; +use libc::{self, c_int, c_void, size_t, socklen_t}; +#[cfg(all(feature = "uio", not(target_os = "redox")))] use libc::{ - self, c_int, c_void, iovec, size_t, socklen_t, CMSG_DATA, CMSG_FIRSTHDR, - CMSG_LEN, CMSG_NXTHDR, + iovec, CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE, }; +#[cfg(not(target_os = "redox"))] use std::io::{IoSlice, IoSliceMut}; #[cfg(feature = "net")] use std::net; use std::os::unix::io::RawFd; -use std::{mem, ptr, slice}; +use std::{mem, ptr}; #[deny(missing_docs)] mod addr; @@ -38,14 +41,16 @@ pub use self::addr::{AddressFamily, UnixAddr}; #[cfg(not(any( target_os = "illumos", target_os = "solaris", - target_os = "haiku" + target_os = "haiku", + target_os = "redox", )))] #[cfg(feature = "net")] pub use self::addr::{LinkAddr, SockaddrIn, SockaddrIn6}; #[cfg(any( target_os = "illumos", target_os = "solaris", - target_os = "haiku" + target_os = "haiku", + target_os = "redox", ))] #[cfg(feature = "net")] pub use self::addr::{SockaddrIn, SockaddrIn6}; @@ -60,16 +65,12 @@ pub use crate::sys::socket::addr::sys_control::SysControlAddr; #[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::sys::socket::addr::vsock::VsockAddr; -#[cfg(feature = "uio")] +#[cfg(all(feature = "uio", not(target_os = "redox")))] pub use libc::{cmsghdr, msghdr}; pub use libc::{sa_family_t, sockaddr, sockaddr_storage, sockaddr_un}; #[cfg(feature = "net")] pub use libc::{sockaddr_in, sockaddr_in6}; -// Needed by the cmsg_space macro -#[doc(hidden)] -pub use libc::{c_uint, CMSG_SPACE}; - #[cfg(feature = "net")] use crate::sys::socket::addr::{ipv4addr_to_libc, ipv6addr_to_libc}; @@ -92,10 +93,11 @@ pub enum SockType { /// entire packet with each input system call. SeqPacket = libc::SOCK_SEQPACKET, /// Provides raw network protocol access. + #[cfg(not(target_os = "redox"))] Raw = libc::SOCK_RAW, /// Provides a reliable datagram layer that does not /// guarantee ordering. - #[cfg(not(any(target_os = "haiku")))] + #[cfg(not(any(target_os = "haiku", target_os = "redox")))] Rdm = libc::SOCK_RDM, } // The TryFrom impl could've been derived using libc_enum!. But for @@ -109,8 +111,9 @@ impl TryFrom<i32> for SockType { libc::SOCK_STREAM => Ok(Self::Stream), libc::SOCK_DGRAM => Ok(Self::Datagram), libc::SOCK_SEQPACKET => Ok(Self::SeqPacket), + #[cfg(not(target_os = "redox"))] libc::SOCK_RAW => Ok(Self::Raw), - #[cfg(not(any(target_os = "haiku")))] + #[cfg(not(any(target_os = "haiku", target_os = "redox")))] libc::SOCK_RDM => Ok(Self::Rdm), _ => Err(Errno::EINVAL), } @@ -239,7 +242,7 @@ libc_bitflags! { /// /// For use with [`Timestamping`][sockopt::Timestamping]. /// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html) - pub struct TimestampingFlag: c_uint { + pub struct TimestampingFlag: libc::c_uint { /// Report any software timestamps when available. SOF_TIMESTAMPING_SOFTWARE; /// Report hardware timestamps as generated by SOF_TIMESTAMPING_TX_HARDWARE when available. @@ -456,7 +459,7 @@ cfg_if! { /// Returns a list group identifiers (the first one being the effective GID) pub fn groups(&self) -> &[libc::gid_t] { unsafe { - slice::from_raw_parts( + std::slice::from_raw_parts( self.0.cmcred_groups.as_ptr() as *const libc::gid_t, self.0.cmcred_ngroups as _ ) @@ -549,6 +552,7 @@ impl Ipv6MembershipRequest { } } +#[cfg(not(target_os = "redox"))] feature! { #![feature = "uio"] @@ -578,18 +582,19 @@ feature! { macro_rules! cmsg_space { ( $( $x:ty ),* ) => { { - let mut space = 0; - $( - // CMSG_SPACE is always safe - space += unsafe { - $crate::sys::socket::CMSG_SPACE(::std::mem::size_of::<$x>() as $crate::sys::socket::c_uint) - } as usize; - )* + let space = 0 $(+ $crate::sys::socket::cmsg_space::<$x>())*; Vec::<u8>::with_capacity(space) } } } +#[inline] +#[doc(hidden)] +pub fn cmsg_space<T>() -> usize { + // SAFETY: CMSG_SPACE is always safe + unsafe { libc::CMSG_SPACE(mem::size_of::<T>() as libc::c_uint) as usize } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq)] /// Contains outcome of sending or receiving a message /// @@ -984,7 +989,7 @@ impl ControlMessageOwned { ControlMessageOwned::Ipv6OrigDstAddr(dl) }, (_, _) => { - let sl = slice::from_raw_parts(p, len); + let sl = std::slice::from_raw_parts(p, len); let ucmsg = UnknownCmsg(*header, Vec::<u8>::from(sl)); ControlMessageOwned::Unknown(ucmsg) } @@ -2392,6 +2397,7 @@ pub fn shutdown(df: RawFd, how: Shutdown) -> Result<()> { #[cfg(test)] mod tests { + #[cfg(not(target_os = "redox"))] #[test] fn can_use_cmsg_space() { let _ = cmsg_space!(u8); |