Skip to content

Commit 1bcd276

Browse files
committed
refactor(net): deduplicate IP CIDR block creation
1 parent 517adc6 commit 1bcd276

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/executor/device.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use smoltcp::socket::dns;
1414
use smoltcp::time::Instant;
1515
use smoltcp::wire::{EthernetAddress, HardwareAddress};
1616
#[cfg(not(feature = "dhcpv4"))]
17-
use smoltcp::wire::{Ipv4Address, Ipv4Cidr};
17+
use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr};
1818

1919
use super::network::{NetworkInterface, NetworkState};
2020
use crate::arch;
@@ -128,10 +128,10 @@ impl<'a> NetworkInterface<'a> {
128128

129129
let ethernet_addr = EthernetAddress(mac);
130130
let hardware_addr = HardwareAddress::Ethernet(ethernet_addr);
131-
let ip_addrs = [Ipv4Cidr::from_netmask(myip, mymask).unwrap()];
131+
let ip_addr = IpCidr::from(Ipv4Cidr::from_netmask(myip, mymask).unwrap());
132132

133133
info!("MAC address {hardware_addr}");
134-
info!("Configure network interface with address {}", ip_addrs[0]);
134+
info!("Configure network interface with address {ip_addr}");
135135
info!("Configure gateway with address {mygw}");
136136
info!("{checksums:?}");
137137
info!("MTU: {mtu} bytes");
@@ -145,9 +145,7 @@ impl<'a> NetworkInterface<'a> {
145145

146146
let mut iface = Interface::new(config, &mut device, crate::executor::network::now());
147147
iface.update_ip_addrs(|ip_addrs| {
148-
ip_addrs
149-
.push(Ipv4Cidr::from_netmask(myip, mymask).unwrap().into())
150-
.unwrap();
148+
ip_addrs.push(ip_addr).unwrap();
151149
});
152150
iface.routes_mut().add_default_ipv4_route(mygw).unwrap();
153151

0 commit comments

Comments
 (0)