Expand description
DHCPv4
This module provides types and utility functions for encoding/decoding a DHCPv4 message.
Example - constructing messages
use dhcproto::{v4, Encodable, Encoder};
// arbitrary hardware addr
let chaddr = vec![
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
];
// construct a new Message
let mut msg = v4::Message::default();
msg.set_flags(v4::Flags::default().set_broadcast()) // set broadcast to true
.set_chaddr(&chaddr) // set chaddr
.opts_mut()
.insert(v4::DhcpOption::MessageType(v4::MessageType::Discover)); // set msg type
// set some more options
msg.opts_mut()
.insert(v4::DhcpOption::ParameterRequestList(vec![
v4::OptionCode::SubnetMask,
v4::OptionCode::Router,
v4::OptionCode::DomainNameServer,
v4::OptionCode::DomainName,
]));
msg.opts_mut()
.insert(v4::DhcpOption::ClientIdentifier(chaddr));
// now encode to bytes
let mut buf = Vec::new();
let mut e = Encoder::new(&mut buf);
msg.encode(&mut e)?;
// buf now has the contents of the encoded DHCP message
Example - decoding messages
use dhcproto::{v4::Message, Decoder, Decodable};
let offer = bootreq();
let msg = Message::decode(&mut Decoder::new(&offer))?;
Re-exports
pub use crate::decoder::Decodable;
pub use crate::decoder::Decoder;
pub use crate::encoder::Encodable;
pub use crate::encoder::Encoder;
pub use crate::error::*;
Modules
Structs
- ex
- Represents available flags on message
- An as-of-yet unimplemented option type
Enums
- Architecture name from - https://www.rfc-editor.org/rfc/rfc4578.html
- AutoConfigure option values
- DHCP Options
- Hardware type of message
- The DHCP message type https://datatracker.ietf.org/doc/html/rfc2131#section-3.1
- NetBIOS allows several different node types
- Opcode of Message
- DHCP Options
Constants
- default dhcpv4 client port
- default dhcpv4 server port
Functions
- Splits
bytes
into chunks of up to u8::MAX (255 is the max opt length), where each chunk is prepended by the length of the chunk and the code. - Splits
bytes
into chunks of up to u8::MAX /factor
(255 is the max opt length), where each chunk is prepended by the length of the chunk and the code. - Encodes a list of domain
Name
s but chunked into u8::MAX pieces, where each chunk is prepended by the length of the chunk and the code.