diff --git a/src/lib.rs b/src/lib.rs index 4f6bd789..89dce26e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -719,6 +719,15 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> { pub fn flags(&self) -> RecvFlags { sys::msghdr_flags(&self.inner) } + + /// Gets the length of the control buffer. + /// + /// Can be used to determine how much, if any, of the control buffer was filled by `recvmsg`. + /// + /// Corresponds to `msg_controllen` on Unix and `Control.len` on Windows. + pub fn control_len(&self) -> usize { + sys::msghdr_control_len(&self.inner) + } } #[cfg(not(target_os = "redox"))] diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 562cd60f..90d3eb1a 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -738,6 +738,11 @@ pub(crate) fn msghdr_flags(msg: &msghdr) -> RecvFlags { RecvFlags(msg.msg_flags) } +#[cfg(not(target_os = "redox"))] +pub(crate) fn msghdr_control_len(msg: &msghdr) -> usize { + msg.msg_controllen as _ +} + /// Unix only API. impl SockAddr { /// Constructs a `SockAddr` with the family `AF_VSOCK` and the provided CID/port. diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 4c5d9879..11f2b7b0 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -215,6 +215,10 @@ pub(crate) fn msghdr_flags(msg: &msghdr) -> RecvFlags { RecvFlags(msg.dwFlags as c_int) } +pub(crate) fn msghdr_control_len(msg: &msghdr) -> usize { + msg.Control.len as _ +} + fn init() { static INIT: Once = Once::new();