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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use std::ffi::CStr;
use ::error::Error;
use ::libresolv_sys::__ns_rr as Rr;
use ::libresolv_sys::__ns_msg as Message;
mod class;
pub use self::class::Class;
pub trait RecordData: Sized {
fn get_record_type() -> RecordType;
fn extract(msg: &mut Message, rr: &Rr) -> Result<Self, Error>;
}
#[derive(Debug, Clone)]
pub struct Record<T: RecordData> {
pub name: String,
pub class: Class,
pub ttl: u32,
pub data: T
}
impl<T: RecordData> Record<T> {
pub fn extract(msg: &mut Message, rr: &Rr) -> Result<Record<T>, Error> {
Ok(Record {
name: unsafe { CStr::from_ptr(rr.name.as_ptr()).to_string_lossy().into_owned() },
class: try!(Class::from_rr_class(rr.rr_class)),
ttl: rr.ttl,
data: try!(<T as RecordData>::extract(msg, rr)),
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[allow(non_camel_case_types)]
#[repr(u16)]
pub enum RecordType {
A = 1,
NS = 2,
MD = 3,
MF = 4,
CNAME = 5,
SOA = 6,
MB = 7,
MG = 8,
MR = 9,
NULL = 10,
WKS = 11,
PTR = 12,
HINFO = 13,
MINFO = 14,
MX = 15,
TXT = 16,
RP = 17,
AFSDB = 18,
X25 = 19,
ISDN = 20,
RT = 21,
NSAP = 22,
NSAP_PTR = 23,
SIG = 24,
KEY = 25,
PX = 26,
GPOS = 27,
AAAA = 28,
LOC = 29,
NXT = 30,
EID = 31,
NIMLOC = 32,
SRV = 33,
ATMA = 34,
NAPTR = 35,
KX = 36,
CERT = 37,
A6 = 38,
DNAME = 39,
SINK = 40,
OPT = 41,
APL = 42,
TKEY = 249,
TSIG = 250,
IXFR = 251,
AXFR = 252,
MAILB = 253,
MAILA = 254,
ANY = 255,
ZXFR = 256,
}
pub use self::a::A;
pub use self::ns::NS;
pub use self::cname::CNAME;
pub use self::soa::SOA;
pub use self::ptr::PTR;
pub use self::mx::MX;
pub use self::txt::TXT;
pub use self::aaaa::AAAA;
mod a;
mod ns;
mod cname;
mod soa;
mod ptr;
mod mx;
mod txt;
mod aaaa;