Skip to content

Commit dc771ec

Browse files
committed
update dhcp example to work in the case where we do not already have an ip address from some other source
1 parent 5eced2a commit dc771ec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

examples/dhcp_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fn main() {
7777
}
7878
Some(dhcpv4::Event::Deconfigured) => {
7979
debug!("DHCP lost config!");
80+
iface.update_ip_addrs(|addrs| addrs.clear());
8081
set_ipv4_addr(&mut iface, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0));
8182
iface.routes_mut().remove_default_ipv4_route();
8283
}
@@ -88,7 +89,6 @@ fn main() {
8889

8990
fn set_ipv4_addr(iface: &mut Interface, cidr: Ipv4Cidr) {
9091
iface.update_ip_addrs(|addrs| {
91-
let dest = addrs.iter_mut().next().unwrap();
92-
*dest = IpCidr::Ipv4(cidr);
92+
addrs.push(IpCidr::Ipv4(cidr)).unwrap();
9393
});
9494
}

0 commit comments

Comments
 (0)