#[cfg(not(feature = "dns-async"))]
mod dns_blocking;
#[cfg(not(feature = "dns-async"))]
pub use dns_blocking::{
get_host_by_name, get_host_by_name_with_cancellation, resolve_dns,
resolve_dns_with_cancellation,
};
#[cfg(feature = "dns-async")]
mod dns_async;
#[cfg(feature = "dns-async")]
mod dns_cache;
#[cfg(feature = "dns-async")]
pub use dns_async::{
get_host_by_name, get_host_by_name_with_cancellation, resolve_dns,
resolve_dns_with_cancellation,
};
#[derive(Copy, Clone, Debug)]
pub struct DnsQuery<'a> {
hostname: &'a str,
addr_type: AddrType,
}
impl<'a> DnsQuery<'a> {
pub fn new(hostname: &'a str) -> Self {
Self {
hostname,
addr_type: AddrType::Any,
}
}
#[must_use = "this function returns a new query, it does not modify the existing one"]
pub fn with_address_type(self, addr_type: AddrType) -> Self {
let mut out = self;
out.addr_type = addr_type;
out
}
pub fn hostname(&self) -> &'a str {
self.hostname
}
pub fn addr_type(&self) -> AddrType {
self.addr_type
}
}
#[derive(Copy, Clone, Debug)]
pub enum AddrType {
Any,
V4,
V6,
}
impl AddrType {
fn addr_matches(&self, addr: core::net::IpAddr) -> bool {
match self {
Self::Any => true,
Self::V4 => matches!(addr, core::net::IpAddr::V4(_)),
Self::V6 => matches!(addr, core::net::IpAddr::V6(_)),
}
}
}