Client

Struct Client 

Source
pub struct Client {
    pub socket: Socket,
    pub haddr: [u8; 16],
    /* private fields */
}
Expand description

Logic for a DHCP client using this lib.

Used by the client binary and integration tests.

Requires the v4_client feature, which is enabled by default.

Fields§

§socket: Socket

A UdpSocket that understands Deliverables to communicate with the Server

§haddr: [u8; 16]

The client’s hardware address.

This is cached for use in multiple messages to the server, and the server will reuse it in its replies.

Implementations§

Source§

impl Client

Source

pub fn new(config: &ClientConfig) -> Self

A wrapper around UdpSocket::bind

Source

pub fn set_rng(&mut self, rng: Box<dyn RngCore>)

Change the default random number generator from ThreadRng to any rng that implements RngCore from the rand crate.

For example, you could use SmallRng which is sometimes faster, but has a higher collision rate of 1 in 65,000:

use toe_beans::v4::{Client, ClientConfig};
use std::net::{Ipv4Addr, SocketAddrV4};
use rand::SeedableRng;
use rand::rngs::SmallRng;

let client_config = ClientConfig::default();
let mut client = Client::new(&client_config);

// initialize the random number generator once.
let rng = SmallRng::from_os_rng();

client.set_rng(Box::new(rng));
Source

pub fn discover(&mut self) -> Message

Sent from the client to server as the start of a DHCP conversation.

Source

pub fn extend(&mut self, address: Ipv4Addr) -> Message

Sent from client to server (during RENEWING/REBINDING) when the client has a lease but wants to renew or rebind it.

A renew will unicast, whereas a rebind will broadcast. Rebinding is intended for multiple DHCP servers that can coordinate consistenency of their leases

Source

pub fn verify(&mut self, address: Ipv4Addr) -> Message

Broadcast from client to server (during INIT-REBOOT) to verify a previously allocated, cached configuration.

Source

pub fn request(&self, message: Message) -> Message

Broadcast from the client to server (during SELECTING) following an Offer message.

Source

pub fn decline(&self, message: Message) -> Message

Sent from the client to server (following an Ack) if the IP address is already in use.

Source

pub fn release(&mut self) -> Message

Sent from the client to server.

Source

pub fn inform(&mut self, parameter_list: Vec<u8>) -> Message

Sent from the client to server.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !Send for Client

§

impl !Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V