forked from stealth/qdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net-headers.h
152 lines (128 loc) · 3.89 KB
/
net-headers.h
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* This file is part of quantum-dns.
*
* (C) 2014-2018 by Sebastian Krahmer, sebastian [dot] krahmer [at] gmail [dot] com
*
* quantum-dns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* quantum-dns is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with quantum-dns. If not, see <http://www.gnu.org/licenses/>.
*/
/* some of the header definitions have been taken from various other
* open-sourced include files
*/
#ifndef qdns_net_headers_h
#define qdns_net_headers_h
#include <sys/types.h>
#ifdef __linux__
#include <bits/endian.h>
#endif
#include <stdint.h>
#ifndef __BYTE_ORDER
#define __BYTE_ORDER BYTE_ORDER
#endif
#ifndef __BIG_ENDIAN
#define __BING_ENDIAN BIG_ENDIAN
#endif
#ifndef __LITTLE_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#endif
namespace net_headers {
class dnshdr {
public:
uint16_t id;
#if __BYTE_ORDER == __BIG_ENDIAN
/* fields in third byte */
uint16_t qr: 1; /* response flag */
uint16_t opcode: 4; /* purpose of message */
uint16_t aa: 1; /* authoritive answer */
uint16_t tc: 1; /* truncated message */
uint16_t rd: 1; /* recursion desired */
/* fields in fourth byte */
uint16_t ra: 1; /* recursion available */
uint16_t unused :1; /* unused bits (MBZ as of 4.9.3a3) */
uint16_t ad: 1; /* authentic data from named */
uint16_t cd: 1; /* checking disabled by resolver */
uint16_t rcode :4; /* response code */
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __PDP_ENDIAN
/* fields in third byte */
uint16_t rd :1; /* recursion desired */
uint16_t tc :1; /* truncated message */
uint16_t aa :1; /* authoritive answer */
uint16_t opcode :4; /* purpose of message */
uint16_t qr :1; /* response flag */
/* fields in fourth byte */
uint16_t rcode :4; /* response code */
uint16_t cd: 1; /* checking disabled by resolver */
uint16_t ad: 1; /* authentic data from named */
uint16_t unused :1; /* unused bits (MBZ as of 4.9.3a3) */
uint16_t ra :1; /* recursion available */
#endif
/*
union {
u_int16_t flags;
u_int16_t QR:1;
u_int16_t opcode:4;
u_int16_t AA:1;
u_int16_t TC:1;
u_int16_t RD:1;
u_int16_t RA:1;
u_int16_t zero:3;
u_int16_t rcode:4;
} u;
*/
uint16_t q_count;
uint16_t a_count;
uint16_t rra_count;
uint16_t ad_count;
dnshdr() : id (0),
q_count(0), a_count(0), rra_count(0), ad_count(0)
{
qr = 0; opcode = 0; aa = 0; tc = 0; rd = 0; ra = 0; ad = 0; cd = 0;
rcode = 0; unused = 0;
}
private: dnshdr(const dnshdr &) {};
};
enum dns_type : uint16_t {
A = 1,
NS = 2,
CNAME = 5,
SOA = 6,
PTR = 12,
HINFO = 13,
MX = 15,
TXT = 16,
AAAA = 28,
SRV = 33,
DNAME = 39,
OPT = 41,
DNSKEY = 48,
EUI64 = 109,
};
// an IPv4 RR
struct dns_rr {
// name here
uint16_t type, _class;
uint32_t ttl;
uint16_t len;
// rdata
} __attribute__((packed));
struct dns_srv_rr {
// name here
uint16_t type, _class;
uint32_t ttl;
uint16_t len;
uint16_t prio, weight, port;
// octet target here
} __attribute__((packed));
} // namespace
#endif