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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#[macro_use] extern crate nom;
mod grammar;
use std::io;
use std::net::{Ipv4Addr, Ipv6Addr};
#[derive(Clone, Debug)]
pub enum IpAddr {
V4(Ipv4Addr),
V6(Ipv6Addr),
}
#[derive(Clone, Debug)]
pub enum Network {
V4(Ipv4Addr, Ipv4Addr),
V6(Ipv6Addr, Ipv6Addr),
}
#[derive(Clone, Debug)]
pub struct Config {
pub nameservers: Vec<IpAddr>,
pub search: Vec<String>,
pub sortlist: Vec<Network>,
pub ndots: u32,
pub timeout: u32,
pub rotate: bool,
pub no_check_names: bool,
pub inet6: bool,
pub ip6_bytestring: bool,
pub ip6_dotint: bool,
pub edns0: bool,
pub single_request: bool,
pub single_request_reopen: bool,
}
impl Config {
pub fn new() -> Config {
Config {
nameservers: Vec::new(),
search: Vec::new(),
sortlist: Vec::new(),
ndots: 1,
timeout: 5,
rotate: false,
no_check_names: false,
inet6: false,
ip6_bytestring: false,
ip6_dotint: false,
edns0: false,
single_request: false,
single_request_reopen: false,
}
}
pub fn parse(buf: &[u8]) -> Result<Config, grammar::ParseError> {
grammar::parse(buf)
}
}