smoltcp::wire

Struct DhcpRepr

Source
pub struct DhcpRepr<'a> {
Show 21 fields pub message_type: MessageType, pub transaction_id: u32, pub secs: u16, pub client_hardware_address: EthernetAddress, pub client_ip: Ipv4Address, pub your_ip: Ipv4Address, pub server_ip: Ipv4Address, pub router: Option<Ipv4Address>, pub subnet_mask: Option<Ipv4Address>, pub relay_agent_ip: Ipv4Address, pub broadcast: bool, pub requested_ip: Option<Ipv4Address>, pub client_identifier: Option<EthernetAddress>, pub server_identifier: Option<Ipv4Address>, pub parameter_request_list: Option<&'a [u8]>, pub dns_servers: Option<Vec<Ipv4Address, MAX_DNS_SERVER_COUNT>>, pub max_size: Option<u16>, pub lease_duration: Option<u32>, pub renew_duration: Option<u32>, pub rebind_duration: Option<u32>, pub additional_options: &'a [DhcpOption<'a>],
}
Expand description

A high-level representation of a Dynamic Host Configuration Protocol packet.

DHCP messages have the following layout (see RFC 2131 for details):

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| message_type  | htype (N/A)   |   hlen (N/A)  |   hops        |
+---------------+---------------+---------------+---------------+
|                       transaction_id                          |
+-------------------------------+-------------------------------+
|           secs                |           flags               |
+-------------------------------+-------------------------------+
|                           client_ip                           |
+---------------------------------------------------------------+
|                            your_ip                            |
+---------------------------------------------------------------+
|                           server_ip                           |
+---------------------------------------------------------------+
|                        relay_agent_ip                         |
+---------------------------------------------------------------+
|                                                               |
|                    client_hardware_address                    |
|                                                               |
|                                                               |
+---------------------------------------------------------------+
|                                                               |
|                          sname  (N/A)                         |
+---------------------------------------------------------------+
|                                                               |
|                          file    (N/A)                        |
+---------------------------------------------------------------+
|                                                               |
|                          options                              |
+---------------------------------------------------------------+

It is assumed that the access layer is Ethernet, so htype (the field representing the hardware address type) is always set to 1, and hlen (which represents the hardware address length) is set to 6.

The options field has a variable length.

Fields§

§message_type: MessageType

This field is also known as op in the RFC. It indicates the type of DHCP message this packet represents.

§transaction_id: u32

This field is also known as xid in the RFC. It is a random number chosen by the client, used by the client and server to associate messages and responses between a client and a server.

§secs: u16

seconds elapsed since client began address acquisition or renewal process the DHCPREQUEST message MUST use the same value in the DHCP message header’s ‘secs’ field and be sent to the same IP broadcast address as the original DHCPDISCOVER message.

§client_hardware_address: EthernetAddress

This field is also known as chaddr in the RFC and for networks where the access layer is ethernet, it is the client MAC address.

§client_ip: Ipv4Address

This field is also known as ciaddr in the RFC. It is only filled in if client is in BOUND, RENEW or REBINDING state and can respond to ARP requests.

§your_ip: Ipv4Address

This field is also known as yiaddr in the RFC.

§server_ip: Ipv4Address

This field is also known as siaddr in the RFC. It may be set by the server in DHCPOFFER and DHCPACK messages, and represent the address of the next server to use in bootstrap.

§router: Option<Ipv4Address>

Default gateway

§subnet_mask: Option<Ipv4Address>

This field comes from a corresponding DhcpOption.

§relay_agent_ip: Ipv4Address

This field is also known as giaddr in the RFC. In order to allow DHCP clients on subnets not directly served by DHCP servers to communicate with DHCP servers, DHCP relay agents can be installed on these subnets. The DHCP client broadcasts on the local link; the relay agent receives the broadcast and transmits it to one or more DHCP servers using unicast. The relay agent stores its own IP address in the relay_agent_ip field of the DHCP packet. The DHCP server uses the relay_agent_ip to determine the subnet on which the relay agent received the broadcast, and allocates an IP address on that subnet. When the DHCP server replies to the client, it sends the reply to the relay_agent_ip address, again using unicast. The relay agent then retransmits the response on the local network

§broadcast: bool

Broadcast flags. It can be set in DHCPDISCOVER, DHCPINFORM and DHCPREQUEST message if the client requires the response to be broadcasted.

§requested_ip: Option<Ipv4Address>

The “requested IP address” option. It can be used by clients in DHCPREQUEST or DHCPDISCOVER messages, or by servers in DHCPDECLINE messages.

§client_identifier: Option<EthernetAddress>

The “client identifier” option.

The ‘client identifier’ is an opaque key, not to be interpreted by the server; for example, the ‘client identifier’ may contain a hardware address, identical to the contents of the ‘chaddr’ field, or it may contain another type of identifier, such as a DNS name. The ‘client identifier’ chosen by a DHCP client MUST be unique to that client within the subnet to which the client is attached. If the client uses a ‘client identifier’ in one message, it MUST use that same identifier in all subsequent messages, to ensure that all servers correctly identify the client.

§server_identifier: Option<Ipv4Address>

The “server identifier” option. It is used both to identify a DHCP server in a DHCP message and as a destination address from clients to servers.

§parameter_request_list: Option<&'a [u8]>

The parameter request list informs the server about which configuration parameters the client is interested in.

§dns_servers: Option<Vec<Ipv4Address, MAX_DNS_SERVER_COUNT>>

DNS servers

§max_size: Option<u16>

The maximum size dhcp packet the interface can receive

§lease_duration: Option<u32>

The DHCP IP lease duration, specified in seconds.

§renew_duration: Option<u32>

The DHCP IP renew duration (T1 interval), in seconds, if specified in the packet.

§rebind_duration: Option<u32>

The DHCP IP rebind duration (T2 interval), in seconds, if specified in the packet.

§additional_options: &'a [DhcpOption<'a>]

When returned from Repr::parse, this field will be None. However, when calling Repr::emit, this field should contain only additional DHCP options not known to smoltcp.

Implementations§

Source§

impl<'a> Repr<'a>

Source

pub fn buffer_len(&self) -> usize

Return the length of a packet that will be emitted from this high-level representation.

Source

pub fn parse<T>(packet: &'a Packet<&'a T>) -> Result<Self>
where T: AsRef<[u8]> + ?Sized,

Parse a DHCP packet and return a high-level representation.

Source

pub fn emit<T>(&self, packet: &mut Packet<&mut T>) -> Result<()>
where T: AsRef<[u8]> + AsMut<[u8]> + ?Sized,

Emit a high-level representation into a Dynamic Host Configuration Protocol packet.

Trait Implementations§

Source§

impl<'a> Clone for Repr<'a>

Source§

fn clone(&self) -> Repr<'a>

Returns a copy 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<'a> Debug for Repr<'a>

Source§

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

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

impl<'a> PartialEq for Repr<'a>

Source§

fn eq(&self, other: &Repr<'a>) -> 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<'a> Eq for Repr<'a>

Source§

impl<'a> StructuralPartialEq for Repr<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Repr<'a>

§

impl<'a> RefUnwindSafe for Repr<'a>

§

impl<'a> Send for Repr<'a>

§

impl<'a> Sync for Repr<'a>

§

impl<'a> Unpin for Repr<'a>

§

impl<'a> UnwindSafe for Repr<'a>

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.