#[non_exhaustive]pub enum ControlMessageOwned {
Show 14 variants
ScmRights(Vec<RawFd>),
ScmCredentials(UnixCredentials),
ScmTimestamp(TimeVal),
ScmTimestampsns(Timestamps),
ScmTimestampns(TimeSpec),
Ipv4PacketInfo(in_pktinfo),
Ipv6PacketInfo(in6_pktinfo),
Ipv4OrigDstAddr(sockaddr_in),
Ipv6OrigDstAddr(sockaddr_in6),
UdpGroSegments(i32),
RxqOvfl(u32),
Ipv4RecvErr(sock_extended_err, Option<sockaddr_in>),
Ipv6RecvErr(sock_extended_err, Option<sockaddr_in6>),
TlsGetRecordType(TlsGetRecordType),
}
Expand description
A type-safe wrapper around a single control message, as used with
recvmsg
.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ScmRights(Vec<RawFd>)
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.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)
A set of nanosecond resolution timestamps
ScmTimestampns(TimeSpec)
Nanoseconds resolution timestamp
Ipv4PacketInfo(in_pktinfo)
Ipv6PacketInfo(in6_pktinfo)
Ipv4OrigDstAddr(sockaddr_in)
Ipv6OrigDstAddr(sockaddr_in6)
UdpGroSegments(i32)
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_err, Option<sockaddr_in>)
Socket error queue control messages read with the MSG_ERRQUEUE
flag.
Ipv6RecvErr(sock_extended_err, Option<sockaddr_in6>)
Socket error queue control messages read with the MSG_ERRQUEUE
flag.
TlsGetRecordType(TlsGetRecordType)
SOL_TLS
messages of type TLS_GET_RECORD_TYPE
Trait Implementations§
source§impl Clone for ControlMessageOwned
impl Clone for ControlMessageOwned
source§fn clone(&self) -> ControlMessageOwned
fn clone(&self) -> ControlMessageOwned
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ControlMessageOwned
impl Debug for ControlMessageOwned
source§impl PartialEq for ControlMessageOwned
impl PartialEq for ControlMessageOwned
impl Eq for ControlMessageOwned
impl StructuralPartialEq for ControlMessageOwned
Auto Trait Implementations§
impl Freeze for ControlMessageOwned
impl RefUnwindSafe for ControlMessageOwned
impl Send for ControlMessageOwned
impl Sync for ControlMessageOwned
impl Unpin for ControlMessageOwned
impl UnwindSafe for ControlMessageOwned
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)