mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-26 00:32:33 +00:00
dns: properly handle AddrType::Either in get_host_by_name()
This commit is contained in:
parent
ad7d739ddc
commit
7f3805437c
@ -84,11 +84,26 @@ where
|
|||||||
addr_type: embedded_nal_async::AddrType,
|
addr_type: embedded_nal_async::AddrType,
|
||||||
) -> Result<embedded_nal_async::IpAddr, Self::Error> {
|
) -> Result<embedded_nal_async::IpAddr, Self::Error> {
|
||||||
use embedded_nal_async::{AddrType, IpAddr};
|
use embedded_nal_async::{AddrType, IpAddr};
|
||||||
let qtype = match addr_type {
|
let (qtype, secondary_qtype) = match addr_type {
|
||||||
AddrType::IPv6 => DnsQueryType::Aaaa,
|
AddrType::IPv4 => (DnsQueryType::A, None),
|
||||||
_ => DnsQueryType::A,
|
AddrType::IPv6 => (DnsQueryType::Aaaa, None),
|
||||||
|
AddrType::Either => {
|
||||||
|
#[cfg(not(feature = "proto-ipv6"))]
|
||||||
|
let v6_first = false;
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
let v6_first = self.stack.config_v6().is_some();
|
||||||
|
match v6_first {
|
||||||
|
true => (DnsQueryType::Aaaa, Some(DnsQueryType::A)),
|
||||||
|
false => (DnsQueryType::A, Some(DnsQueryType::Aaaa)),
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let addrs = self.query(host, qtype).await?;
|
let mut addrs = self.query(host, qtype).await?;
|
||||||
|
if addrs.is_empty() {
|
||||||
|
if let Some(qtype) = secondary_qtype {
|
||||||
|
addrs = self.query(host, qtype).await?
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(first) = addrs.get(0) {
|
if let Some(first) = addrs.get(0) {
|
||||||
Ok(match first {
|
Ok(match first {
|
||||||
#[cfg(feature = "proto-ipv4")]
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
Loading…
Reference in New Issue
Block a user