pub struct Message {
pub op: OpCode,
pub xid: u32,
pub secs: u16,
pub bdcast_flag: bool,
pub ciaddr: Ipv4Addr,
pub yiaddr: Ipv4Addr,
pub siaddr: Ipv4Addr,
pub giaddr: Ipv4Addr,
pub chaddr: Mac,
pub sname: String,
pub file: String,
pub options: Vec<DhcpOption>,
}
Expand description
A DHCP protocol message as defined in RFC 2131.
All fields in Message
follow the naming conventions outlined in the RFC.
Note that Message
does not expose htype
, hlen
, or hops
fields, as
these fields are effectively constants.
Fields§
§op: OpCode
§xid: u32
§secs: u16
§bdcast_flag: bool
§ciaddr: Ipv4Addr
ciaddr
should be stored in Big-Endian order, e.g [192, 168, 1, 1]
.
yiaddr: Ipv4Addr
yiaddr
should be stored in Big-Endian order, e.g [192, 168, 1, 1]
.
siaddr: Ipv4Addr
siaddr
should be stored in Big-Endian order, e.g [192, 168, 1, 1]
.
giaddr: Ipv4Addr
giaddr
should be stored in Big-Endian order, e.g [192, 168, 1, 1]
.
chaddr: Mac
chaddr
should be stored in Big-Endian order,
e.g [0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF]
.
sname: String
sname
should not exceed 64 characters.
file: String
file
should not exceed 128 characters.
options: Vec<DhcpOption>
Implementations§
Source§impl Message
impl Message
Sourcepub fn from_buffer(buf: &[u8]) -> Result<Self, ProtocolError>
pub fn from_buffer(buf: &[u8]) -> Result<Self, ProtocolError>
Instantiates a new Message
from a byte buffer conforming to the DHCP
protocol as defined RFC 2131. Returns None
if the buffer is malformed.
Any malformed configuration options will be skipped over, leaving only
well formed DhcpOption
s in the final Message
.
Sourcepub fn serialize(self) -> Vec<u8> ⓘ
pub fn serialize(self) -> Vec<u8> ⓘ
Consumes the calling Message
to serialize it into a buffer of bytes.
Sourcepub fn get_dhcp_type(&self) -> Result<MessageType, ProtocolError>
pub fn get_dhcp_type(&self) -> Result<MessageType, ProtocolError>
Returns the value’s DHCP MessageType
or appropriate MessageTypeError
in case of failure.
Trait Implementations§
Source§impl From<&Message> for ClientIdentifier
impl From<&Message> for ClientIdentifier
Source§fn from(msg: &Message) -> ClientIdentifier
fn from(msg: &Message) -> ClientIdentifier
Returns the opaque client identifier associated with the argument message.
Typically, a message will contain a DhcpOption::ClientIdentifier
which stores the
associated opaque client identifier. In the absence of this option, an identifier
will be constructed from the chaddr
field of the message.