]> The Tcpdump Group git mirrors - tcpdump/blob - nameser.h
Bitfield layout in memory is not specified by the ANSI C spec; don't use
[tcpdump] / nameser.h
1 /*
2 * Copyright (c) 1983, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)nameser.h 8.2 (Berkeley) 2/16/94
34 * -
35 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
36 *
37 * Permission to use, copy, modify, and distribute this software for any
38 * purpose with or without fee is hereby granted, provided that the above
39 * copyright notice and this permission notice appear in all copies, and that
40 * the name of Digital Equipment Corporation not be used in advertising or
41 * publicity pertaining to distribution of the document or software without
42 * specific, written prior permission.
43 *
44 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
45 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
47 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
48 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
49 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
50 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
51 * SOFTWARE.
52 * -
53 * --Copyright--
54 */
55
56 #ifndef _NAMESER_H_
57 #define _NAMESER_H_
58
59 #include <sys/types.h>
60
61 /*
62 * Define constants based on rfc883
63 */
64 #define PACKETSZ 512 /* maximum packet size */
65 #define MAXDNAME 256 /* maximum domain name */
66 #define MAXCDNAME 255 /* maximum compressed domain name */
67 #define MAXLABEL 63 /* maximum length of domain label */
68 /* Number of bytes of fixed size data in query structure */
69 #define QFIXEDSZ 4
70 /* number of bytes of fixed size data in resource record */
71 #define RRFIXEDSZ 10
72
73 /*
74 * Internet nameserver port number
75 */
76 #define NAMESERVER_PORT 53
77
78 /*
79 * Currently defined opcodes
80 */
81 #define QUERY 0x0 /* standard query */
82 #define IQUERY 0x1 /* inverse query */
83 #define STATUS 0x2 /* nameserver status query */
84 /*#define xxx 0x3 /* 0x3 reserved */
85 /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
86 #define UPDATEA 0x9 /* add resource record */
87 #define UPDATED 0xa /* delete a specific resource record */
88 #define UPDATEDA 0xb /* delete all named resource record */
89 #define UPDATEM 0xc /* modify a specific resource record */
90 #define UPDATEMA 0xd /* modify all named resource record */
91
92 #define ZONEINIT 0xe /* initial zone transfer */
93 #define ZONEREF 0xf /* incremental zone referesh */
94
95 /*
96 * Currently defined response codes
97 */
98 #define NOERROR 0 /* no error */
99 #define FORMERR 1 /* format error */
100 #define SERVFAIL 2 /* server failure */
101 #define NXDOMAIN 3 /* non existent domain */
102 #define NOTIMP 4 /* not implemented */
103 #define REFUSED 5 /* query refused */
104 /* non standard */
105 #define NOCHANGE 0xf /* update failed to change db */
106
107 /*
108 * Type values for resources and queries
109 */
110 #define T_A 1 /* host address */
111 #define T_NS 2 /* authoritative server */
112 #define T_MD 3 /* mail destination */
113 #define T_MF 4 /* mail forwarder */
114 #define T_CNAME 5 /* connonical name */
115 #define T_SOA 6 /* start of authority zone */
116 #define T_MB 7 /* mailbox domain name */
117 #define T_MG 8 /* mail group member */
118 #define T_MR 9 /* mail rename name */
119 #define T_NULL 10 /* null resource record */
120 #define T_WKS 11 /* well known service */
121 #define T_PTR 12 /* domain name pointer */
122 #define T_HINFO 13 /* host information */
123 #define T_MINFO 14 /* mailbox information */
124 #define T_MX 15 /* mail routing information */
125 #define T_TXT 16 /* text strings */
126 #define T_RP 17 /* responsible person */
127 #define T_AFSDB 18 /* AFS cell database */
128 #define T_NSAP 22 /* NSAP address */
129 #define T_NSAP_PTR 23 /* reverse lookup for NSAP */
130 /* non standard */
131 #define T_UINFO 100 /* user (finger) information */
132 #define T_UID 101 /* user ID */
133 #define T_GID 102 /* group ID */
134 #define T_UNSPEC 103 /* Unspecified format (binary data) */
135 /* Query type values which do not appear in resource records */
136 #define T_AXFR 252 /* transfer zone of authority */
137 #define T_MAILB 253 /* transfer mailbox records */
138 #define T_MAILA 254 /* transfer mail agent records */
139 #define T_ANY 255 /* wildcard match */
140
141 /*
142 * Values for class field
143 */
144
145 #define C_IN 1 /* the arpa internet */
146 #define C_CHAOS 3 /* for chaos net (MIT) */
147 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
148 /* Query class values which do not appear in resource records */
149 #define C_ANY 255 /* wildcard match */
150
151 /*
152 * Status return codes for T_UNSPEC conversion routines
153 */
154 #define CONV_SUCCESS 0
155 #define CONV_OVERFLOW -1
156 #define CONV_BADFMT -2
157 #define CONV_BADCKSUM -3
158 #define CONV_BADBUFLEN -4
159
160 /*
161 * Structure for query header.
162 */
163 typedef struct {
164 u_int16_t id; /* query identification number */
165 u_int8_t flags1; /* first byte of flags */
166 u_int8_t flags2; /* second byte of flags */
167 u_int16_t qdcount; /* number of question entries */
168 u_int16_t ancount; /* number of answer entries */
169 u_int16_t nscount; /* number of authority entries */
170 u_int16_t arcount; /* number of resource entries */
171 } HEADER;
172
173 /*
174 * Macros for subfields of flag fields.
175 */
176 #define DNS_QR(np) ((np)->flags1 & 0x80) /* response flag */
177 #define DNS_OPCODE(np) ((((np)->flags1) >> 3) & 0xF) /* purpose of message */
178 #define DNS_AA(np) ((np)->flags1 & 0x04) /* authoritative answer */
179 #define DNS_TC(np) ((np)->flags1 & 0x02) /* truncated message */
180 #define DNS_RD(np) ((np)->flags1 & 0x01) /* recursion desired */
181
182 #define DNS_RA(np) ((np)->flags2 & 0x80) /* recursion available */
183 #define DNS_AD(np) ((np)->flags2 & 0x20) /* authentic data from named */
184 #define DNS_CD(np) ((np)->flags2 & 0x10) /* checking disabled by resolver */
185 #define DNS_RCODE(np) ((np)->flags2 & 0xF) /* response code */
186
187 /*
188 * Defines for handling compressed domain names
189 */
190 #define INDIR_MASK 0xc0
191
192 /*
193 * Structure for passing resource records around.
194 */
195 struct rrec {
196 int16_t r_zone; /* zone number */
197 int16_t r_class; /* class number */
198 int16_t r_type; /* type number */
199 u_int32_t r_ttl; /* time to live */
200 int r_size; /* size of data area */
201 char *r_data; /* pointer to data */
202 };
203
204 extern u_int16_t _getshort();
205 extern u_int32_t _getlong();
206
207 /*
208 * Inline versions of get/put short/long. Pointer is advanced.
209 * We also assume that a "u_int16_t" holds 2 "chars"
210 * and that a "u_int32_t" holds 4 "chars".
211 *
212 * These macros demonstrate the property of C whereby it can be
213 * portable or it can be elegant but never both.
214 */
215 #define GETSHORT(s, cp) { \
216 register u_char *t_cp = (u_char *)(cp); \
217 (s) = ((u_int16_t)t_cp[0] << 8) | (u_int16_t)t_cp[1]; \
218 (cp) += 2; \
219 }
220
221 #define GETLONG(l, cp) { \
222 register u_char *t_cp = (u_char *)(cp); \
223 (l) = (((u_int32_t)t_cp[0]) << 24) \
224 | (((u_int32_t)t_cp[1]) << 16) \
225 | (((u_int32_t)t_cp[2]) << 8) \
226 | (((u_int32_t)t_cp[3])); \
227 (cp) += 4; \
228 }
229
230 #define PUTSHORT(s, cp) { \
231 register u_int16_t t_s = (u_int16_t)(s); \
232 register u_char *t_cp = (u_char *)(cp); \
233 *t_cp++ = t_s >> 8; \
234 *t_cp = t_s; \
235 (cp) += 2; \
236 }
237
238 /*
239 * Warning: PUTLONG --no-longer-- destroys its first argument. if you
240 * were depending on this "feature", you will lose.
241 */
242 #define PUTLONG(l, cp) { \
243 register u_int32_t t_l = (u_int32_t)(l); \
244 register u_char *t_cp = (u_char *)(cp); \
245 *t_cp++ = t_l >> 24; \
246 *t_cp++ = t_l >> 16; \
247 *t_cp++ = t_l >> 8; \
248 *t_cp = t_l; \
249 (cp) += 4; \
250 }
251
252 #endif /* !_NAMESER_H_ */