Struct rtnetlink::NetlinkHeader [−][src]
pub struct NetlinkHeader { /* fields omitted */ }
A Netlink header representation.
A netlink header has the following structure:
0 8 16 24 32
+----------------+----------------+----------------+----------------+
| packet length (including header) |
+----------------+----------------+----------------+----------------+
| message type | flags |
+----------------+----------------+----------------+----------------+
| sequence number |
+----------------+----------------+----------------+----------------+
| port number (formerly known as PID) |
+----------------+----------------+----------------+----------------+
Example: parsing a netlink header
extern crate rtnetlink; use rtnetlink::{NetlinkBuffer, NetlinkHeader, Parseable}; use rtnetlink::constants::{RTM_GETLINK, NLM_F_ROOT, NLM_F_REQUEST, NLM_F_MATCH}; // a packet captured with tcpdump that was sent when running `ip link show` static PKT: [u8; 40] = [ 0x28, 0x00, 0x00, 0x00, // length = 40 0x12, 0x00, // message type = 18 (RTM_GETLINK) 0x01, 0x03, // flags = Request + Specify Tree Root + Return All Matching 0x34, 0x0e, 0xf9, 0x5a, // sequence number = 1526271540 0x00, 0x00, 0x00, 0x00, // port id = 0 // payload 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x01, 0x00, 0x00, 0x00]; fn main() { let pkt: NetlinkHeader = NetlinkBuffer::new_checked(&PKT[..]).unwrap().parse().unwrap(); assert_eq!(pkt.length(), 40); assert_eq!(pkt.message_type(), RTM_GETLINK); assert_eq!(pkt.sequence_number(), 1_526_271_540); assert_eq!(pkt.port_number(), 0); assert_eq!(u16::from(pkt.flags()), NLM_F_ROOT | NLM_F_REQUEST | NLM_F_MATCH); }
Example: emitting a netlink header
extern crate rtnetlink; use rtnetlink::{NetlinkBuffer, NetlinkHeader, NetlinkFlags, Emitable}; use rtnetlink::constants::{RTM_GETLINK, NLM_F_ROOT, NLM_F_REQUEST, NLM_F_MATCH}; // a packet captured with tcpdump that was sent when running `ip link show` static PKT: [u8; 40] = [ 0x28, 0x00, 0x00, 0x00, // length = 40 0x12, 0x00, // message type = 18 (RTM_GETLINK) 0x01, 0x03, // flags = Request + Specify Tree Root + Return All Matching 0x34, 0x0e, 0xf9, 0x5a, // sequence number = 1526271540 0x00, 0x00, 0x00, 0x00, // port id = 0 // payload 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x01, 0x00, 0x00, 0x00]; fn main() { let flags = NetlinkFlags::from(NLM_F_ROOT | NLM_F_REQUEST | NLM_F_MATCH); let pkt = NetlinkHeader::new(40, RTM_GETLINK, flags, 0x5af9_0e34, 0); assert_eq!(pkt.buffer_len(), 16); let mut buf = vec![0; 16]; pkt.emit(&mut buf[..]); assert_eq!(&buf[..], &PKT[..16]); }
Methods
impl NetlinkHeader
[src]
impl NetlinkHeader
pub fn new(
length: u32,
message_type: u16,
flags: NetlinkFlags,
sequence_number: u32,
port_number: u32
) -> Self
[src]
pub fn new(
length: u32,
message_type: u16,
flags: NetlinkFlags,
sequence_number: u32,
port_number: u32
) -> Self
Create a new header, initialized with the given values
pub fn length(&self) -> u32
[src]
pub fn length(&self) -> u32
Get the length field
pub fn length_mut(&mut self) -> &mut u32
[src]
pub fn length_mut(&mut self) -> &mut u32
Get a mutable reference to the length field
pub fn set_length(&mut self, value: u32) -> &mut Self
[src]
pub fn set_length(&mut self, value: u32) -> &mut Self
Setter for the length field
pub fn message_type(&self) -> u16
[src]
pub fn message_type(&self) -> u16
Get the message type field
pub fn message_type_mut(&mut self) -> &mut u16
[src]
pub fn message_type_mut(&mut self) -> &mut u16
Get a mutable reference to the message type field
pub fn set_message_type(&mut self, value: u16) -> &mut Self
[src]
pub fn set_message_type(&mut self, value: u16) -> &mut Self
Setter for the message_type field
pub fn flags(&self) -> NetlinkFlags
[src]
pub fn flags(&self) -> NetlinkFlags
Get the flags field
pub fn flags_mut(&mut self) -> &mut NetlinkFlags
[src]
pub fn flags_mut(&mut self) -> &mut NetlinkFlags
Get a mutable reference to the flags field
pub fn set_flags(&mut self, value: NetlinkFlags) -> &mut Self
[src]
pub fn set_flags(&mut self, value: NetlinkFlags) -> &mut Self
Setter for the flags field
pub fn sequence_number(&self) -> u32
[src]
pub fn sequence_number(&self) -> u32
Get the sequence number field
pub fn sequence_number_mut(&mut self) -> &mut u32
[src]
pub fn sequence_number_mut(&mut self) -> &mut u32
Get a mutable reference to the sequence number field
pub fn set_sequence_number(&mut self, value: u32) -> &mut Self
[src]
pub fn set_sequence_number(&mut self, value: u32) -> &mut Self
Setter for the sequence number field
pub fn port_number(&self) -> u32
[src]
pub fn port_number(&self) -> u32
Get the port number field
pub fn port_number_mut(&mut self) -> &mut u32
[src]
pub fn port_number_mut(&mut self) -> &mut u32
Get a mutable reference to the port number field
pub fn set_port_number(&mut self, value: u32) -> &mut Self
[src]
pub fn set_port_number(&mut self, value: u32) -> &mut Self
Setter for the port number field
Trait Implementations
impl Debug for NetlinkHeader
[src]
impl Debug for NetlinkHeader
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for NetlinkHeader
[src]
impl PartialEq for NetlinkHeader
fn eq(&self, other: &NetlinkHeader) -> bool
[src]
fn eq(&self, other: &NetlinkHeader) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &NetlinkHeader) -> bool
[src]
fn ne(&self, other: &NetlinkHeader) -> bool
This method tests for !=
.
impl Eq for NetlinkHeader
[src]
impl Eq for NetlinkHeader
impl Clone for NetlinkHeader
[src]
impl Clone for NetlinkHeader
fn clone(&self) -> NetlinkHeader
[src]
fn clone(&self) -> NetlinkHeader
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for NetlinkHeader
[src]
impl Copy for NetlinkHeader
impl Hash for NetlinkHeader
[src]
impl Hash for NetlinkHeader
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Default for NetlinkHeader
[src]
impl Default for NetlinkHeader
fn default() -> NetlinkHeader
[src]
fn default() -> NetlinkHeader
Returns the "default value" for a type. Read more
impl Emitable for NetlinkHeader
[src]
impl Emitable for NetlinkHeader
fn buffer_len(&self) -> usize
[src]
fn buffer_len(&self) -> usize
Return the length of the serialized data.
fn emit(&self, buffer: &mut [u8])
[src]
fn emit(&self, buffer: &mut [u8])
Serialize this types and write the serialized data into the given buffer. Read more
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NetlinkHeader> for NetlinkBuffer<&'a T>
[src]
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NetlinkHeader> for NetlinkBuffer<&'a T>
fn parse(&self) -> Result<NetlinkHeader>
[src]
fn parse(&self) -> Result<NetlinkHeader>
Deserialize the current type.
Auto Trait Implementations
impl Send for NetlinkHeader
impl Send for NetlinkHeader
impl Sync for NetlinkHeader
impl Sync for NetlinkHeader