|
1 | 1 | use hickory_resolver::{ |
2 | | - TokioResolver, name_server::TokioConnectionProvider, system_conf::read_system_conf, |
| 2 | + TokioResolver, net::runtime::TokioRuntimeProvider, proto::rr::RData, |
| 3 | + system_conf::read_system_conf, |
3 | 4 | }; |
4 | 5 | use local_ip_address::list_afinet_netifas; |
5 | 6 | use serde::Serialize; |
@@ -31,11 +32,19 @@ static GLOBAL_DNS_RESOLVER: LazyLock<Option<TokioResolver>> = LazyLock::new(|| { |
31 | 32 | }; |
32 | 33 | resolver_opts.timeout = Duration::from_secs(5); |
33 | 34 |
|
34 | | - Some( |
35 | | - TokioResolver::builder_with_config(resolver_config, TokioConnectionProvider::default()) |
36 | | - .with_options(resolver_opts) |
37 | | - .build(), |
38 | | - ) |
| 35 | + match TokioResolver::builder_with_config(resolver_config, TokioRuntimeProvider::default()) |
| 36 | + .with_options(resolver_opts) |
| 37 | + .build() |
| 38 | + { |
| 39 | + Ok(resolver) => Some(resolver), |
| 40 | + Err(err) => { |
| 41 | + tracing::error!( |
| 42 | + error = &err as &dyn std::error::Error, |
| 43 | + "failed to build DNS resolver, DNS lookups will be skipped" |
| 44 | + ); |
| 45 | + None |
| 46 | + } |
| 47 | + } |
39 | 48 | }); |
40 | 49 |
|
41 | 50 | /// Captures all system network information, including network interfaces, |
@@ -89,8 +98,12 @@ impl SystemNetworkInfo { |
89 | 98 | .filter_map(|(ip, reverse_lookup)| match reverse_lookup { |
90 | 99 | Ok(result) => { |
91 | 100 | let hostnames = result |
92 | | - .into_iter() |
93 | | - .map(|ptr_record| ptr_record.to_utf8()) |
| 101 | + .answers() |
| 102 | + .iter() |
| 103 | + .filter_map(|record| match &record.data { |
| 104 | + RData::PTR(ptr) => Some(ptr.0.to_utf8()), |
| 105 | + _ => None, |
| 106 | + }) |
94 | 107 | .collect(); |
95 | 108 | tracing::info!(%ip, ?hostnames, "performed reverse DNS lookup for IP"); |
96 | 109 | Some((ip, hostnames)) |
|
0 commit comments