]>
git.ipfire.org Git - people/ms/dnsmasq.git/blob - src/dns-protocol.h
1 /* dnsmasq is Copyright (c) 2000-2015 Simon Kelley
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #define NAMESERVER_PORT 53
23 #define PACKETSZ 512 /* maximum packet size */
24 #define MAXDNAME 1025 /* maximum presentation domain name */
25 #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
26 #define MAXLABEL 63 /* maximum length of domain label */
28 #define NOERROR 0 /* no error */
29 #define FORMERR 1 /* format error */
30 #define SERVFAIL 2 /* server failure */
31 #define NXDOMAIN 3 /* non existent domain */
32 #define NOTIMP 4 /* not implemented */
33 #define REFUSED 5 /* query refused */
35 #define QUERY 0 /* opcode */
37 #define C_IN 1 /* the arpa internet */
38 #define C_CHAOS 3 /* for chaos net (MIT) */
39 #define C_HESIOD 4 /* hesiod */
40 #define C_ANY 255 /* wildcard match */
78 #define EDNS0_OPTION_MAC 65001 /* dyndns.org temporary assignment */
79 #define EDNS0_OPTION_CLIENT_SUBNET 8 /* IANA */
84 u16 qdcount
,ancount
,nscount
,arcount
;
87 #define HB3_QR 0x80 /* Query */
88 #define HB3_OPCODE 0x78
89 #define HB3_AA 0x04 /* Authoritative Answer */
90 #define HB3_TC 0x02 /* TrunCated */
91 #define HB3_RD 0x01 /* Recursion Desired */
93 #define HB4_RA 0x80 /* Recursion Available */
94 #define HB4_AD 0x20 /* Authenticated Data */
95 #define HB4_CD 0x10 /* Checking Disabled */
96 #define HB4_RCODE 0x0f
98 #define OPCODE(x) (((x)->hb3 & HB3_OPCODE) >> 3)
99 #define SET_OPCODE(x, code) (x)->hb3 = ((x)->hb3 & ~HB3_OPCODE) | code
101 #define RCODE(x) ((x)->hb4 & HB4_RCODE)
102 #define SET_RCODE(x, code) (x)->hb4 = ((x)->hb4 & ~HB4_RCODE) | code
104 #define GETSHORT(s, cp) { \
105 unsigned char *t_cp = (unsigned char *)(cp); \
106 (s) = ((u16)t_cp[0] << 8) \
112 #define GETLONG(l, cp) { \
113 unsigned char *t_cp = (unsigned char *)(cp); \
114 (l) = ((u32)t_cp[0] << 24) \
115 | ((u32)t_cp[1] << 16) \
116 | ((u32)t_cp[2] << 8) \
122 #define PUTSHORT(s, cp) { \
123 u16 t_s = (u16)(s); \
124 unsigned char *t_cp = (unsigned char *)(cp); \
125 *t_cp++ = t_s >> 8; \
130 #define PUTLONG(l, cp) { \
131 u32 t_l = (u32)(l); \
132 unsigned char *t_cp = (unsigned char *)(cp); \
133 *t_cp++ = t_l >> 24; \
134 *t_cp++ = t_l >> 16; \
135 *t_cp++ = t_l >> 8; \
140 #define CHECK_LEN(header, pp, plen, len) \
141 ((size_t)((pp) - (unsigned char *)(header) + (len)) <= (plen))
143 #define ADD_RDLEN(header, pp, plen, len) \
144 (!CHECK_LEN(header, pp, plen, len) ? 0 : (((pp) += (len)), 1))
146 /* Escape character in our presentation format for names.
147 Cannot be '.' or /000 and must be !isprint().
148 Note that escaped chars are stored as
149 <NAME_ESCAPE> <orig-char+1>
150 to ensure that the escaped form of /000 doesn't include /000
152 #define NAME_ESCAPE 1