summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sys/mod.rs1
-rw-r--r--src/sys/socket/addr.rs29
-rw-r--r--src/sys/socket/mod.rs50
-rw-r--r--src/sys/socket/sockopt.rs8
4 files changed, 51 insertions, 37 deletions
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index 383f08df..e74bb18a 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -138,7 +138,6 @@ feature! {
pub mod signalfd;
}
-#[cfg(not(target_os = "redox"))]
feature! {
#![feature = "socket"]
#[allow(missing_docs)]
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index aad407a7..48309749 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -100,8 +100,10 @@ pub enum AddressFamily {
#[cfg_attr(docsrs, doc(cfg(all())))]
Ax25 = libc::AF_AX25,
/// IPX - Novell protocols
+ #[cfg(not(target_os = "redox"))]
Ipx = libc::AF_IPX,
/// AppleTalk
+ #[cfg(not(target_os = "redox"))]
AppleTalk = libc::AF_APPLETALK,
/// AX.25 packet layer protocol.
/// (see [netrom(4)](https://www.unix.com/man-page/linux/4/netrom/))
@@ -130,7 +132,7 @@ pub enum AddressFamily {
#[cfg_attr(docsrs, doc(cfg(all())))]
Rose = libc::AF_ROSE,
/// DECet protocol sockets.
- #[cfg(not(target_os = "haiku"))]
+ #[cfg(not(any(target_os = "haiku", target_os = "redox")))]
Decnet = libc::AF_DECnet,
/// Reserved for "802.2LLC project"; never used.
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -162,7 +164,7 @@ pub enum AddressFamily {
#[cfg_attr(docsrs, doc(cfg(all())))]
Rds = libc::AF_RDS,
/// IBM SNA
- #[cfg(not(target_os = "haiku"))]
+ #[cfg(not(any(target_os = "haiku", target_os = "redox")))]
Sna = libc::AF_SNA,
/// Socket interface over IrDA
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -202,7 +204,8 @@ pub enum AddressFamily {
target_os = "illumos",
target_os = "ios",
target_os = "macos",
- target_os = "solaris"
+ target_os = "solaris",
+ target_os = "redox",
)))]
#[cfg_attr(docsrs, doc(cfg(all())))]
Bluetooth = libc::AF_BLUETOOTH,
@@ -219,7 +222,8 @@ pub enum AddressFamily {
#[cfg(not(any(
target_os = "illumos",
target_os = "solaris",
- target_os = "haiku"
+ target_os = "haiku",
+ target_os = "redox",
)))]
#[cfg_attr(docsrs, doc(cfg(all())))]
Isdn = libc::AF_ISDN,
@@ -460,7 +464,8 @@ pub struct UnixAddr {
target_os = "android",
target_os = "fuchsia",
target_os = "illumos",
- target_os = "linux"
+ target_os = "linux",
+ target_os = "redox",
))]
sun_len: u8,
}
@@ -624,7 +629,8 @@ impl UnixAddr {
if #[cfg(any(target_os = "android",
target_os = "fuchsia",
target_os = "illumos",
- target_os = "linux"
+ target_os = "linux",
+ target_os = "redox",
))]
{
UnixAddr { sun, sun_len }
@@ -690,7 +696,8 @@ impl UnixAddr {
if #[cfg(any(target_os = "android",
target_os = "fuchsia",
target_os = "illumos",
- target_os = "linux"
+ target_os = "linux",
+ target_os = "redox",
))]
{
self.sun_len
@@ -736,7 +743,8 @@ impl SockaddrLike for UnixAddr {
if #[cfg(any(target_os = "android",
target_os = "fuchsia",
target_os = "illumos",
- target_os = "linux"
+ target_os = "linux",
+ target_os = "redox",
))] {
let su_len = len.unwrap_or(
mem::size_of::<libc::sockaddr_un>() as libc::socklen_t
@@ -1221,7 +1229,7 @@ pub union SockaddrStorage {
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
alg: AlgAddr,
- #[cfg(feature = "net")]
+ #[cfg(all(feature = "net", not(target_os = "redox")))]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
dl: LinkAddr,
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -2338,6 +2346,7 @@ mod tests {
}
}
+ #[cfg(not(target_os = "redox"))]
mod link {
#![allow(clippy::cast_ptr_alignment)]
@@ -2534,7 +2543,7 @@ mod tests {
nix_sin6.0.sin6_flowinfo = 0x12345678;
nix_sin6.0.sin6_scope_id = 0x9abcdef0;
- let std_sin6 : std::net::SocketAddrV6 = nix_sin6.into();
+ let std_sin6: std::net::SocketAddrV6 = nix_sin6.into();
assert_eq!(nix_sin6, std_sin6.into());
}
}
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);
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index 90216649..a18b5905 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -544,13 +544,13 @@ cfg_if! {
sockopt_impl!(
/// The maximum segment size for outgoing TCP packets.
TcpMaxSeg, Both, libc::IPPROTO_TCP, libc::TCP_MAXSEG, u32);
- } else {
+ } else if #[cfg(not(target_os = "redox"))] {
sockopt_impl!(
/// The maximum segment size for outgoing TCP packets.
TcpMaxSeg, GetOnly, libc::IPPROTO_TCP, libc::TCP_MAXSEG, u32);
}
}
-#[cfg(not(any(target_os = "openbsd", target_os = "haiku")))]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "redox")))]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
@@ -572,7 +572,7 @@ sockopt_impl!(
libc::TCP_REPAIR,
u32
);
-#[cfg(not(any(target_os = "openbsd", target_os = "haiku")))]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "redox")))]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
@@ -693,7 +693,7 @@ sockopt_impl!(
libc::SO_TIMESTAMPING,
super::TimestampingFlag
);
-#[cfg(not(target_os = "haiku"))]
+#[cfg(not(any(target_os = "haiku", target_os = "redox")))]
sockopt_impl!(
/// Enable or disable the receiving of the `SO_TIMESTAMP` control message.
ReceiveTimestamp,