dns_parser_revived/
structs.rs

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