1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! DNS resolver configuration
use std::io;
use std::net::SocketAddr;
use std::time::Duration;
/// Configures the behavior of DNS requests
#[derive(Clone, Debug)]
pub struct DnsConfig {
/// List of name servers; must not be empty
pub name_servers: Vec<SocketAddr>,
/// List of search domains
pub search: Vec<String>,
/// Minimum number of dots in a name to trigger an initial absolute query
pub n_dots: u32,
/// Duration before retrying or failing an unanswered request
pub timeout: Duration,
/// Number of attempts made before returning an error
pub attempts: u32,
/// Whether to rotate through available nameservers
pub rotate: bool,
/// If `true`, perform `AAAA` queries first and return IPv4 addresses
/// as IPv4-mapped IPv6 addresses.
pub use_inet6: bool,
}
impl DnsConfig {
/// Returns the default system configuration for DNS requests.
pub fn load_default() -> io::Result<DnsConfig> {
default_config_impl()
}
/// Returns a `DnsConfig` using the given set of name servers,
/// setting all other fields to generally sensible default values.
pub fn with_name_servers(name_servers: Vec<SocketAddr>) -> DnsConfig {
DnsConfig{
name_servers: name_servers,
search: Vec::new(),
n_dots: 1,
timeout: Duration::from_secs(5),
attempts: 5,
rotate: false,
use_inet6: false,
}
}
}
#[cfg(unix)]
fn default_config_impl() -> io::Result<DnsConfig> {
use resolv_conf::load;
load()
}
#[cfg(windows)]
fn default_config_impl() -> io::Result<DnsConfig> {
// TODO: Get a list of nameservers from Windows API.
// For now, return an IO error.
Err(io::Error::new(io::ErrorKind::Other, "Nameserver list not available on Windows"))
}