Skip to content

Commit

Permalink
go back to clearing and pushing new address
Browse files Browse the repository at this point in the history
  • Loading branch information
jlogan03 committed Feb 9, 2024
1 parent 53d7d0f commit 1191598
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions examples/dhcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ fn main() {
config.random_seed = rand::random();
let mut iface = Interface::new(config, &mut device, Instant::now());

// Initialize with an address so that there is something to mutate later.
// This also allows sockets made before a real address is negotiated
// via DHCP to update properly afterward.
iface.update_ip_addrs(|addrs| {
addrs
.push(IpCidr::Ipv4(Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0)))
.unwrap();
});
// Initialize with an unspecified address
set_ipv4_addr(&mut iface, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0));

// Create sockets
let mut dhcp_socket = dhcpv4::Socket::new();
Expand Down Expand Up @@ -95,10 +89,10 @@ fn main() {
}
}

/// Mutate the first IP address to match the one supplied
/// Clear any existing IP addresses & add the new one
fn set_ipv4_addr(iface: &mut Interface, cidr: Ipv4Cidr) {
iface.update_ip_addrs(|addrs| {
let dest = addrs.iter_mut().next().unwrap();
*dest = IpCidr::Ipv4(cidr);
addrs.clear();
addrs.push(IpCidr::Ipv4(cidr)).unwrap();
});
}

0 comments on commit 1191598

Please sign in to comment.