Struct smoltcp::socket::dhcpv4::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> 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§

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> 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>,

§

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>,

§

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.