diff --git a/edge-nal-embassy/CHANGELOG.md b/edge-nal-embassy/CHANGELOG.md index 16ea46f..70e60aa 100644 --- a/edge-nal-embassy/CHANGELOG.md +++ b/edge-nal-embassy/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.1] - 2024-01-05 +* Fix regression: ability to UDP/TCP bind to socket 0.0.0.0 + ## [0.4.0] - 2024-01-02 * Proper TCP socket shutdown; Generic TCP timeout utils; built-in HTTP server timeouts; update docu (#34) * fix a typo (#44) diff --git a/edge-nal-embassy/Cargo.toml b/edge-nal-embassy/Cargo.toml index cce7e3e..cf0d55f 100644 --- a/edge-nal-embassy/Cargo.toml +++ b/edge-nal-embassy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edge-nal-embassy" -version = "0.4.0" +version = "0.4.1" edition = "2021" rust-version = "1.77" description = "An implementation of edge-nal based on `embassy-net`" diff --git a/edge-nal-embassy/src/lib.rs b/edge-nal-embassy/src/lib.rs index 5fdc7c8..9722dc6 100644 --- a/edge-nal-embassy/src/lib.rs +++ b/edge-nal-embassy/src/lib.rs @@ -7,7 +7,7 @@ use core::mem::MaybeUninit; use core::net::SocketAddr; use core::ptr::NonNull; -use embassy_net::IpEndpoint; +use embassy_net::{IpEndpoint, IpListenEndpoint}; pub use dns::*; pub use tcp::*; @@ -72,3 +72,17 @@ pub(crate) fn to_net_socket(socket: IpEndpoint) -> SocketAddr { // socket.port, // ) // } + +pub(crate) fn to_emb_socket(socket: SocketAddr) -> IpEndpoint { + IpEndpoint { + addr: socket.ip().into(), + port: socket.port(), + } +} + +pub(crate) fn to_emb_bind_socket(socket: SocketAddr) -> IpListenEndpoint { + IpListenEndpoint { + addr: (!socket.ip().is_unspecified()).then(|| socket.ip().into()), + port: socket.port(), + } +} diff --git a/edge-nal-embassy/src/tcp.rs b/edge-nal-embassy/src/tcp.rs index 2575a68..fd8df39 100644 --- a/edge-nal-embassy/src/tcp.rs +++ b/edge-nal-embassy/src/tcp.rs @@ -11,7 +11,7 @@ use embassy_net::Stack; use embedded_io_async::{ErrorKind, ErrorType, Read, Write}; -use crate::{to_net_socket, Pool}; +use crate::{to_emb_bind_socket, to_emb_socket, to_net_socket, Pool}; /// A struct that implements the `TcpConnect` and `TcpBind` factory traits from `edge-nal` /// Capable of managing up to N concurrent connections with TX and RX buffers according to TX_SZ and RX_SZ. @@ -44,7 +44,7 @@ impl TcpConnect async fn connect(&self, remote: SocketAddr) -> Result, Self::Error> { let mut socket = TcpSocket::new(self.stack, self.buffers)?; - socket.socket.connect(remote).await?; + socket.socket.connect(to_emb_socket(remote)).await?; Ok(socket) } @@ -82,7 +82,7 @@ impl edge_nal::TcpAccept async fn accept(&self) -> Result<(SocketAddr, Self::Socket<'_>), Self::Error> { let mut socket = TcpSocket::new(self.stack.stack, self.stack.buffers)?; - socket.socket.accept(self.local).await?; + socket.socket.accept(to_emb_bind_socket(self.local)).await?; let local_endpoint = socket.socket.local_endpoint().unwrap(); diff --git a/edge-nal-embassy/src/udp.rs b/edge-nal-embassy/src/udp.rs index 5c2d10f..65b2cb5 100644 --- a/edge-nal-embassy/src/udp.rs +++ b/edge-nal-embassy/src/udp.rs @@ -8,7 +8,7 @@ use embassy_net::{MulticastError, Stack}; use embedded_io_async::{ErrorKind, ErrorType}; -use crate::{to_net_socket, Pool}; +use crate::{to_emb_bind_socket, to_emb_socket, to_net_socket, Pool}; /// A struct that implements the `UdpBind` factory trait from `edge-nal` /// Capable of managing up to N concurrent connections with TX and RX buffers according to TX_SZ and RX_SZ, and packet metadata according to `M`. @@ -49,7 +49,7 @@ impl Udp async fn bind(&self, local: SocketAddr) -> Result, Self::Error> { let mut socket = UdpSocket::new(self.stack, self.buffers)?; - socket.socket.bind(local)?; + socket.socket.bind(to_emb_bind_socket(local))?; Ok(socket) } @@ -125,7 +125,7 @@ impl Udp for UdpSocket<'_, N, TX_SZ, RX_SZ, M> { async fn send(&mut self, remote: SocketAddr, data: &[u8]) -> Result<(), Self::Error> { - self.socket.send_to(data, remote).await?; + self.socket.send_to(data, to_emb_socket(remote)).await?; Ok(()) }