Enum nix::sys::socket::ControlMessageOwned[][src]

pub enum ControlMessageOwned {
    ScmRights(Vec<RawFd>),
    ScmCredentials(UnixCredentials),
    ScmTimestamp(TimeVal),
    ScmTimestampns(TimeSpec),
    Ipv4PacketInfo(in_pktinfo),
    Ipv6PacketInfo(in6_pktinfo),
    UdpGroSegments(u16),
    RxqOvfl(u32),
    // some variants omitted
}
Expand description

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

Further reading

Variants

ScmRights

Received version of [ControlMessage::ScmRights][#enum.ControlMessage.html#variant.ScmRights]

Tuple Fields of ScmRights

0: Vec<RawFd>
ScmCredentials

Received version of [ControlMessage::ScmCredentials][#enum.ControlMessage.html#variant.ScmCredentials]

Tuple Fields of ScmCredentials

0: UnixCredentials
ScmTimestamp

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

Tuple Fields of ScmTimestamp

0: TimeVal
ScmTimestampns

Nanoseconds resolution timestamp

Further reading

Tuple Fields of ScmTimestampns

0: TimeSpec
Ipv4PacketInfo

Tuple Fields of Ipv4PacketInfo

0: in_pktinfo
Ipv6PacketInfo

Tuple Fields of Ipv6PacketInfo

0: in6_pktinfo
UdpGroSegments

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.

Tuple Fields of UdpGroSegments

0: u16
RxqOvfl

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.

Tuple Fields of RxqOvfl

0: u32

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.