diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-02-26 08:22:38 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-26 08:22:38 +0000 |
| commit | 5367baa845ab00e9567ba968a5b45489fef896fa (patch) | |
| tree | 52e8bb3f5c2567e1ba79771b91871ddc829a3b74 | |
| parent | 64247ae456edbbf49b3ab096278d77da2782cca7 (diff) | |
| parent | d5f88e578c98555d3fc57924dfb7974c9789aa06 (diff) | |
Merge #1238
1238: embassy-net: DNS resolver detects when name is just an IP address r=lulf a=kbleeke
fixes #1237
I am not sure, if this is the right place to put this code. Alternatively, It could be in dns::DnsSocket or reqwless (and all other libraries that need to maybe resolve hostnames).
Are there other DNS query-types where it would make sense to try to parse an IP address?
Co-authored-by: kbleeke <[email protected]>
| -rw-r--r-- | embassy-net/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
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<D: Driver + 'static> Stack<D> { | |||
| 236 | /// Make a query for a given name and return the corresponding IP addresses. | 236 | /// Make a query for a given name and return the corresponding IP addresses. |
| 237 | #[cfg(feature = "dns")] | 237 | #[cfg(feature = "dns")] |
| 238 | pub async fn dns_query(&self, name: &str, qtype: dns::DnsQueryType) -> Result<Vec<IpAddress, 1>, dns::Error> { | 238 | pub async fn dns_query(&self, name: &str, qtype: dns::DnsQueryType) -> Result<Vec<IpAddress, 1>, dns::Error> { |
| 239 | // For A and AAAA queries we try detect whether `name` is just an IP address | ||
| 240 | match qtype { | ||
| 241 | dns::DnsQueryType::A => { | ||
| 242 | if let Ok(ip) = name.parse().map(IpAddress::Ipv4) { | ||
| 243 | return Ok([ip].into_iter().collect()); | ||
| 244 | } | ||
| 245 | } | ||
| 246 | #[cfg(feature = "proto-ipv6")] | ||
| 247 | dns::DnsQueryType::Aaaa => { | ||
| 248 | if let Ok(ip) = name.parse().map(IpAddress::Ipv6) { | ||
| 249 | return Ok([ip].into_iter().collect()); | ||
| 250 | } | ||
| 251 | } | ||
| 252 | _ => {} | ||
| 253 | } | ||
| 254 | |||
| 239 | let query = poll_fn(|cx| { | 255 | let query = poll_fn(|cx| { |
| 240 | self.with_mut(|s, i| { | 256 | self.with_mut(|s, i| { |
| 241 | let socket = s.sockets.get_mut::<dns::Socket>(i.dns_socket); | 257 | let socket = s.sockets.get_mut::<dns::Socket>(i.dns_socket); |
