veilid_tools/resolver/native/
mod.rs1use super::*;
2
3#[cfg_attr(
5 any(target_os = "macos", target_os = "ios", target_os = "windows"),
6 allow(
7 dead_code,
8 reason = "decoder is used by the Android and libresolv backends"
9 )
10)]
11pub(crate) mod dns;
12
13cfg_if! {
14 if #[cfg(target_os = "android")] {
15 pub(crate) mod android;
16 mod fd_ready;
17 mod ptr_unix;
18 use android as txt;
19 use ptr_unix as ptr;
20 } else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
21 pub(crate) mod apple;
22 mod fd_ready;
23 mod ptr_unix;
24 use apple as txt;
25 use ptr_unix as ptr;
26 } else if #[cfg(target_os = "windows")] {
27 pub(crate) mod windows;
28 use windows as txt;
29 use windows as ptr;
30 } else {
31 pub(crate) mod resolv;
32 mod ptr_unix;
33 use resolv as txt;
34 use ptr_unix as ptr;
35 }
36}
37
38impl From<dns::DnsError> for ResolverError {
39 fn from(e: dns::DnsError) -> Self {
40 match e {
41 dns::DnsError::Unsupported => ResolverError::Unsupported,
42 e => ResolverError::Generic(e.to_string()),
43 }
44 }
45}
46
47pub struct Resolver {}
49
50impl Resolver {
51 #[must_use]
53 pub fn supports_txt() -> bool {
54 cfg_if! {
55 if #[cfg(target_os = "android")] {
56 android::available()
57 } else {
58 true
59 }
60 }
61 }
62
63 pub async fn txt_lookup<S: AsRef<str>>(host: S) -> Result<Vec<String>, ResolverError> {
68 Ok(txt::txt_lookup(host.as_ref()).await?)
69 }
70
71 pub async fn ptr_lookup(ip_addr: IpAddr) -> Result<String, ResolverError> {
75 Ok(ptr::ptr_lookup(ip_addr).await?)
76 }
77}