Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fields in UnknownCmsg public #2520

Merged
merged 6 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2520.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made `nix::sys::socket::UnknownCmsg` public and more readable
16 changes: 11 additions & 5 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,6 @@ pub enum ControlMessageOwned {
TlsGetRecordType(TlsGetRecordType),

/// Catch-all variant for unimplemented cmsg types.
#[doc(hidden)]
Unknown(UnknownCmsg),
}

Expand Down Expand Up @@ -1062,7 +1061,10 @@ impl ControlMessageOwned {
},
(_, _) => {
let sl = unsafe { std::slice::from_raw_parts(p, len) };
let ucmsg = UnknownCmsg(*header, Vec::<u8>::from(sl));
let ucmsg = UnknownCmsg {
cmsg_header: *header,
data_bytes: Vec::<u8>::from(sl),
};
ControlMessageOwned::Unknown(ucmsg)
}
}
Expand Down Expand Up @@ -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(cmsghdr, Vec<u8>);
pub struct UnknownCmsg {
/// Control message header.
pub cmsg_header: cmsghdr,
/// Bytes of the control message data.
pub data_bytes: Vec<u8>
}

impl ControlMessage<'_> {
/// The value of CMSG_SPACE on this message.
Expand Down