nrf_modem/
embedded_nal_async.rs1use crate::DnsQuery;
2
3#[derive(Copy, Clone, Debug)]
10#[cfg_attr(feature = "defmt", derive(defmt::Format))]
11pub struct ModemNal;
12
13impl embedded_nal_async::Dns for ModemNal {
14 type Error = crate::Error;
15
16 async fn get_host_by_name(
17 &self,
18 hostname: &str,
19 addr_type: embedded_nal_async::AddrType,
20 ) -> Result<core::net::IpAddr, Self::Error> {
21 let query = DnsQuery::new(hostname).with_address_type(addr_type.into());
22 crate::dns::resolve_dns(query).await
23 }
24
25 async fn get_host_by_address(
26 &self,
27 _addr: core::net::IpAddr,
28 _result: &mut [u8],
29 ) -> Result<usize, Self::Error> {
30 Err(crate::Error::ReverseDnsLookupNotSupported)
31 }
32}
33
34impl embedded_nal_async::TcpConnect for ModemNal {
35 type Error = crate::Error;
36
37 type Connection<'a> = crate::TcpStream;
38
39 async fn connect<'a>(
40 &'a self,
41 remote: core::net::SocketAddr,
42 ) -> Result<Self::Connection<'a>, Self::Error> {
43 crate::TcpStream::connect(remote).await
44 }
45}
46
47impl From<embedded_nal_async::AddrType> for crate::dns::AddrType {
48 fn from(value: embedded_nal_async::AddrType) -> Self {
49 match value {
50 embedded_nal_async::AddrType::Either => Self::Any,
51 embedded_nal_async::AddrType::IPv4 => Self::V4,
52 embedded_nal_async::AddrType::IPv6 => Self::V6,
53 }
54 }
55}