@@ -10,7 +10,7 @@ use std::collections::BTreeMap;
1010use std:: os:: unix:: io:: AsRawFd ;
1111use smoltcp:: phy:: wait as phy_wait;
1212use smoltcp:: wire:: { EthernetAddress , Ipv4Address , IpCidr } ;
13- use smoltcp:: iface:: { NeighborCache , EthernetInterfaceBuilder } ;
13+ use smoltcp:: iface:: { NeighborCache , EthernetInterfaceBuilder , Routes } ;
1414use smoltcp:: socket:: { SocketSet , RawSocketBuffer , RawPacketMetadata } ;
1515use smoltcp:: time:: Instant ;
1616use smoltcp:: dhcp:: Dhcpv4Client ;
@@ -28,11 +28,13 @@ fn main() {
2828 let neighbor_cache = NeighborCache :: new ( BTreeMap :: new ( ) ) ;
2929 let ethernet_addr = EthernetAddress ( [ 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 ] ) ;
3030 let ip_addrs = [ IpCidr :: new ( Ipv4Address :: UNSPECIFIED . into ( ) , 0 ) ] ;
31+ let mut routes_storage = [ None ; 1 ] ;
32+ let routes = Routes :: new ( & mut routes_storage[ ..] ) ;
3133 let mut iface = EthernetInterfaceBuilder :: new ( device)
3234 . ethernet_addr ( ethernet_addr)
3335 . neighbor_cache ( neighbor_cache)
3436 . ip_addrs ( ip_addrs)
35- . ipv4_gateway ( Ipv4Address :: UNSPECIFIED )
37+ . routes ( routes )
3638 . finalize ( ) ;
3739
3840 let mut sockets = SocketSet :: new ( vec ! [ ] ) ;
@@ -56,7 +58,13 @@ fn main() {
5658 let ip_addr = iface. ipv4_addr ( ) . unwrap ( ) ;
5759 if ip_addr != prev_ip_addr {
5860 println ! ( "Assigned a new IPv4 address: {}" , ip_addr) ;
59- println ! ( "Default gateway: {}" , iface. ipv4_gateway( ) . unwrap( ) ) ;
61+ iface. routes_mut ( )
62+ . update ( |routes_map| {
63+ routes_map. get ( & IpCidr :: new ( Ipv4Address :: UNSPECIFIED . into ( ) , 0 ) )
64+ . map ( |default_route| {
65+ println ! ( "Default gateway: {}" , default_route. via_router) ;
66+ } ) ;
67+ } ) ;
6068 for dns_server in dhcp. dns_servers ( ) {
6169 println ! ( "DNS servers: {}" , dns_server) ;
6270 }
0 commit comments