mio_httpc/dns_parser/
structs.rs

1use super::{Class, Header, Name, QueryClass, QueryType, RRData};
2
3/// Parsed DNS packet
4#[derive(Debug)]
5pub struct Packet<'a> {
6    pub header: Header,
7    pub questions: Vec<Question<'a>>,
8    pub answers: Vec<ResourceRecord<'a>>,
9    pub nameservers: Vec<ResourceRecord<'a>>,
10    pub additional: Vec<ResourceRecord<'a>>,
11    /// Optional Pseudo-RR
12    /// When present it is sent as an RR in the additional section. In this RR
13    /// the `class` and `ttl` fields store max udp packet size and flags
14    /// respectively. To keep `ResourceRecord` clean we store the OPT record
15    /// here.
16    pub opt: Option<OptRecord<'a>>,
17}
18
19/// A parsed chunk of data in the Query section of the packet
20#[derive(Debug)]
21pub struct Question<'a> {
22    pub qname: Name<'a>,
23    /// Whether or not we prefer unicast responses.
24    /// This is used in multicast DNS.
25    pub prefer_unicast: bool,
26    pub qtype: QueryType,
27    pub qclass: QueryClass,
28}
29
30/// A single DNS record
31///
32/// We aim to provide whole range of DNS records available. But as time is
33/// limited we have some types of packets which are parsed and other provided
34/// as unparsed slice of bytes.
35#[derive(Debug)]
36pub struct ResourceRecord<'a> {
37    pub name: Name<'a>,
38    /// Whether or not the set of resource records is fully contained in the
39    /// packet, or whether there will be more resource records in future
40    /// packets. Only used for multicast DNS.
41    pub multicast_unique: bool,
42    pub cls: Class,
43    pub ttl: u32,
44    pub data: RRData<'a>,
45}
46
47/// RFC 6891 OPT RR
48#[derive(Debug)]
49pub struct OptRecord<'a> {
50    pub udp: u16,
51    pub extrcode: u8,
52    pub version: u8,
53    pub flags: u16,
54    pub data: RRData<'a>,
55}
56
57#[derive(Debug)]
58pub struct SoaRecord<'a> {
59    pub primary_ns: Name<'a>,
60    pub mailbox: Name<'a>,
61    pub serial: u32,
62    pub refresh: u32,
63    pub retry: u32,
64    pub expire: u32,
65    pub minimum_ttl: u32,
66}