pub struct NetlinkMessage { /* private fields */ }Expand description
Represent a netlink message.
A netlink message is made of a header (represented by
NetlinkHeader) and message (represented by
NetlinkPayload):
0 8 16 24 32
+----------------+----------------+----------------+----------------+
| packet length (including header) | \
+----------------+----------------+----------------+----------------+ |
| message type | flags | |
+----------------+----------------+----------------+----------------+ | NetlinkHeader
| sequence number | |
+----------------+----------------+----------------+----------------+ |
| port number (formerly known as PID) | /
+----------------+----------------+----------------+----------------+
| payload | \
| (variable length) | | NetlinkPayload
| | |
| | /
+----------------+----------------+----------------+----------------+Implementations§
Source§impl NetlinkMessage
impl NetlinkMessage
pub fn new(header: NetlinkHeader, payload: NetlinkPayload) -> Self
pub fn into_parts(self) -> (NetlinkHeader, NetlinkPayload)
pub fn payload(&self) -> &NetlinkPayload
pub fn payload_mut(&mut self) -> &mut NetlinkPayload
pub fn header(&self) -> &NetlinkHeader
pub fn header_mut(&mut self) -> &mut NetlinkHeader
Sourcepub fn to_bytes(&mut self, buffer: &mut [u8]) -> Result<usize, EncodeError>
pub fn to_bytes(&mut self, buffer: &mut [u8]) -> Result<usize, EncodeError>
Safely serialize the message. Under the hood, this calls
Emitable::emit(), but unlike emit(), this method
does not panic if the message is malformed or if the destination buffer is too small.
Instead, an error is returned.
Sourcepub fn from_bytes(buffer: &[u8]) -> Result<Self, DecodeError>
pub fn from_bytes(buffer: &[u8]) -> Result<Self, DecodeError>
Try to parse a message from a buffer
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Check if the payload is a NLMSG_DONE message
(Rtnl::Done)
Sourcepub fn is_noop(&self) -> bool
pub fn is_noop(&self) -> bool
Check if the payload is a NLMSG_NOOP message
(Rtnl::Noop)
Sourcepub fn is_overrun(&self) -> bool
pub fn is_overrun(&self) -> bool
Check if the payload is a NLMSG_OVERRUN message
(Rtnl::Overrun)
Sourcepub fn is_error(&self) -> bool
pub fn is_error(&self) -> bool
Check if the payload is a NLMSG_ERROR message with a negative error code
(Rtnl::Error)
Sourcepub fn is_ack(&self) -> bool
pub fn is_ack(&self) -> bool
Check if the payload is a NLMSG_ERROR message with a non-negative error code
(Rtnl::Ack)
Sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Ensure the header (NetlinkHeader) is consistent with the payload (NetlinkPayload):
- compute the payload length and set the header’s length field
- check the payload type and set the header’s message type field accordingly
If you are not 100% sure the header is correct, this method should be called before calling
Emitable::emit() or
to_bytes(). emit() could panic if the header is inconsistent with
the rest of the message, and to_bytes() would return an error.
Trait Implementations§
Source§impl Clone for NetlinkMessage
impl Clone for NetlinkMessage
Source§fn clone(&self) -> NetlinkMessage
fn clone(&self) -> NetlinkMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more