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