DhcpFixedPayload

Struct DhcpFixedPayload 

Source
pub struct DhcpFixedPayload { /* private fields */ }
Expand description

The fixed-length part of the DHCP payload. The options section can vary in length, and is handled separately. For “Inform” message kind, this is the entire message.

Implementations§

Source§

impl DhcpFixedPayload

Source

pub fn new( end_of_message: bool, op: DhcpOperation, kind: DhcpMessageKind, transaction_id: u32, broadcast: bool, ciaddr: IpV4Addr, yiaddr: IpV4Addr, siaddr: IpV4Addr, chaddr: MacAddr, ) -> Self

Convenience function to remove boilerplate for predetermined fields.

Source

pub fn new_inform( ipaddr: IpV4Addr, macaddr: MacAddr, transaction_id: u32, ) -> Self

Build a DHCP INFORM message to broadcast to the network indicating that we are taking a pre-assigned IP address which may have already be assigned statically in the configuration of the router. This message should also be accompanied by an ARP “announce” message to broadcast the presence of the machine to others on the network that may or may not receive a forwarded copy of the DHCP INFORM.

Examples found in repository?
examples/dhcp.rs (lines 5-9)
2fn main() -> () {
3    use catnip::*;
4
5    let dhcp_inform = DhcpFixedPayload::new_inform(
6        IpV4Addr::new([1, 2, 3, 4]),
7        MacAddr::new([5, 6, 7, 8, 9, 10]),
8        12345
9    );
10
11    // Serialize
12    let bytes = dhcp_inform.to_be_bytes();
13    // Deserialize
14    let msg_parsed = DhcpFixedPayload::read_bytes(&bytes);
15
16    assert_eq!(msg_parsed, dhcp_inform);
17}
Source

pub fn to_be_bytes(&self) -> [u8; 244]

Pack into big-endian (network) byte array

Examples found in repository?
examples/dhcp.rs (line 12)
2fn main() -> () {
3    use catnip::*;
4
5    let dhcp_inform = DhcpFixedPayload::new_inform(
6        IpV4Addr::new([1, 2, 3, 4]),
7        MacAddr::new([5, 6, 7, 8, 9, 10]),
8        12345
9    );
10
11    // Serialize
12    let bytes = dhcp_inform.to_be_bytes();
13    // Deserialize
14    let msg_parsed = DhcpFixedPayload::read_bytes(&bytes);
15
16    assert_eq!(msg_parsed, dhcp_inform);
17}

Trait Implementations§

Source§

impl ByteStruct for DhcpFixedPayload

Source§

fn write_bytes(&self, bytes: &mut [u8])

Packs the struct into raw bytes and write to a slice
Source§

fn read_bytes(bytes: &[u8]) -> Self

Unpacks raw bytes from a slice into a new struct
Source§

impl ByteStructLen for DhcpFixedPayload

Source§

const BYTE_LEN: usize = 244usize

The length of the packed bytes of this type
Source§

impl Clone for DhcpFixedPayload

Source§

fn clone(&self) -> DhcpFixedPayload

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DhcpFixedPayload

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DhcpFixedPayload

Source§

fn eq(&self, other: &DhcpFixedPayload) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl uDebug for DhcpFixedPayload

Source§

fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
where W: uWrite + ?Sized,

Formats the value using the given formatter
Source§

impl Copy for DhcpFixedPayload

Source§

impl Eq for DhcpFixedPayload

Source§

impl StructuralPartialEq for DhcpFixedPayload

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByteStructUnspecifiedByteOrder for T
where T: ByteStruct,

Source§

fn write_bytes_default_le(&self, bytes: &mut [u8])

Source§

fn read_bytes_default_le(bytes: &[u8]) -> T

Source§

fn write_bytes_default_be(&self, bytes: &mut [u8])

Source§

fn read_bytes_default_be(bytes: &[u8]) -> T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.