Skip to content

Commit 47f79e6

Browse files
authored
Merge pull request #54 from reitermarkus/update-smoltcp
Update `smoltcp` to 0.12.
2 parents c80497a + 57465a2 commit 47f79e6

3 files changed

Lines changed: 28 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](http://keepachangelog.com/)
77
and this project adheres to [Semantic Versioning](http://semver.org/).
88

9+
# [Unreleased](https://github.com/quartiq/smoltcp-nal/compare/v0.6.0...HEAD)
10+
11+
## Changed
12+
13+
* [breaking] `smoltcp` updated to 0.12.
14+
915
# [0.6.0](https://github.com/quartiq/smoltcp-nal/compare/v0.5.1...v0.6.0) - 2025-01-27
1016

17+
## Changed
18+
1119
* [breaking] `embedded-nal` bumped. Now `core::net::SocketAddr` and related ip types are used.
1220
MSRV becomes 1.77.0.
1321

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ default-features = false
2121
features = ["wyrand"]
2222

2323
[dependencies.smoltcp]
24-
version = "0.11"
24+
version = "0.12"
2525
features = [
2626
"medium-ethernet",
2727
"proto-ipv6",

src/lib.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use core::{
1919
convert::TryFrom,
20-
net::{IpAddr, Ipv4Addr, SocketAddr},
20+
net::{IpAddr, SocketAddr},
2121
};
2222
pub use embedded_nal;
2323
use nanorand::{Rng, SeedableRng};
@@ -26,7 +26,7 @@ pub use smoltcp;
2626
use embedded_nal::{TcpClientStack, UdpClientStack, UdpFullStack};
2727
use embedded_time::duration::Milliseconds;
2828
use 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

Comments
 (0)