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: SocketA 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
impl Client
Sourcepub fn new(config: &ClientConfig) -> Self
pub fn new(config: &ClientConfig) -> Self
A wrapper around UdpSocket::bind
Sourcepub fn set_rng(&mut self, rng: Box<dyn RngCore>)
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));Sourcepub fn discover(&mut self) -> Message
pub fn discover(&mut self) -> Message
Sent from the client to server as the start of a DHCP conversation.
Sourcepub fn extend(&mut self, address: Ipv4Addr) -> Message
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
Sourcepub fn verify(&mut self, address: Ipv4Addr) -> Message
pub fn verify(&mut self, address: Ipv4Addr) -> Message
Broadcast from client to server (during INIT-REBOOT) to verify a previously allocated, cached configuration.
Sourcepub fn request(&self, message: Message) -> Message
pub fn request(&self, message: Message) -> Message
Broadcast from the client to server (during SELECTING) following an Offer message.