Enum nix::sys::socket::ControlMessageOwned

#[non_exhaustive]
pub enum ControlMessageOwned {    
    ScmRights(Vec<RawFd>),
    ScmCredentials(UnixCredentials),
    ScmTimestamp(TimeVal),
    ScmTimestampns(TimeSpec),
    Ipv4PacketInfo(libc::in_pktinfo),
    Ipv6PacketInfo(libc::in6_pktinfo),
    UdpGroSegments(u16),
    RxqOvfl(u32),
    Ipv4RecvErr(libc::sock_extended_err, Option<sockaddr_in>),
    Ipv6RecvErr(libc::sock_extended_err, Option<sockaddr_in6>),
    /* some fields hidden */
}
Documentation

A type-safe wrapper around a single control message, as used with recvmsg.

Further reading

Variants

ScmRights(Vec<RawFd>)

Received version of ControlMessage::ScmRights

ScmTimestamp(TimeVal)

A message of type SCM_TIMESTAMP, containing the time the packet was received by the kernel.

See the kernel’s explanation in “SO_TIMESTAMP” of networking/timestamping.

Examples

// Set up
let message = "Ohayō!".as_bytes();
let in_socket = socket(
    AddressFamily::Inet,
    SockType::Datagram,
    SockFlag::empty(),
    None).unwrap();
setsockopt(in_socket, sockopt::ReceiveTimestamp, &true).unwrap();
let localhost = InetAddr::new(IpAddr::new_v4(127, 0, 0, 1), 0);
bind(in_socket, &SockAddr::new_inet(localhost)).unwrap();
let address = getsockname(in_socket).unwrap();
// Get initial time
let time0 = SystemTime::now();
// Send the message
let iov = [IoVec::from_slice(message)];
let flags = MsgFlags::empty();
let l = sendmsg(in_socket, &iov, &[], flags, Some(&address)).unwrap();
assert_eq!(message.len(), l);
// Receive the message
let mut buffer = vec![0u8; message.len()];
let mut cmsgspace = cmsg_space!(TimeVal);
let iov = [IoVec::from_mut_slice(&mut buffer)];
let r = recvmsg(in_socket, &iov, Some(&mut cmsgspace), flags).unwrap();
let rtime = match r.cmsgs().next() {
    Some(ControlMessageOwned::ScmTimestamp(rtime)) => rtime,
    Some(_) => panic!("Unexpected control message"),
    None => panic!("No control message")
};
// Check the final time
let time1 = SystemTime::now();
// the packet's received timestamp should lie in-between the two system
// times, unless the system clock was adjusted in the meantime.
let rduration = Duration::new(rtime.tv_sec() as u64,
                              rtime.tv_usec() as u32 * 1000);
assert!(time0.duration_since(UNIX_EPOCH).unwrap() <= rduration);
assert!(rduration <= time1.duration_since(UNIX_EPOCH).unwrap());
// Close socket
nix::unistd::close(in_socket).unwrap();
ScmTimestampns(TimeSpec)

Nanoseconds resolution timestamp

Further reading

Ipv4PacketInfo(libc::in_pktinfo)
libc::in_pktinfo
Ipv6PacketInfo(libc::in6_pktinfo)
libc::in6_pktinfo
UdpGroSegments(u16)
u16

UDP Generic Receive Offload (GRO) allows receiving multiple UDP packets from a single sender. Fixed-size payloads are following one by one in a receive buffer. This Control Message indicates the size of all smaller packets, except, maybe, the last one.

UdpGroSegment socket option should be enabled on a socket to allow receiving GRO packets.

RxqOvfl(u32)
u32

SO_RXQ_OVFL indicates that an unsigned 32 bit value ancilliary msg (cmsg) should be attached to recieved skbs indicating the number of packets dropped by the socket between the last recieved packet and this received packet.

RxqOvfl socket option should be enabled on a socket to allow receiving the drop counter.

Ipv4RecvErr(libc::sock_extended_err, Option<sockaddr_in>)
libc::sock_extended_err
Option<sockaddr_in>

Socket error queue control messages read with the MSG_ERRQUEUE flag.

Ipv6RecvErr(libc::sock_extended_err, Option<sockaddr_in6>)
libc::sock_extended_err
Option<sockaddr_in6>

Socket error queue control messages read with the MSG_ERRQUEUE flag.

Trait Implementations

impl Debug for ControlMessageOwned
fn fmt(&Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl PartialEq<ControlMessageOwned> for ControlMessageOwned
fn eq(&Self, other: &ControlMessageOwned) -> bool
fn ne(&Self, other: &ControlMessageOwned) -> bool

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T
where
    T: 'static + ?Sized,
fn type_id(&Self) -> TypeId
impl<T> Borrow<T> for T
where
    T: ?Sized,
fn borrow(&Self) -> &T
impl<T> BorrowMut<T> for T
where
    T: ?Sized,
fn borrow_mut(&mut Self) -> &mut T
impl<T> From<T> for T
fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for T
where
    U: From<T>,
fn into(Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

impl<T> ToOwned for T
where
    T: Clone,
type Owned = T
fn to_owned(&Self) -> T
fn clone_into(&Self, target: &mut T)
impl<T, U> TryFrom<U> for T
where
    U: Into<T>,
type Error = Infallible
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for T
where
    U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn try_into(Self) -> Result<U, <U as TryFrom<T>>::Error>