diff options
| author | Aurélien Jacobs <[email protected]> | 2024-06-11 11:20:06 +0200 |
|---|---|---|
| committer | Aurélien Jacobs <[email protected]> | 2024-06-11 11:39:07 +0200 |
| commit | 7f3805437c412f7aa1b820b9cd48879428067e46 (patch) | |
| tree | ed768a13406558cce98f4f829fb63b1bd3904118 /embassy-net | |
| parent | ad7d739ddcc0e888574ba36a294b41d560927c5d (diff) | |
dns: properly handle AddrType::Either in get_host_by_name()
Diffstat (limited to 'embassy-net')
| -rw-r--r-- | embassy-net/src/dns.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/embassy-net/src/dns.rs b/embassy-net/src/dns.rs index a1151d5e4..8ccfa4e4f 100644 --- a/embassy-net/src/dns.rs +++ b/embassy-net/src/dns.rs | |||
| @@ -84,11 +84,26 @@ where | |||
| 84 | addr_type: embedded_nal_async::AddrType, | 84 | addr_type: embedded_nal_async::AddrType, |
| 85 | ) -> Result<embedded_nal_async::IpAddr, Self::Error> { | 85 | ) -> Result<embedded_nal_async::IpAddr, Self::Error> { |
| 86 | use embedded_nal_async::{AddrType, IpAddr}; | 86 | use embedded_nal_async::{AddrType, IpAddr}; |
| 87 | let qtype = match addr_type { | 87 | let (qtype, secondary_qtype) = match addr_type { |
| 88 | AddrType::IPv6 => DnsQueryType::Aaaa, | 88 | AddrType::IPv4 => (DnsQueryType::A, None), |
| 89 | _ => DnsQueryType::A, | 89 | AddrType::IPv6 => (DnsQueryType::Aaaa, None), |
| 90 | AddrType::Either => { | ||
| 91 | #[cfg(not(feature = "proto-ipv6"))] | ||
| 92 | let v6_first = false; | ||
| 93 | #[cfg(feature = "proto-ipv6")] | ||
| 94 | let v6_first = self.stack.config_v6().is_some(); | ||
| 95 | match v6_first { | ||
| 96 | true => (DnsQueryType::Aaaa, Some(DnsQueryType::A)), | ||
| 97 | false => (DnsQueryType::A, Some(DnsQueryType::Aaaa)), | ||
| 98 | } | ||
| 99 | } | ||
| 90 | }; | 100 | }; |
| 91 | let addrs = self.query(host, qtype).await?; | 101 | let mut addrs = self.query(host, qtype).await?; |
| 102 | if addrs.is_empty() { | ||
| 103 | if let Some(qtype) = secondary_qtype { | ||
| 104 | addrs = self.query(host, qtype).await? | ||
| 105 | } | ||
| 106 | } | ||
| 92 | if let Some(first) = addrs.get(0) { | 107 | if let Some(first) = addrs.get(0) { |
| 93 | Ok(match first { | 108 | Ok(match first { |
| 94 | #[cfg(feature = "proto-ipv4")] | 109 | #[cfg(feature = "proto-ipv4")] |
