1717
1818use core:: {
1919 convert:: TryFrom ,
20- net:: { IpAddr , Ipv4Addr , SocketAddr } ,
20+ net:: { IpAddr , SocketAddr } ,
2121} ;
2222pub use embedded_nal;
2323use nanorand:: { Rng , SeedableRng } ;
@@ -26,7 +26,7 @@ pub use smoltcp;
2626use embedded_nal:: { TcpClientStack , UdpClientStack , UdpFullStack } ;
2727use embedded_time:: duration:: Milliseconds ;
2828use smoltcp:: {
29- iface:: SocketHandle ,
29+ iface:: { PollResult , SocketHandle } ,
3030 socket:: dhcpv4,
3131 wire:: { IpAddress , IpCidr , IpEndpoint , Ipv4Address , Ipv4Cidr } ,
3232} ;
@@ -244,9 +244,11 @@ where
244244 self . last_poll . replace ( self . last_poll . unwrap ( ) + elapsed_ms) ;
245245 }
246246
247- let updated =
247+ let updated = matches ! (
248248 self . network_interface
249- . poll ( self . stack_time , & mut self . device , & mut self . sockets ) ;
249+ . poll( self . stack_time, & mut self . device, & mut self . sockets) ,
250+ PollResult :: SocketStateChanged
251+ ) ;
250252
251253 // Service the DHCP client.
252254 if let Some ( handle) = self . dhcp_handle {
@@ -256,7 +258,13 @@ where
256258 if let Some ( event) = self . sockets . get_mut :: < dhcpv4:: Socket > ( handle) . poll ( ) {
257259 match event {
258260 dhcpv4:: Event :: Configured ( config) => {
259- if config. address . address ( ) . is_unicast ( )
261+ let is_unicast = {
262+ let address = config. address . address ( ) ;
263+ !( address. is_broadcast ( )
264+ || address. is_multicast ( )
265+ || address. is_unspecified ( ) )
266+ } ;
267+ if is_unicast
260268 && self . network_interface . ipv4_addr ( ) . unwrap ( )
261269 != config. address . address ( )
262270 {
@@ -606,12 +614,12 @@ where
606614 . map_err ( |e| embedded_nal:: nb:: Error :: Other ( NetworkError :: UdpReadFailure ( e) ) ) ?;
607615
608616 let source = {
609- let octets = source. endpoint . addr . as_bytes ( ) ;
617+ let addr = match source. endpoint . addr {
618+ IpAddress :: Ipv4 ( addr) => IpAddr :: V4 ( addr) ,
619+ IpAddress :: Ipv6 ( addr) => IpAddr :: V6 ( addr) ,
620+ } ;
610621
611- SocketAddr :: new (
612- IpAddr :: V4 ( Ipv4Addr :: new ( octets[ 0 ] , octets[ 1 ] , octets[ 2 ] , octets[ 3 ] ) ) ,
613- source. endpoint . port ,
614- )
622+ SocketAddr :: new ( addr, source. endpoint . port )
615623 } ;
616624
617625 Ok ( ( size, source) )
@@ -710,7 +718,7 @@ where
710718 let smoltcp:: wire:: IpAddress :: Ipv4 ( addr) = addr else {
711719 panic ! ( "Unexpected address return type" ) ;
712720 } ;
713- return Ok ( IpAddr :: V4 ( addr. 0 . into ( ) ) ) ;
721+ return Ok ( IpAddr :: V4 ( * addr) ) ;
714722 }
715723 Err ( smoltcp:: socket:: dns:: GetQueryResultError :: Pending ) => { }
716724 Err ( smoltcp:: socket:: dns:: GetQueryResultError :: Failed ) => {
0 commit comments