ControlMessageOwned

Enum ControlMessageOwned 

Source
#[non_exhaustive]
pub enum ControlMessageOwned {
Show 17 variants ScmRights(Vec<RawFd>), ScmCredentials(UnixCredentials), ScmTimestamp(TimeVal), ScmTimestampsns(Timestamps), ScmTimestampns(TimeSpec), Ipv4PacketInfo(in_pktinfo), Ipv6PacketInfo(in6_pktinfo), Ipv4OrigDstAddr(sockaddr_in), Ipv6OrigDstAddr(sockaddr_in6), Ipv4Ttl(i32), Ipv6HopLimit(i32), Ipv4Tos(u8), Ipv6TClass(i32), RxqOvfl(u32), Ipv4RecvErr(sock_extended_err, Option<sockaddr_in>), Ipv6RecvErr(sock_extended_err, Option<sockaddr_in6>), Unknown(UnknownCmsg),
}
Available on crate features socket and uio only.
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<RawFd>)

Received version of ControlMessage::ScmRights

§

ScmCredentials(UnixCredentials)

Available on linux_android only.

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.as_raw_fd(), &localhost).unwrap();
let address: SockaddrIn = getsockname(in_socket.as_raw_fd()).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.as_raw_fd(), &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.as_raw_fd(), &mut iov, Some(&mut cmsgspace), flags)
    .unwrap();
let rtime = match r.cmsgs().unwrap().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
§

ScmTimestampsns(Timestamps)

Available on linux_android only.

A set of nanosecond resolution timestamps

Further reading

§

ScmTimestampns(TimeSpec)

Available on linux_android only.

Nanoseconds resolution timestamp

Further reading

§

Ipv4PacketInfo(in_pktinfo)

Available on crate feature net only.
§

Ipv6PacketInfo(in6_pktinfo)

Available on crate feature net only.
§

Ipv4OrigDstAddr(sockaddr_in)

Available on crate feature net only.
§

Ipv6OrigDstAddr(sockaddr_in6)

Available on crate feature net only.
§

Ipv4Ttl(i32)

Available on crate feature net only.

Time-to-Live (TTL) header field of the incoming IPv4 packet.

Further reading

§

Ipv6HopLimit(i32)

Available on crate feature net only.

Hop Limit header field of the incoming IPv6 packet.

Further reading for Linux Further reading for FreeBSD

§

Ipv4Tos(u8)

Available on crate feature net only.

Retrieve the DSCP (ToS) header field of the incoming IPv4 packet.

§

Ipv6TClass(i32)

Available on crate feature net only.

Retrieve the DSCP (Traffic Class) header field of the incoming IPv6 packet.

§

RxqOvfl(u32)

Available on linux_android or Fuchsia only.

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_err, Option<sockaddr_in>)

Available on crate feature net only.

Socket error queue control messages read with the MSG_ERRQUEUE flag.

§

Ipv6RecvErr(sock_extended_err, Option<sockaddr_in6>)

Available on crate feature net only.

Socket error queue control messages read with the MSG_ERRQUEUE flag.

§

Unknown(UnknownCmsg)

Catch-all variant for unimplemented cmsg types.

Trait Implementations§

Source§

impl Clone for ControlMessageOwned

Source§

fn clone(&self) -> ControlMessageOwned

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ControlMessageOwned

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ControlMessageOwned

Source§

fn eq(&self, other: &ControlMessageOwned) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ControlMessageOwned

Source§

impl StructuralPartialEq for ControlMessageOwned

Auto Trait Implementations§

§

impl Freeze for ControlMessageOwned

Available on Unix only.
§

impl RefUnwindSafe for ControlMessageOwned

Available on Unix only.
§

impl Send for ControlMessageOwned

Available on Unix only.
§

impl Sync for ControlMessageOwned

Available on Unix only.
§

impl Unpin for ControlMessageOwned

Available on Unix only.
§

impl UnwindSafe for ControlMessageOwned

Available on Unix only.

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Available on Unix only.
Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Available on Unix only.
Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Available on Unix only.
Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Available on Unix only.
Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Available on Unix only.
Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Available on Unix only.
Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Available on Unix only.
Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Available on Unix only.
Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Available on Unix only.
Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.