Commit 1191598 1 parent 53d7d0f commit 1191598 Copy full SHA for 1191598
File tree 1 file changed +5
-11
lines changed
1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -38,14 +38,8 @@ fn main() {
38
38
config. random_seed = rand:: random ( ) ;
39
39
let mut iface = Interface :: new ( config, & mut device, Instant :: now ( ) ) ;
40
40
41
- // Initialize with an address so that there is something to mutate later.
42
- // This also allows sockets made before a real address is negotiated
43
- // via DHCP to update properly afterward.
44
- iface. update_ip_addrs ( |addrs| {
45
- addrs
46
- . push ( IpCidr :: Ipv4 ( Ipv4Cidr :: new ( Ipv4Address :: UNSPECIFIED , 0 ) ) )
47
- . unwrap ( ) ;
48
- } ) ;
41
+ // Initialize with an unspecified address
42
+ set_ipv4_addr ( & mut iface, Ipv4Cidr :: new ( Ipv4Address :: UNSPECIFIED , 0 ) ) ;
49
43
50
44
// Create sockets
51
45
let mut dhcp_socket = dhcpv4:: Socket :: new ( ) ;
@@ -95,10 +89,10 @@ fn main() {
95
89
}
96
90
}
97
91
98
- /// Mutate the first IP address to match the one supplied
92
+ /// Clear any existing IP addresses & add the new one
99
93
fn set_ipv4_addr ( iface : & mut Interface , cidr : Ipv4Cidr ) {
100
94
iface. update_ip_addrs ( |addrs| {
101
- let dest = addrs. iter_mut ( ) . next ( ) . unwrap ( ) ;
102
- * dest = IpCidr :: Ipv4 ( cidr) ;
95
+ addrs. clear ( ) ;
96
+ addrs . push ( IpCidr :: Ipv4 ( cidr) ) . unwrap ( ) ;
103
97
} ) ;
104
98
}
You can’t perform that action at this time.
0 commit comments