@@ -12,11 +12,9 @@ use smoltcp::socket::dhcpv4;
12
12
#[ cfg( all( feature = "dns" , not( feature = "dhcpv4" ) ) ) ]
13
13
use smoltcp:: socket:: dns;
14
14
use smoltcp:: time:: Instant ;
15
- #[ cfg( not( feature = "dhcpv4" ) ) ]
16
- use smoltcp:: wire:: Ipv4Address ;
17
15
use smoltcp:: wire:: { EthernetAddress , HardwareAddress } ;
18
16
#[ cfg( not( feature = "dhcpv4" ) ) ]
19
- use smoltcp:: wire:: { IpAddress , IpCidr } ;
17
+ use smoltcp:: wire:: { IpCidr , Ipv4Address , Ipv4Cidr } ;
20
18
21
19
use super :: network:: { NetworkInterface , NetworkState } ;
22
20
use crate :: arch;
@@ -128,34 +126,12 @@ impl<'a> NetworkInterface<'a> {
128
126
#[ cfg( feature = "dns" ) ]
129
127
let mydns2 = Ipv4Address :: from_str ( hermit_var_or ! ( "HERMIT_DNS2" , "1.1.1.1" ) ) . unwrap ( ) ;
130
128
131
- // calculate the netmask length
132
- // => count the number of contiguous 1 bits,
133
- // starting at the most significant bit in the first octet
134
- let mut prefix_len = ( !mymask. octets ( ) [ 0 ] ) . trailing_zeros ( ) ;
135
- if prefix_len == 8 {
136
- prefix_len += ( !mymask. octets ( ) [ 1 ] ) . trailing_zeros ( ) ;
137
- }
138
- if prefix_len == 16 {
139
- prefix_len += ( !mymask. octets ( ) [ 2 ] ) . trailing_zeros ( ) ;
140
- }
141
- if prefix_len == 24 {
142
- prefix_len += ( !mymask. octets ( ) [ 3 ] ) . trailing_zeros ( ) ;
143
- }
144
-
145
- let ethernet_addr = EthernetAddress ( [ mac[ 0 ] , mac[ 1 ] , mac[ 2 ] , mac[ 3 ] , mac[ 4 ] , mac[ 5 ] ] ) ;
129
+ let ethernet_addr = EthernetAddress ( mac) ;
146
130
let hardware_addr = HardwareAddress :: Ethernet ( ethernet_addr) ;
147
- let ip_addrs = [ IpCidr :: new (
148
- IpAddress :: v4 (
149
- myip. octets ( ) [ 0 ] ,
150
- myip. octets ( ) [ 1 ] ,
151
- myip. octets ( ) [ 2 ] ,
152
- myip. octets ( ) [ 3 ] ,
153
- ) ,
154
- prefix_len. try_into ( ) . unwrap ( ) ,
155
- ) ] ;
131
+ let ip_addr = IpCidr :: from ( Ipv4Cidr :: from_netmask ( myip, mymask) . unwrap ( ) ) ;
156
132
157
133
info ! ( "MAC address {hardware_addr}" ) ;
158
- info ! ( "Configure network interface with address {}" , ip_addrs [ 0 ] ) ;
134
+ info ! ( "Configure network interface with address {ip_addr}" ) ;
159
135
info ! ( "Configure gateway with address {mygw}" ) ;
160
136
info ! ( "{checksums:?}" ) ;
161
137
info ! ( "MTU: {mtu} bytes" ) ;
@@ -169,17 +145,7 @@ impl<'a> NetworkInterface<'a> {
169
145
170
146
let mut iface = Interface :: new ( config, & mut device, crate :: executor:: network:: now ( ) ) ;
171
147
iface. update_ip_addrs ( |ip_addrs| {
172
- ip_addrs
173
- . push ( IpCidr :: new (
174
- IpAddress :: v4 (
175
- myip. octets ( ) [ 0 ] ,
176
- myip. octets ( ) [ 1 ] ,
177
- myip. octets ( ) [ 2 ] ,
178
- myip. octets ( ) [ 3 ] ,
179
- ) ,
180
- prefix_len. try_into ( ) . unwrap ( ) ,
181
- ) )
182
- . unwrap ( ) ;
148
+ ip_addrs. push ( ip_addr) . unwrap ( ) ;
183
149
} ) ;
184
150
iface. routes_mut ( ) . add_default_ipv4_route ( mygw) . unwrap ( ) ;
185
151
0 commit comments