Skip to content

Commit 205a626

Browse files
committed
refactor(net): simplify IP address creation
1 parent 9b2ddc4 commit 205a626

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

src/executor/device.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use smoltcp::socket::dhcpv4;
1313
use smoltcp::socket::dns;
1414
use smoltcp::time::Instant;
1515
#[cfg(not(feature = "dhcpv4"))]
16+
use smoltcp::wire::IpCidr;
17+
#[cfg(not(feature = "dhcpv4"))]
1618
use smoltcp::wire::Ipv4Address;
1719
use smoltcp::wire::{EthernetAddress, HardwareAddress};
18-
#[cfg(not(feature = "dhcpv4"))]
19-
use smoltcp::wire::{IpAddress, IpCidr};
2020

2121
use super::network::{NetworkInterface, NetworkState};
2222
use crate::arch;
@@ -135,15 +135,7 @@ impl<'a> NetworkInterface<'a> {
135135

136136
let ethernet_addr = EthernetAddress(mac);
137137
let hardware_addr = HardwareAddress::Ethernet(ethernet_addr);
138-
let ip_addrs = [IpCidr::new(
139-
IpAddress::v4(
140-
myip.octets()[0],
141-
myip.octets()[1],
142-
myip.octets()[2],
143-
myip.octets()[3],
144-
),
145-
prefix_len,
146-
)];
138+
let ip_addrs = [IpCidr::new(myip.into(), prefix_len)];
147139

148140
info!("MAC address {hardware_addr}");
149141
info!("Configure network interface with address {}", ip_addrs[0]);
@@ -160,17 +152,7 @@ impl<'a> NetworkInterface<'a> {
160152

161153
let mut iface = Interface::new(config, &mut device, crate::executor::network::now());
162154
iface.update_ip_addrs(|ip_addrs| {
163-
ip_addrs
164-
.push(IpCidr::new(
165-
IpAddress::v4(
166-
myip.octets()[0],
167-
myip.octets()[1],
168-
myip.octets()[2],
169-
myip.octets()[3],
170-
),
171-
prefix_len,
172-
))
173-
.unwrap();
155+
ip_addrs.push(IpCidr::new(myip.into(), prefix_len)).unwrap();
174156
});
175157
iface.routes_mut().add_default_ipv4_route(mygw).unwrap();
176158

0 commit comments

Comments
 (0)