Libinfo-173.tar.gz
[apple/libinfo.git] / dns.subproj / nameser8_compat.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * ++Copyright++ 1983, 1989, 1993
27 * -
28 * Copyright (c) 1983, 1989, 1993
29 * The Regents of the University of California. All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 * -
59 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
60 *
61 * Permission to use, copy, modify, and distribute this software for any
62 * purpose with or without fee is hereby granted, provided that the above
63 * copyright notice and this permission notice appear in all copies, and that
64 * the name of Digital Equipment Corporation not be used in advertising or
65 * publicity pertaining to distribution of the document or software without
66 * specific, written prior permission.
67 *
68 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
69 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
70 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
71 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
72 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
73 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
74 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
75 * SOFTWARE.
76 * -
77 * --Copyright--
78 */
79
80 /*
81 * @(#)nameser.h 8.1 (Berkeley) 6/2/93
82 * $Id: nameser8_compat.h,v 1.2 2003/02/18 17:29:24 majka Exp $
83 */
84
85 #ifndef _NAMESER_H_
86 #define _NAMESER_H_
87
88 #include <sys/param.h>
89 #if (!defined(BSD)) || (BSD < 199306)
90 # include <sys/bitypes.h>
91 #else
92 # include <sys/types.h>
93 #endif
94 #include <sys/cdefs.h>
95
96 #ifdef _AUX_SOURCE
97 #include <sys/types.h> /* ech for A/UX */
98 #define res_send ucb_res_send /* already def'd in libc */
99 #define _res_close _ucb_res_close /* removing res_send.o from the library */
100 #endif /* gives an undefined symbol... */
101
102 /*
103 * revision information. this is the release date in YYYYMMDD format.
104 * it can change every day so the right thing to do with it is use it
105 * in preprocessor commands such as "#if (__BIND > 19931104)". do not
106 * compare for equality; rather, use it to determine whether your resolver
107 * is new enough to contain a certain feature.
108 */
109
110 #define __BIND 19950621 /* interface version stamp */
111
112 /*
113 * Define constants based on rfc883
114 */
115 #define PACKETSZ 512 /* maximum packet size */
116 #define MAXDNAME 256 /* maximum domain name */
117 #define MAXCDNAME 255 /* maximum compressed domain name */
118 #define MAXLABEL 63 /* maximum length of domain label */
119 #define HFIXEDSZ 12 /* #/bytes of fixed data in header */
120 #define QFIXEDSZ 4 /* #/bytes of fixed data in query */
121 #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
122 #define INT32SZ 4 /* for systems without 32-bit ints */
123 #define INT16SZ 2 /* for systems without 16-bit ints */
124 #define INADDRSZ 4 /* for sizeof(struct inaddr) != 4 */
125
126 /*
127 * Internet nameserver port number
128 */
129 #define NAMESERVER_PORT 53
130
131 /*
132 * Currently defined opcodes
133 */
134 #define QUERY 0x0 /* standard query */
135 #define IQUERY 0x1 /* inverse query */
136 #define STATUS 0x2 /* nameserver status query */
137 /*#define xxx 0x3*/ /* 0x3 reserved */
138 #define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
139 #ifdef ALLOW_UPDATES
140 /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
141 # define UPDATEA 0x9 /* add resource record */
142 # define UPDATED 0xa /* delete a specific resource record */
143 # define UPDATEDA 0xb /* delete all named resource record */
144 # define UPDATEM 0xc /* modify a specific resource record */
145 # define UPDATEMA 0xd /* modify all named resource record */
146 # define ZONEINIT 0xe /* initial zone transfer */
147 # define ZONEREF 0xf /* incremental zone referesh */
148 #endif
149
150 /*
151 * Currently defined response codes
152 */
153 #define NOERROR 0 /* no error */
154 #define FORMERR 1 /* format error */
155 #define SERVFAIL 2 /* server failure */
156 #define NXDOMAIN 3 /* non existent domain */
157 #define NOTIMP 4 /* not implemented */
158 #define REFUSED 5 /* query refused */
159 #ifdef ALLOW_UPDATES
160 /* non standard */
161 # define NOCHANGE 0xf /* update failed to change db */
162 #endif
163
164 /*
165 * Type values for resources and queries
166 */
167 #define T_A 1 /* host address */
168 #define T_NS 2 /* authoritative server */
169 #define T_MD 3 /* mail destination */
170 #define T_MF 4 /* mail forwarder */
171 #define T_CNAME 5 /* canonical name */
172 #define T_SOA 6 /* start of authority zone */
173 #define T_MB 7 /* mailbox domain name */
174 #define T_MG 8 /* mail group member */
175 #define T_MR 9 /* mail rename name */
176 #define T_NULL 10 /* null resource record */
177 #define T_WKS 11 /* well known service */
178 #define T_PTR 12 /* domain name pointer */
179 #define T_HINFO 13 /* host information */
180 #define T_MINFO 14 /* mailbox information */
181 #define T_MX 15 /* mail routing information */
182 #define T_TXT 16 /* text strings */
183 #define T_RP 17 /* responsible person */
184 #define T_AFSDB 18 /* AFS cell database */
185 #define T_X25 19 /* X_25 calling address */
186 #define T_ISDN 20 /* ISDN calling address */
187 #define T_RT 21 /* router */
188 #define T_NSAP 22 /* NSAP address */
189 #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
190 #define T_SIG 24 /* security signature */
191 #define T_KEY 25 /* security key */
192 #define T_PX 26 /* X.400 mail mapping */
193 #define T_GPOS 27 /* geographical position (withdrawn) */
194 #define T_AAAA 28 /* IP6 Address */
195 #define T_LOC 29 /* Location Information */
196 /* non standard */
197 #define T_UINFO 100 /* user (finger) information */
198 #define T_UID 101 /* user ID */
199 #define T_GID 102 /* group ID */
200 #define T_UNSPEC 103 /* Unspecified format (binary data) */
201 /* Query type values which do not appear in resource records */
202 #define T_AXFR 252 /* transfer zone of authority */
203 #define T_MAILB 253 /* transfer mailbox records */
204 #define T_MAILA 254 /* transfer mail agent records */
205 #define T_ANY 255 /* wildcard match */
206
207 /*
208 * Values for class field
209 */
210
211 #define C_IN 1 /* the arpa internet */
212 #define C_CHAOS 3 /* for chaos net (MIT) */
213 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
214 /* Query class values which do not appear in resource records */
215 #define C_ANY 255 /* wildcard match */
216
217 /*
218 * Status return codes for T_UNSPEC conversion routines
219 */
220 #define CONV_SUCCESS 0
221 #define CONV_OVERFLOW (-1)
222 #define CONV_BADFMT (-2)
223 #define CONV_BADCKSUM (-3)
224 #define CONV_BADBUFLEN (-4)
225
226 #ifndef BYTE_ORDER
227 #if (BSD >= 199103)
228 # include <machine/endian.h>
229 #else
230 #ifdef linux
231 # include <endian.h>
232 #else
233 #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
234 #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
235 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
236
237 #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
238 defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
239 defined(__alpha__) || defined(__alpha)
240 #define BYTE_ORDER LITTLE_ENDIAN
241 #endif
242
243 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
244 defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
245 defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
246 defined(apollo) || defined(__convex__) || defined(_CRAY) || \
247 defined(__hppa) || defined(__hp9000) || \
248 defined(__hp9000s300) || defined(__hp9000s700) || \
249 defined (BIT_ZERO_ON_LEFT) || defined(m68k)
250 #define BYTE_ORDER BIG_ENDIAN
251 #endif
252 #endif /* linux */
253 #endif /* BSD */
254 #endif /* BYTE_ORDER */
255
256 #if !defined(BYTE_ORDER) || \
257 (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
258 BYTE_ORDER != PDP_ENDIAN)
259 /* you must determine what the correct bit order is for
260 * your compiler - the next line is an intentional error
261 * which will force your compiles to bomb until you fix
262 * the above macros.
263 */
264 error "Undefined or invalid BYTE_ORDER";
265 #endif
266
267 /*
268 * Structure for query header. The order of the fields is machine- and
269 * compiler-dependent, depending on the byte/bit order and the layout
270 * of bit fields. We use bit fields only in int variables, as this
271 * is all ANSI requires. This requires a somewhat confusing rearrangement.
272 */
273
274 typedef struct {
275 unsigned id :16; /* query identification number */
276 #if BYTE_ORDER == BIG_ENDIAN
277 /* fields in third byte */
278 unsigned qr: 1; /* response flag */
279 unsigned opcode: 4; /* purpose of message */
280 unsigned aa: 1; /* authoritive answer */
281 unsigned tc: 1; /* truncated message */
282 unsigned rd: 1; /* recursion desired */
283 /* fields in fourth byte */
284 unsigned ra: 1; /* recursion available */
285 unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */
286 unsigned rcode :4; /* response code */
287 #endif
288 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
289 /* fields in third byte */
290 unsigned rd :1; /* recursion desired */
291 unsigned tc :1; /* truncated message */
292 unsigned aa :1; /* authoritive answer */
293 unsigned opcode :4; /* purpose of message */
294 unsigned qr :1; /* response flag */
295 /* fields in fourth byte */
296 unsigned rcode :4; /* response code */
297 unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */
298 unsigned ra :1; /* recursion available */
299 #endif
300 /* remaining bytes */
301 unsigned qdcount :16; /* number of question entries */
302 unsigned ancount :16; /* number of answer entries */
303 unsigned nscount :16; /* number of authority entries */
304 unsigned arcount :16; /* number of resource entries */
305 } HEADER;
306
307 /*
308 * Defines for handling compressed domain names
309 */
310 #define INDIR_MASK 0xc0
311
312 /*
313 * Structure for passing resource records around.
314 */
315 struct rrec {
316 int16_t r_zone; /* zone number */
317 int16_t r_class; /* class number */
318 int16_t r_type; /* type number */
319 u_int32_t r_ttl; /* time to live */
320 int r_size; /* size of data area */
321 char *r_data; /* pointer to data */
322 };
323
324 extern u_int16_t _getshort __P((const u_char *));
325 extern u_int32_t _getlong __P((const u_char *));
326
327 /*
328 * Inline versions of get/put short/long. Pointer is advanced.
329 *
330 * These macros demonstrate the property of C whereby it can be
331 * portable or it can be elegant but rarely both.
332 */
333 #define GETSHORT(s, cp) { \
334 register u_char *t_cp = (u_char *)(cp); \
335 (s) = ((u_int16_t)t_cp[0] << 8) \
336 | ((u_int16_t)t_cp[1]) \
337 ; \
338 (cp) += INT16SZ; \
339 }
340
341 #define GETLONG(l, cp) { \
342 register u_char *t_cp = (u_char *)(cp); \
343 (l) = ((u_int32_t)t_cp[0] << 24) \
344 | ((u_int32_t)t_cp[1] << 16) \
345 | ((u_int32_t)t_cp[2] << 8) \
346 | ((u_int32_t)t_cp[3]) \
347 ; \
348 (cp) += INT32SZ; \
349 }
350
351 #define PUTSHORT(s, cp) { \
352 register u_int16_t t_s = (u_int16_t)(s); \
353 register u_char *t_cp = (u_char *)(cp); \
354 *t_cp++ = t_s >> 8; \
355 *t_cp = t_s; \
356 (cp) += INT16SZ; \
357 }
358
359 #define PUTLONG(l, cp) { \
360 register u_int32_t t_l = (u_int32_t)(l); \
361 register u_char *t_cp = (u_char *)(cp); \
362 *t_cp++ = t_l >> 24; \
363 *t_cp++ = t_l >> 16; \
364 *t_cp++ = t_l >> 8; \
365 *t_cp = t_l; \
366 (cp) += INT32SZ; \
367 }
368
369 #endif /* !_NAMESER_H_ */