#[non_exhaustive]
pub enum ControlMessageOwned {
    ScmRights(Vec<i32, Global>),
    ScmCredentials(UnixCredentials),
    ScmTimestamp(TimeVal),
    ScmTimestampsns(Timestamps),
    ScmTimestampns(TimeSpec),
    Ipv4PacketInfo(in_pktinfo),
    Ipv6PacketInfo(in6_pktinfo),
    UdpGroSegments(u16),
    RxqOvfl(u32),
    Ipv4RecvErr(sock_extended_errOption<sockaddr_in>),
    Ipv6RecvErr(sock_extended_errOption<sockaddr_in6>),
    // some variants omitted
}
Expand description

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

Further reading

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.

ScmRights(Vec<i32, Global>)

Received version of ControlMessage::ScmRights

ScmCredentials(UnixCredentials)

Received version of ControlMessage::ScmCredentials

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 = SockaddrIn::from_str("127.0.0.1:0").unwrap();
bind(in_socket, &localhost);
let address: SockaddrIn = getsockname(in_socket).unwrap();
// Get initial time
let time0 = SystemTime::now();
// Send the message
let iov = [IoSlice::new(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 mut iov = [IoSliceMut::new(&mut buffer)];
let r = recvmsg::<SockaddrIn>(in_socket, &mut 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();

ScmTimestampsns(Timestamps)

A set of nanosecond resolution timestamps

Further reading

ScmTimestampns(TimeSpec)

Nanoseconds resolution timestamp

Further reading

Ipv4PacketInfo(in_pktinfo)

Ipv6PacketInfo(in6_pktinfo)

UdpGroSegments(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)

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(sock_extended_errOption<sockaddr_in>)

Socket error queue control messages read with the MSG_ERRQUEUE flag.

Ipv6RecvErr(sock_extended_errOption<sockaddr_in6>)

Socket error queue control messages read with the MSG_ERRQUEUE flag.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Use this to cast from one trait object type to another. Read more

Use this to upcast a trait to one of its supertraits. Read more

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the “source” trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more