smoltcp::socket::dhcpv4

Struct Socket

Source
pub struct Socket<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Socket<'a>

DHCP client socket.

The socket acquires an IP address configuration through DHCP autonomously. You must query the configuration with .poll() after every call to Interface::poll(), and apply the configuration to the Interface.

Source

pub fn new() -> Self

Create a DHCPv4 socket

Source

pub fn set_retry_config(&mut self, config: RetryConfig)

Set the retry/timeouts configuration.

Source

pub fn get_retry_config(&self) -> RetryConfig

Gets the current retry/timeouts configuration

Source

pub fn set_outgoing_options(&mut self, options: &'a [DhcpOption<'a>])

Set the outgoing options.

Source

pub fn set_receive_packet_buffer(&mut self, buffer: &'a mut [u8])

Set the buffer into which incoming DHCP packets are copied into.

Source

pub fn set_parameter_request_list(&mut self, parameter_request_list: &'a [u8])

Set the parameter request list.

This should contain at least OPT_SUBNET_MASK (1), OPT_ROUTER (3), and OPT_DOMAIN_NAME_SERVER (6).

Source

pub fn max_lease_duration(&self) -> Option<Duration>

Get the configured max lease duration.

See also Self::set_max_lease_duration()

Source

pub fn set_max_lease_duration(&mut self, max_lease_duration: Option<Duration>)

Set the max lease duration.

When set, the lease duration will be capped at the configured duration if the DHCP server gives us a longer lease. This is generally not recommended, but can be useful for debugging or reacting faster to network configuration changes.

If None, no max is applied (the lease duration from the DHCP server is used.)

Source

pub fn ignore_naks(&self) -> bool

Get whether to ignore NAKs.

See also Self::set_ignore_naks()

Source

pub fn set_ignore_naks(&mut self, ignore_naks: bool)

Set whether to ignore NAKs.

This is not compliant with the DHCP RFCs, since theoretically we must stop using the assigned IP when receiving a NAK. This can increase reliability on broken networks with buggy routers or rogue DHCP servers, however.

Source

pub fn set_ports(&mut self, server_port: u16, client_port: u16)

Set the server/client port

Allows you to specify the ports used by DHCP. This is meant to support esoteric usecases allowed by the dhclient program.

Source

pub fn reset(&mut self)

Reset state and restart discovery phase.

Use this to speed up acquisition of an address in a new network if a link was down and it is now back up.

Source

pub fn poll(&mut self) -> Option<Event<'_>>

Query the socket for configuration changes.

The socket has an internal “configuration changed” flag. If set, this function returns the configuration and resets the flag.

Source

pub fn register_waker(&mut self, waker: &Waker)

Register a waker.

The waker is woken on state changes that might affect the return value of poll method calls, which indicates a new state in the DHCP configuration provided by this DHCP socket.

Notes:

  • Only one waker can be registered at a time. If another waker was previously registered, it is overwritten and will no longer be woken.
  • The Waker is woken only once. Once woken, you must register it again to receive more wakes.

Trait Implementations§

Source§

impl<'a> AnySocket<'a> for Socket<'a>

Source§

fn upcast(self) -> Socket<'a>

Source§

fn downcast<'c>(socket: &'c Socket<'a>) -> Option<&'c Self>

Source§

fn downcast_mut<'c>(socket: &'c mut Socket<'a>) -> Option<&'c mut Self>

Source§

impl<'a> Debug for Socket<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Socket<'a>

§

impl<'a> RefUnwindSafe for Socket<'a>

§

impl<'a> Send for Socket<'a>

§

impl<'a> Sync for Socket<'a>

§

impl<'a> Unpin for Socket<'a>

§

impl<'a> !UnwindSafe for Socket<'a>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.