44#[ cfg( target_os = "linux" ) ]
55#[ cfg( feature = "uio" ) ]
66use crate :: sys:: time:: TimeSpec ;
7+ #[ cfg( not( target_os = "redox" ) ) ]
78#[ cfg( feature = "uio" ) ]
89use crate :: sys:: time:: TimeVal ;
910use crate :: { errno:: Errno , Result } ;
1011use cfg_if:: cfg_if;
12+ use libc:: { self , c_int, c_void, size_t, socklen_t} ;
13+ #[ cfg( all( feature = "uio" , not( target_os = "redox" ) ) ) ]
1114use libc:: {
12- self , c_int, c_void, iovec, size_t, socklen_t, CMSG_DATA , CMSG_FIRSTHDR ,
13- CMSG_LEN , CMSG_NXTHDR ,
15+ iovec, CMSG_DATA , CMSG_FIRSTHDR , CMSG_LEN , CMSG_NXTHDR , CMSG_SPACE ,
1416} ;
17+ #[ cfg( not( target_os = "redox" ) ) ]
1518use std:: io:: { IoSlice , IoSliceMut } ;
1619#[ cfg( feature = "net" ) ]
1720use std:: net;
1821use std:: os:: unix:: io:: RawFd ;
19- use std:: { mem, ptr, slice } ;
22+ use std:: { mem, ptr} ;
2023
2124#[ deny( missing_docs) ]
2225mod addr;
@@ -38,14 +41,16 @@ pub use self::addr::{AddressFamily, UnixAddr};
3841#[ cfg( not( any(
3942 target_os = "illumos" ,
4043 target_os = "solaris" ,
41- target_os = "haiku"
44+ target_os = "haiku" ,
45+ target_os = "redox" ,
4246) ) ) ]
4347#[ cfg( feature = "net" ) ]
4448pub use self :: addr:: { LinkAddr , SockaddrIn , SockaddrIn6 } ;
4549#[ cfg( any(
4650 target_os = "illumos" ,
4751 target_os = "solaris" ,
48- target_os = "haiku"
52+ target_os = "haiku" ,
53+ target_os = "redox" ,
4954) ) ]
5055#[ cfg( feature = "net" ) ]
5156pub use self :: addr:: { SockaddrIn , SockaddrIn6 } ;
@@ -60,16 +65,12 @@ pub use crate::sys::socket::addr::sys_control::SysControlAddr;
6065#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
6166pub use crate :: sys:: socket:: addr:: vsock:: VsockAddr ;
6267
63- #[ cfg( feature = "uio" ) ]
68+ #[ cfg( all ( feature = "uio" , not ( target_os = "redox" ) ) ) ]
6469pub use libc:: { cmsghdr, msghdr} ;
6570pub use libc:: { sa_family_t, sockaddr, sockaddr_storage, sockaddr_un} ;
6671#[ cfg( feature = "net" ) ]
6772pub use libc:: { sockaddr_in, sockaddr_in6} ;
6873
69- // Needed by the cmsg_space macro
70- #[ doc( hidden) ]
71- pub use libc:: { c_uint, CMSG_SPACE } ;
72-
7374#[ cfg( feature = "net" ) ]
7475use crate :: sys:: socket:: addr:: { ipv4addr_to_libc, ipv6addr_to_libc} ;
7576
@@ -92,10 +93,11 @@ pub enum SockType {
9293 /// entire packet with each input system call.
9394 SeqPacket = libc:: SOCK_SEQPACKET ,
9495 /// Provides raw network protocol access.
96+ #[ cfg( not( target_os = "redox" ) ) ]
9597 Raw = libc:: SOCK_RAW ,
9698 /// Provides a reliable datagram layer that does not
9799 /// guarantee ordering.
98- #[ cfg( not( any( target_os = "haiku" ) ) ) ]
100+ #[ cfg( not( any( target_os = "haiku" , target_os = "redox" ) ) ) ]
99101 Rdm = libc:: SOCK_RDM ,
100102}
101103// The TryFrom impl could've been derived using libc_enum!. But for
@@ -109,8 +111,9 @@ impl TryFrom<i32> for SockType {
109111 libc:: SOCK_STREAM => Ok ( Self :: Stream ) ,
110112 libc:: SOCK_DGRAM => Ok ( Self :: Datagram ) ,
111113 libc:: SOCK_SEQPACKET => Ok ( Self :: SeqPacket ) ,
114+ #[ cfg( not( target_os = "redox" ) ) ]
112115 libc:: SOCK_RAW => Ok ( Self :: Raw ) ,
113- #[ cfg( not( any( target_os = "haiku" ) ) ) ]
116+ #[ cfg( not( any( target_os = "haiku" , target_os = "redox" ) ) ) ]
114117 libc:: SOCK_RDM => Ok ( Self :: Rdm ) ,
115118 _ => Err ( Errno :: EINVAL ) ,
116119 }
@@ -239,7 +242,7 @@ libc_bitflags! {
239242 ///
240243 /// For use with [`Timestamping`][sockopt::Timestamping].
241244 /// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
242- pub struct TimestampingFlag : c_uint {
245+ pub struct TimestampingFlag : libc :: c_uint {
243246 /// Report any software timestamps when available.
244247 SOF_TIMESTAMPING_SOFTWARE ;
245248 /// Report hardware timestamps as generated by SOF_TIMESTAMPING_TX_HARDWARE when available.
@@ -456,7 +459,7 @@ cfg_if! {
456459 /// Returns a list group identifiers (the first one being the effective GID)
457460 pub fn groups( & self ) -> & [ libc:: gid_t] {
458461 unsafe {
459- slice:: from_raw_parts(
462+ std :: slice:: from_raw_parts(
460463 self . 0 . cmcred_groups. as_ptr( ) as * const libc:: gid_t,
461464 self . 0 . cmcred_ngroups as _
462465 )
@@ -549,6 +552,7 @@ impl Ipv6MembershipRequest {
549552}
550553}
551554
555+ #[ cfg( not( target_os = "redox" ) ) ]
552556feature ! {
553557#![ feature = "uio" ]
554558
@@ -578,18 +582,19 @@ feature! {
578582macro_rules! cmsg_space {
579583 ( $( $x: ty ) , * ) => {
580584 {
581- let mut space = 0 ;
582- $(
583- // CMSG_SPACE is always safe
584- space += unsafe {
585- $crate :: sys:: socket:: CMSG_SPACE ( :: std:: mem:: size_of:: <$x>( ) as $crate :: sys:: socket:: c_uint)
586- } as usize ;
587- ) *
585+ let space = 0 $( + $crate :: sys:: socket:: cmsg_space:: <$x>( ) ) * ;
588586 Vec :: <u8 >:: with_capacity( space)
589587 }
590588 }
591589}
592590
591+ #[ inline]
592+ #[ doc( hidden) ]
593+ pub fn cmsg_space<T >( ) -> usize {
594+ // SAFETY: CMSG_SPACE is always safe
595+ unsafe { libc:: CMSG_SPACE ( mem:: size_of:: <T >( ) as libc:: c_uint) as usize }
596+ }
597+
593598#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
594599/// Contains outcome of sending or receiving a message
595600///
@@ -984,7 +989,7 @@ impl ControlMessageOwned {
984989 ControlMessageOwned :: Ipv6OrigDstAddr ( dl)
985990 } ,
986991 ( _, _) => {
987- let sl = slice:: from_raw_parts( p, len) ;
992+ let sl = std :: slice:: from_raw_parts( p, len) ;
988993 let ucmsg = UnknownCmsg ( * header, Vec :: <u8 >:: from( sl) ) ;
989994 ControlMessageOwned :: Unknown ( ucmsg)
990995 }
@@ -2392,6 +2397,7 @@ pub fn shutdown(df: RawFd, how: Shutdown) -> Result<()> {
23922397
23932398#[ cfg( test) ]
23942399mod tests {
2400+ #[ cfg( not( target_os = "redox" ) ) ]
23952401 #[ test]
23962402 fn can_use_cmsg_space ( ) {
23972403 let _ = cmsg_space ! ( u8 ) ;
0 commit comments