1#[cfg(not(feature = "dns-async"))]
2mod dns_blocking;
3
4#[cfg(not(feature = "dns-async"))]
5pub use dns_blocking::{
6 get_host_by_name, get_host_by_name_with_cancellation, resolve_dns,
7 resolve_dns_with_cancellation,
8};
9
10#[cfg(feature = "dns-async")]
11mod dns_async;
12
13#[cfg(feature = "dns-async")]
14mod dns_cache;
15
16#[cfg(feature = "dns-async")]
17pub use dns_async::{
18 get_host_by_name, get_host_by_name_with_cancellation, resolve_dns,
19 resolve_dns_with_cancellation,
20};
21
22#[derive(Copy, Clone, Debug)]
26pub struct DnsQuery<'a> {
27 hostname: &'a str,
29
30 addr_type: AddrType,
32}
33
34impl<'a> DnsQuery<'a> {
35 pub fn new(hostname: &'a str) -> Self {
39 Self {
40 hostname,
41 addr_type: AddrType::Any,
42 }
43 }
44
45 #[must_use = "this function returns a new query, it does not modify the existing one"]
49 pub fn with_address_type(self, addr_type: AddrType) -> Self {
50 let mut out = self;
51 out.addr_type = addr_type;
52 out
53 }
54
55 pub fn hostname(&self) -> &'a str {
57 self.hostname
58 }
59
60 pub fn addr_type(&self) -> AddrType {
62 self.addr_type
63 }
64}
65
66#[derive(Copy, Clone, Debug)]
68pub enum AddrType {
69 Any,
71
72 V4,
74
75 V6,
77}
78
79impl AddrType {
80 fn addr_matches(&self, addr: core::net::IpAddr) -> bool {
82 match self {
83 Self::Any => true,
84 Self::V4 => matches!(addr, core::net::IpAddr::V4(_)),
85 Self::V6 => matches!(addr, core::net::IpAddr::V6(_)),
86 }
87 }
88}