We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5eced2a commit 28b9901Copy full SHA for 28b9901
examples/dhcp_client.rs
@@ -38,6 +38,9 @@ fn main() {
38
config.random_seed = rand::random();
39
let mut iface = Interface::new(config, &mut device, Instant::now());
40
41
+ // Initialize with an unspecified address
42
+ set_ipv4_addr(&mut iface, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0));
43
+
44
// Create sockets
45
let mut dhcp_socket = dhcpv4::Socket::new();
46
@@ -86,9 +89,10 @@ fn main() {
86
89
}
87
90
88
91
92
+/// Clear any existing IP addresses & add the new one
93
fn set_ipv4_addr(iface: &mut Interface, cidr: Ipv4Cidr) {
94
iface.update_ip_addrs(|addrs| {
- let dest = addrs.iter_mut().next().unwrap();
- *dest = IpCidr::Ipv4(cidr);
95
+ addrs.clear();
96
+ addrs.push(IpCidr::Ipv4(cidr)).unwrap();
97
});
98
0 commit comments