1 /*!\file arpa/nameser.h
6 * Copyright (c) 1983, 1989, 1993
7 * The Regents of the University of California. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
40 * Permission to use, copy, modify, and distribute this software for any
41 * purpose with or without fee is hereby granted, provided that the above
42 * copyright notice and this permission notice appear in all copies, and that
43 * the name of Digital Equipment Corporation not be used in advertising or
44 * publicity pertaining to distribution of the document or software without
45 * specific, written prior permission.
47 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
48 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
50 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
51 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
52 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
53 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
58 * @(#)nameser.h 8.2 (Berkeley) 2/16/94
59 * From Id: nameser.h,v 4.9.1.15 1994/07/19 22:51:24 vixie Exp
60 * $Id: nameser.h,v 1.8 1996/08/29 20:01:00 peter Exp $
63 #ifndef __ARPA_NAMESER_H
64 #define __ARPA_NAMESER_H
66 #ifndef __SYS_W32API_H
67 #include <sys/w32api.h>
71 #include <sys/param.h>
74 #ifndef __SYS_WTYPES_H
75 #include <sys/wtypes.h>
79 #include <sys/cdefs.h>
83 * revision information. this is the release date in YYYYMMDD format.
84 * it can change every day so the right thing to do with it is use it
85 * in preprocessor commands such as "#if (__BIND > 19931104)". do not
86 * compare for equality; rather, use it to determine whether your resolver
87 * is new enough to contain a certain feature.
90 #define __BIND 19960801 /* interface version stamp */
93 * Define constants based on rfc883
95 #define PACKETSZ 512 /* maximum packet size */
96 #define MAXDNAME 1025 /* maximum domain name */
97 #define MAXCDNAME 255 /* maximum compressed domain name */
98 #define MAXLABEL 63 /* maximum length of domain label */
99 #define HFIXEDSZ 12 /* #/bytes of fixed data in header */
100 #define QFIXEDSZ 4 /* #/bytes of fixed data in query */
101 #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
102 #define INT32SZ 4 /* for systems without 32-bit ints */
103 #define INT16SZ 2 /* for systems without 16-bit ints */
104 #define INADDRSZ 4 /* IPv4 T_A */
105 #define IN6ADDRSZ 16 /* IPv6 T_AAAA */
109 * Internet nameserver port number
111 #define NAMESERVER_PORT 53
114 * Currently defined opcodes
116 #define QUERY 0x0 /* standard query */
117 #define IQUERY 0x1 /* inverse query */
118 #define STATUS 0x2 /* nameserver status query */
119 #define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
122 /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
123 # define UPDATEA 0x9 /* add resource record */
124 # define UPDATED 0xa /* delete a specific resource record */
125 # define UPDATEDA 0xb /* delete all named resource record */
126 # define UPDATEM 0xc /* modify a specific resource record */
127 # define UPDATEMA 0xd /* modify all named resource record */
128 # define ZONEINIT 0xe /* initial zone transfer */
129 # define ZONEREF 0xf /* incremental zone referesh */
133 * Currently defined response codes
135 #if !defined(WIN32) && !defined(_WIN32) /* <winerror.h> value is okay */
136 #define NOERROR 0 /* no error */
138 #define FORMERR 1 /* format error */
139 #define SERVFAIL 2 /* server failure */
140 #define NXDOMAIN 3 /* non existent domain */
141 #define NOTIMP 4 /* not implemented */
142 #define REFUSED 5 /* query refused */
146 # define NOCHANGE 0xf /* update failed to change db */
150 * Type values for resources and queries
152 #define T_A 1 /* host address */
153 #define T_NS 2 /* authoritative server */
154 #define T_MD 3 /* mail destination */
155 #define T_MF 4 /* mail forwarder */
156 #define T_CNAME 5 /* canonical name */
157 #define T_SOA 6 /* start of authority zone */
158 #define T_MB 7 /* mailbox domain name */
159 #define T_MG 8 /* mail group member */
160 #define T_MR 9 /* mail rename name */
161 #define T_NULL 10 /* null resource record */
162 #define T_WKS 11 /* well known service */
163 #define T_PTR 12 /* domain name pointer */
164 #define T_HINFO 13 /* host information */
165 #define T_MINFO 14 /* mailbox information */
166 #define T_MX 15 /* mail routing information */
167 #define T_TXT 16 /* text strings */
168 #define T_RP 17 /* responsible person */
169 #define T_AFSDB 18 /* AFS cell database */
170 #define T_X25 19 /* X_25 calling address */
171 #define T_ISDN 20 /* ISDN calling address */
172 #define T_RT 21 /* router */
173 #define T_NSAP 22 /* NSAP address */
174 #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
175 #define T_SIG 24 /* security signature */
176 #define T_KEY 25 /* security key */
177 #define T_PX 26 /* X.400 mail mapping */
178 #define T_GPOS 27 /* geographical position (withdrawn) */
179 #define T_AAAA 28 /* IP6 Address */
180 #define T_LOC 29 /* Location Information */
181 #define T_NXT 30 /* Next Valid Name in Zone */
182 #define T_EID 31 /* Endpoint identifier */
183 #define T_NIMLOC 32 /* Nimrod locator */
184 #define T_SRV 33 /* Server selection */
185 #define T_ATMA 34 /* ATM Address */
186 #define T_NAPTR 35 /* Naming Authority PoinTeR */
188 #define T_UINFO 100 /* user (finger) information */
189 #define T_UID 101 /* user ID */
190 #define T_GID 102 /* group ID */
191 #define T_UNSPEC 103 /* Unspecified format (binary data) */
192 /* Query type values which do not appear in resource records */
193 #define T_IXFR 251 /* incremental zone transfer */
194 #define T_AXFR 252 /* transfer zone of authority */
195 #define T_MAILB 253 /* transfer mailbox records */
196 #define T_MAILA 254 /* transfer mail agent records */
197 #define T_ANY 255 /* wildcard match */
199 #define T_WINS 0xFF01 /* WINS name lookup */
200 #define T_WINSR 0xFF02 /* WINS reverse lookup */
203 * Values for class field
206 #define C_IN 1 /* the arpa internet */
207 #define C_CHAOS 3 /* for chaos net (MIT) */
208 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
209 /* Query class values which do not appear in resource records */
210 #define C_ANY 255 /* wildcard match */
213 * Status return codes for T_UNSPEC conversion routines
215 #define CONV_SUCCESS 0
216 #define CONV_OVERFLOW (-1)
217 #define CONV_BADFMT (-2)
218 #define CONV_BADCKSUM (-3)
219 #define CONV_BADBUFLEN (-4)
221 #include <sys/packon.h>
224 * Structure for query header. The order of the fields is machine- and
225 * compiler-dependent, depending on the byte/bit order and the layout
226 * of bit fields. We use bit fields only in int variables, as this
227 * is all ANSI requires. This requires a somewhat confusing rearrangement.
231 unsigned id :16; /* query identification number */
233 /* fields in third byte */
234 unsigned rd :1; /* recursion desired */
235 unsigned tc :1; /* truncated message */
236 unsigned aa :1; /* authoritative answer */
237 unsigned opcode :4; /* purpose of message */
238 unsigned qr :1; /* response flag */
240 /* fields in fourth byte */
241 unsigned rcode :4; /* response code */
242 unsigned cd: 1; /* checking disabled by resolver */
243 unsigned ad: 1; /* authentic data from named */
244 unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
245 unsigned ra :1; /* recursion available */
247 /* remaining bytes */
248 unsigned qdcount :16; /* number of question entries */
249 unsigned ancount :16; /* number of answer entries */
250 unsigned nscount :16; /* number of authority entries */
251 unsigned arcount :16; /* number of resource entries */
256 * Defines for handling compressed domain names
258 #define INDIR_MASK 0xc0
261 * Structure for passing resource records around.
264 u_short r_zone; /* zone number */
265 u_short r_class; /* class number */
266 u_short r_type; /* type number */
267 u_long r_ttl; /* time to live */
268 int r_size; /* size of data area */
269 char *r_data; /* pointer to data */
272 #include <sys/packoff.h>
277 W32_FUNC u_short _getshort (const u_char *);
278 W32_FUNC u_long _getlong (const u_char *);
283 * Inline versions of get/put short/long. Pointer is advanced.
285 * These macros demonstrate the property of C whereby it can be
286 * portable or it can be elegant but rarely both.
288 #define GETSHORT(s, cp) do { \
289 register u_char *t_cp = (u_char *)(cp); \
290 (s) = ((u_short)t_cp[0] << 8) \
291 | ((u_short)t_cp[1]); \
295 #define GETLONG(l, cp) do { \
296 register u_char *t_cp = (u_char *)(cp); \
297 (l) = ((u_long)t_cp[0] << 24) \
298 | ((u_long)t_cp[1] << 16) \
299 | ((u_long)t_cp[2] << 8) \
300 | ((u_long)t_cp[3]); \
304 #define PUTSHORT(s, cp) do { \
305 register u_short t_s = (u_short)(s); \
306 register u_char *t_cp = (u_char *)(cp); \
307 *t_cp++ = (u_char) (t_s >> 8); \
308 *t_cp = (u_char) t_s; \
312 #define PUTLONG(l, cp) do { \
313 register u_long t_l = (u_long)(l); \
314 register u_char *t_cp = (u_char *)(cp); \
315 *t_cp++ = (u_char) (t_l >> 24); \
316 *t_cp++ = (u_char) (t_l >> 16); \
317 *t_cp++ = (u_char) (t_l >> 8); \
318 *t_cp = (u_char) t_l; \