pub struct NetlinkHeader { /* private fields */ }
Expand description

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)             |
+----------------+----------------+----------------+----------------+
extern crate netlink_packet;
use netlink_packet::{NetlinkBuffer, NetlinkHeader, Parseable};
use netlink_packet::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);
}
extern crate netlink_packet;
use netlink_packet::{NetlinkBuffer, NetlinkHeader, NetlinkFlags, Emitable};
use netlink_packet::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]);
}

Implementations§

Create a new header, initialized with the given values

Get the length field

Get a mutable reference to the length field

Setter for the length field

Get the message type field

Get a mutable reference to the message type field

Setter for the message_type field

Get the flags field

Get a mutable reference to the flags field

Setter for the flags field

Get the sequence number field

Get a mutable reference to the sequence number field

Setter for the sequence number field

Get the port number field

Get a mutable reference to the port number field

Setter for the port number field

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
Returns the “default value” for a type. Read more
Return the length of the serialized data.
Serialize this types and write the serialized data into the given buffer. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
Deserialize the current type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.