Skip to content

Commit

Permalink
from-to nal net
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Nov 13, 2023
1 parent 71771ed commit 4181221
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/asynch/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub mod server {
pub dns2: Option<Ipv4Addr>,
pub range_start: Ipv4Addr,
pub range_end: Ipv4Addr,
pub lease_duration: Duration,
pub lease_duration_secs: u32,
}

struct Lease {
Expand Down Expand Up @@ -271,7 +271,7 @@ pub mod server {
dns: conf.dns1.iter().chain(conf.dns2.iter()).cloned().collect(),
range_start: conf.range_start,
range_end: conf.range_end,
lease_duration: conf.lease_duration,
lease_duration: Duration::from_secs(conf.lease_duration_secs as _),
leases: heapless::LinearMap::new(),
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/asynch/stdnal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use futures_lite::io::{AsyncReadExt, AsyncWriteExt};

use embedded_io::ErrorType;
use embedded_io_async::{Read, Write};
use no_std_net::{SocketAddr, SocketAddrV4, SocketAddrV6};
use no_std_net::{Ipv4Addr, SocketAddr, SocketAddrV4, SocketAddrV6};

use embedded_nal_async::{
AddrType, ConnectedUdp, Dns, IpAddr, TcpConnect, UdpStack, UnconnectedUdp,
Expand Down Expand Up @@ -305,7 +305,7 @@ fn dns_lookup_host(host: &str, addr_type: AddrType) -> Result<IpAddr, io::Error>
.ok_or_else(|| io::ErrorKind::AddrNotAvailable.into())
}

fn to_std_addr(addr: SocketAddr) -> std::net::SocketAddr {
pub fn to_std_addr(addr: SocketAddr) -> std::net::SocketAddr {
match addr {
SocketAddr::V4(addr) => net::SocketAddr::V4(net::SocketAddrV4::new(
addr.ip().octets().into(),
Expand All @@ -320,7 +320,7 @@ fn to_std_addr(addr: SocketAddr) -> std::net::SocketAddr {
}
}

fn to_nal_addr(addr: std::net::SocketAddr) -> SocketAddr {
pub fn to_nal_addr(addr: std::net::SocketAddr) -> SocketAddr {
match addr {
net::SocketAddr::V4(addr) => {
SocketAddr::V4(SocketAddrV4::new(addr.ip().octets().into(), addr.port()))
Expand All @@ -333,3 +333,11 @@ fn to_nal_addr(addr: std::net::SocketAddr) -> SocketAddr {
)),
}
}

pub fn to_std_ipv4_addr(addr: Ipv4Addr) -> std::net::Ipv4Addr {
addr.octets().into()
}

pub fn to_nal_ipv4_addr(addr: std::net::Ipv4Addr) -> Ipv4Addr {
addr.octets().into()
}

0 comments on commit 4181221

Please sign in to comment.