From d99908d44c3e93a0fabd8e8323a6dd1a3f67b6de Mon Sep 17 00:00:00 2001 From: hax0r31337 Date: Thu, 17 Oct 2024 16:52:35 +0000 Subject: [PATCH 1/6] fix: make fields in UnknownCmsg public --- src/sys/socket/mod.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 53e85ba170..e8a43f9e40 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -39,10 +39,20 @@ pub use self::addr::{SockaddrLike, SockaddrStorage}; pub use self::addr::{AddressFamily, UnixAddr}; #[cfg(not(solarish))] pub use self::addr::{AddressFamily, UnixAddr}; -#[cfg(not(any(solarish, target_os = "haiku", target_os = "hurd", target_os = "redox")))] +#[cfg(not(any( + solarish, + target_os = "haiku", + target_os = "hurd", + target_os = "redox" +)))] #[cfg(feature = "net")] pub use self::addr::{LinkAddr, SockaddrIn, SockaddrIn6}; -#[cfg(any(solarish, target_os = "haiku", target_os = "hurd", target_os = "redox"))] +#[cfg(any( + solarish, + target_os = "haiku", + target_os = "hurd", + target_os = "redox" +))] #[cfg(feature = "net")] pub use self::addr::{SockaddrIn, SockaddrIn6}; @@ -794,17 +804,17 @@ pub enum ControlMessageOwned { #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv6HopLimit(i32), - /// Retrieve the DSCP (ToS) header field of the incoming IPv4 packet. + /// Retrieve the DSCP (ToS) header field of the incoming IPv4 packet. #[cfg(any(linux_android, target_os = "freebsd"))] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv4Tos(u8), - /// Retrieve the DSCP (Traffic Class) header field of the incoming IPv6 packet. + /// Retrieve the DSCP (Traffic Class) header field of the incoming IPv6 packet. #[cfg(any(linux_android, target_os = "freebsd"))] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] - Ipv6TClass(i32), + Ipv6TClass(i32), /// UDP Generic Receive Offload (GRO) allows receiving multiple UDP /// packets from a single sender. @@ -1258,7 +1268,7 @@ pub enum ControlMessage<'a> { // An opaque structure used to prevent cmsghdr from being a public type #[doc(hidden)] #[derive(Clone, Debug, Eq, PartialEq)] -pub struct UnknownCmsg(cmsghdr, Vec); +pub struct UnknownCmsg(pub cmsghdr, pub Vec); impl ControlMessage<'_> { /// The value of CMSG_SPACE on this message. @@ -2454,4 +2464,3 @@ pub fn shutdown(df: RawFd, how: Shutdown) -> Result<()> { Errno::result(shutdown(df, how)).map(drop) } } - From 4a93f131ba270d056a0acda2cf8ee3ca310515fb Mon Sep 17 00:00:00 2001 From: hax0r31337 Date: Thu, 17 Oct 2024 16:57:50 +0000 Subject: [PATCH 2/6] chore: changelog --- changelog/2520.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/2520.changed.md diff --git a/changelog/2520.changed.md b/changelog/2520.changed.md new file mode 100644 index 0000000000..be6cddb6bf --- /dev/null +++ b/changelog/2520.changed.md @@ -0,0 +1 @@ +Made fields in `nix::sys::socket::UnknownCmsg` public From 380e4c24b717b845b8bdee32dfb06cb31f45aa92 Mon Sep 17 00:00:00 2001 From: hax0r31337 Date: Thu, 17 Oct 2024 17:07:35 +0000 Subject: [PATCH 3/6] fix: mess caused by format on save --- src/sys/socket/mod.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index e8a43f9e40..56277fa412 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -39,20 +39,10 @@ pub use self::addr::{SockaddrLike, SockaddrStorage}; pub use self::addr::{AddressFamily, UnixAddr}; #[cfg(not(solarish))] pub use self::addr::{AddressFamily, UnixAddr}; -#[cfg(not(any( - solarish, - target_os = "haiku", - target_os = "hurd", - target_os = "redox" -)))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "hurd", target_os = "redox")))] #[cfg(feature = "net")] pub use self::addr::{LinkAddr, SockaddrIn, SockaddrIn6}; -#[cfg(any( - solarish, - target_os = "haiku", - target_os = "hurd", - target_os = "redox" -))] +#[cfg(any(solarish, target_os = "haiku", target_os = "hurd", target_os = "redox"))] #[cfg(feature = "net")] pub use self::addr::{SockaddrIn, SockaddrIn6}; @@ -804,17 +794,17 @@ pub enum ControlMessageOwned { #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv6HopLimit(i32), - /// Retrieve the DSCP (ToS) header field of the incoming IPv4 packet. + /// Retrieve the DSCP (ToS) header field of the incoming IPv4 packet. #[cfg(any(linux_android, target_os = "freebsd"))] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv4Tos(u8), - /// Retrieve the DSCP (Traffic Class) header field of the incoming IPv6 packet. + /// Retrieve the DSCP (Traffic Class) header field of the incoming IPv6 packet. #[cfg(any(linux_android, target_os = "freebsd"))] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] - Ipv6TClass(i32), + Ipv6TClass(i32), /// UDP Generic Receive Offload (GRO) allows receiving multiple UDP /// packets from a single sender. @@ -2313,7 +2303,8 @@ pub fn recvfrom( 0, addr.as_mut_ptr().cast(), &mut len as *mut socklen_t, - ))? as usize; + ))? as:q + usize; Ok((ret, T::from_raw(addr.assume_init().as_ptr(), Some(len)))) } From 59370915e5c1b7087e370b0b7318150123760ed1 Mon Sep 17 00:00:00 2001 From: hax0r31337 Date: Thu, 17 Oct 2024 17:08:58 +0000 Subject: [PATCH 4/6] fix: mess caused by format on save --- src/sys/socket/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 56277fa412..ea6875577d 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -2303,8 +2303,7 @@ pub fn recvfrom( 0, addr.as_mut_ptr().cast(), &mut len as *mut socklen_t, - ))? as:q - usize; + ))? as usize; Ok((ret, T::from_raw(addr.assume_init().as_ptr(), Some(len)))) } From 804498bb27dd6499669040a196ac2322954d6f83 Mon Sep 17 00:00:00 2001 From: hax0r31337 Date: Fri, 18 Oct 2024 18:05:45 +0000 Subject: [PATCH 5/6] feat: make the type visible in the doc --- src/sys/socket/mod.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index ea6875577d..f69a98ec43 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -846,7 +846,6 @@ pub enum ControlMessageOwned { TlsGetRecordType(TlsGetRecordType), /// Catch-all variant for unimplemented cmsg types. - #[doc(hidden)] Unknown(UnknownCmsg), } @@ -1062,7 +1061,10 @@ impl ControlMessageOwned { }, (_, _) => { let sl = unsafe { std::slice::from_raw_parts(p, len) }; - let ucmsg = UnknownCmsg(*header, Vec::::from(sl)); + let ucmsg = UnknownCmsg { + cmsg_header: *header, + data_bytes: Vec::::from(sl), + }; ControlMessageOwned::Unknown(ucmsg) } } @@ -1255,10 +1257,14 @@ pub enum ControlMessage<'a> { Ipv6TClass(&'a i32), } -// An opaque structure used to prevent cmsghdr from being a public type -#[doc(hidden)] +/// Control messages that are currently not supported by Nix. #[derive(Clone, Debug, Eq, PartialEq)] -pub struct UnknownCmsg(pub cmsghdr, pub Vec); +pub struct UnknownCmsg { + /// Control message header. + pub cmsg_header: cmsghdr, + /// Bytes of the control message data. + pub data_bytes: Vec +} impl ControlMessage<'_> { /// The value of CMSG_SPACE on this message. @@ -2454,3 +2460,4 @@ pub fn shutdown(df: RawFd, how: Shutdown) -> Result<()> { Errno::result(shutdown(df, how)).map(drop) } } + From f0275df51b33cefa33dda006c67009189cd87487 Mon Sep 17 00:00:00 2001 From: hax0r31337 Date: Fri, 18 Oct 2024 18:07:06 +0000 Subject: [PATCH 6/6] chore: update changelog --- changelog/2520.changed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/2520.changed.md b/changelog/2520.changed.md index be6cddb6bf..4314be6817 100644 --- a/changelog/2520.changed.md +++ b/changelog/2520.changed.md @@ -1 +1 @@ -Made fields in `nix::sys::socket::UnknownCmsg` public +Made `nix::sys::socket::UnknownCmsg` public and more readable