From d5f88e578c98555d3fc57924dfb7974c9789aa06 Mon Sep 17 00:00:00 2001 From: kbleeke Date: Sat, 25 Feb 2023 20:58:28 +0100 Subject: [PATCH] embassy-net: DNS resolver detects when name is just an IP address and returns immediately --- embassy-net/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index bda5f9e14..4ec1b5a77 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -236,6 +236,22 @@ impl Stack { /// Make a query for a given name and return the corresponding IP addresses. #[cfg(feature = "dns")] pub async fn dns_query(&self, name: &str, qtype: dns::DnsQueryType) -> Result, dns::Error> { + // For A and AAAA queries we try detect whether `name` is just an IP address + match qtype { + dns::DnsQueryType::A => { + if let Ok(ip) = name.parse().map(IpAddress::Ipv4) { + return Ok([ip].into_iter().collect()); + } + } + #[cfg(feature = "proto-ipv6")] + dns::DnsQueryType::Aaaa => { + if let Ok(ip) = name.parse().map(IpAddress::Ipv6) { + return Ok([ip].into_iter().collect()); + } + } + _ => {} + } + let query = poll_fn(|cx| { self.with_mut(|s, i| { let socket = s.sockets.get_mut::(i.dns_socket);