nameser.h revision 13771
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 * -
34 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
35 *
36 * Permission to use, copy, modify, and distribute this software for any
37 * purpose with or without fee is hereby granted, provided that the above
38 * copyright notice and this permission notice appear in all copies, and that
39 * the name of Digital Equipment Corporation not be used in advertising or
40 * publicity pertaining to distribution of the document or software without
41 * specific, written prior permission.
42 *
43 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
44 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
45 * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
46 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
47 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
48 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
49 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
50 * SOFTWARE.
51 * -
52 * --Copyright--
53 *
54 *      @(#)nameser.h	8.2 (Berkeley) 2/16/94
55 *	From Id: nameser.h,v 4.9.1.15 1994/07/19 22:51:24 vixie Exp
56 *	$Id: nameser.h,v 1.6 1996/01/07 05:01:52 peter Exp $
57 */
58
59#ifndef _ARPA_NAMESER_H_
60#define	_ARPA_NAMESER_H_
61
62#include <sys/param.h>
63#include <sys/types.h>
64#include <sys/cdefs.h>
65#include <machine/endian.h>
66
67
68/*
69 * revision information.  this is the release date in YYYYMMDD format.
70 * it can change every day so the right thing to do with it is use it
71 * in preprocessor commands such as "#if (__BIND > 19931104)".  do not
72 * compare for equality; rather, use it to determine whether your resolver
73 * is new enough to contain a certain feature.
74 */
75
76#define	__BIND		19950621	/* interface version stamp */
77
78/*
79 * Define constants based on rfc883
80 */
81#define	PACKETSZ	512		/* maximum packet size */
82#define	MAXDNAME	256		/* maximum domain name */
83#define	MAXCDNAME	255		/* maximum compressed domain name */
84#define	MAXLABEL	63		/* maximum length of domain label */
85#define	HFIXEDSZ	12		/* #/bytes of fixed data in header */
86#define	QFIXEDSZ	4		/* #/bytes of fixed data in query */
87#define	RRFIXEDSZ	10		/* #/bytes of fixed data in r record */
88#define	INT32SZ		4		/* for systems without 32-bit ints */
89#define	INT16SZ		2		/* for systems without 16-bit ints */
90#define	INADDRSZ	4		/* for sizeof(struct inaddr) != 4 */
91
92/*
93 * Internet nameserver port number
94 */
95#define	NAMESERVER_PORT	53
96
97/*
98 * Currently defined opcodes
99 */
100#define	QUERY		0x0		/* standard query */
101#define	IQUERY		0x1		/* inverse query */
102#define	STATUS		0x2		/* nameserver status query */
103/*#define xxx		0x3 */		/* 0x3 reserved */
104#define	NS_NOTIFY_OP	0x4		/* notify secondary of SOA change */
105#ifdef ALLOW_UPDATES
106	/* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
107# define UPDATEA	0x9		/* add resource record */
108# define UPDATED	0xa		/* delete a specific resource record */
109# define UPDATEDA	0xb		/* delete all named resource record */
110# define UPDATEM	0xc		/* modify a specific resource record */
111# define UPDATEMA	0xd		/* modify all named resource record */
112# define ZONEINIT	0xe		/* initial zone transfer */
113# define ZONEREF	0xf		/* incremental zone referesh */
114#endif
115
116/*
117 * Currently defined response codes
118 */
119#define	NOERROR		0		/* no error */
120#define	FORMERR		1		/* format error */
121#define	SERVFAIL	2		/* server failure */
122#define	NXDOMAIN	3		/* non existent domain */
123#define	NOTIMP		4		/* not implemented */
124#define	REFUSED		5		/* query refused */
125#ifdef ALLOW_UPDATES
126	/* non standard */
127# define NOCHANGE	0xf		/* update failed to change db */
128#endif
129
130/*
131 * Type values for resources and queries
132 */
133#define	T_A		1		/* host address */
134#define	T_NS		2		/* authoritative server */
135#define	T_MD		3		/* mail destination */
136#define	T_MF		4		/* mail forwarder */
137#define T_CNAME		5		/* canonical name */
138#define	T_SOA		6		/* start of authority zone */
139#define	T_MB		7		/* mailbox domain name */
140#define	T_MG		8		/* mail group member */
141#define	T_MR		9		/* mail rename name */
142#define	T_NULL		10		/* null resource record */
143#define	T_WKS		11		/* well known service */
144#define	T_PTR		12		/* domain name pointer */
145#define	T_HINFO		13		/* host information */
146#define	T_MINFO		14		/* mailbox information */
147#define	T_MX		15		/* mail routing information */
148#define	T_TXT		16		/* text strings */
149#define	T_RP		17		/* responsible person */
150#define	T_AFSDB		18		/* AFS cell database */
151#define	T_X25		19		/* X_25 calling address */
152#define	T_ISDN		20		/* ISDN calling address */
153#define	T_RT		21		/* router */
154#define	T_NSAP		22		/* NSAP address */
155#define	T_NSAP_PTR	23		/* reverse NSAP lookup (deprecated) */
156#define	T_SIG		24		/* security signature */
157#define	T_KEY		25		/* security key */
158#define	T_PX		26		/* X.400 mail mapping */
159#define	T_GPOS		27		/* geographical position (withdrawn) */
160#define	T_AAAA		28		/* IP6 Address */
161#define	T_LOC		29		/* Location Information */
162	/* non standard */
163#define	T_UINFO		100		/* user (finger) information */
164#define	T_UID		101		/* user ID */
165#define	T_GID		102		/* group ID */
166#define	T_UNSPEC	103		/* Unspecified format (binary data) */
167	/* Query type values which do not appear in resource records */
168#define	T_AXFR		252		/* transfer zone of authority */
169#define	T_MAILB		253		/* transfer mailbox records */
170#define	T_MAILA		254		/* transfer mail agent records */
171#define	T_ANY		255		/* wildcard match */
172
173/*
174 * Values for class field
175 */
176
177#define	C_IN		1		/* the arpa internet */
178#define	C_CHAOS		3		/* for chaos net (MIT) */
179#define	C_HS		4		/* for Hesiod name server (MIT) (XXX) */
180	/* Query class values which do not appear in resource records */
181#define	C_ANY		255		/* wildcard match */
182
183/*
184 * Status return codes for T_UNSPEC conversion routines
185 */
186#define	CONV_SUCCESS	0
187#define	CONV_OVERFLOW	(-1)
188#define	CONV_BADFMT	(-2)
189#define	CONV_BADCKSUM	(-3)
190#define	CONV_BADBUFLEN	(-4)
191
192/*
193 * Structure for query header.  The order of the fields is machine- and
194 * compiler-dependent, depending on the byte/bit order and the layout
195 * of bit fields.  We use bit fields only in int variables, as this
196 * is all ANSI requires.  This requires a somewhat confusing rearrangement.
197 */
198
199typedef struct {
200	unsigned	id :16;		/* query identification number */
201#if BYTE_ORDER == BIG_ENDIAN
202			/* fields in third byte */
203	unsigned	qr: 1;		/* response flag */
204	unsigned	opcode: 4;	/* purpose of message */
205	unsigned	aa: 1;		/* authoritative answer */
206	unsigned	tc: 1;		/* truncated message */
207	unsigned	rd: 1;		/* recursion desired */
208			/* fields in fourth byte */
209	unsigned	ra: 1;		/* recursion available */
210	unsigned	unused :3;	/* unused bits (MBZ as of 4.9.3a3) */
211	unsigned	rcode :4;	/* response code */
212#endif
213#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
214			/* fields in third byte */
215	unsigned	rd :1;		/* recursion desired */
216	unsigned	tc :1;		/* truncated message */
217	unsigned	aa :1;		/* authoritative answer */
218	unsigned	opcode :4;	/* purpose of message */
219	unsigned	qr :1;		/* response flag */
220			/* fields in fourth byte */
221	unsigned	rcode :4;	/* response code */
222	unsigned	unused :3;	/* unused bits (MBZ as of 4.9.3a3) */
223	unsigned	ra :1;		/* recursion available */
224#endif
225			/* remaining bytes */
226	unsigned	qdcount :16;	/* number of question entries */
227	unsigned	ancount :16;	/* number of answer entries */
228	unsigned	nscount :16;	/* number of authority entries */
229	unsigned	arcount :16;	/* number of resource entries */
230} HEADER;
231
232/*
233 * Defines for handling compressed domain names
234 */
235#define	INDIR_MASK	0xc0
236
237/*
238 * Structure for passing resource records around.
239 */
240struct rrec {
241	int16_t		r_zone;			/* zone number */
242	int16_t		r_class;		/* class number */
243	int16_t		r_type;			/* type number */
244	u_int32_t	r_ttl;			/* time to live */
245	int		r_size;			/* size of data area */
246	char		*r_data;		/* pointer to data */
247};
248
249extern	u_int16_t	_getshort __P((const u_char *));
250extern	u_int32_t	_getlong __P((const u_char *));
251
252/*
253 * Inline versions of get/put short/long.  Pointer is advanced.
254 *
255 * These macros demonstrate the property of C whereby it can be
256 * portable or it can be elegant but rarely both.
257 */
258#define	GETSHORT(s, cp) { \
259	register u_char *t_cp = (u_char *)(cp); \
260	(s) = ((u_int16_t)t_cp[0] << 8) \
261	    | ((u_int16_t)t_cp[1]) \
262	    ; \
263	(cp) += INT16SZ; \
264}
265
266#define	GETLONG(l, cp) { \
267	register u_char *t_cp = (u_char *)(cp); \
268	(l) = ((u_int32_t)t_cp[0] << 24) \
269	    | ((u_int32_t)t_cp[1] << 16) \
270	    | ((u_int32_t)t_cp[2] << 8) \
271	    | ((u_int32_t)t_cp[3]) \
272	    ; \
273	(cp) += INT32SZ; \
274}
275
276#define	PUTSHORT(s, cp) { \
277	register u_int16_t t_s = (u_int16_t)(s); \
278	register u_char *t_cp = (u_char *)(cp); \
279	*t_cp++ = t_s >> 8; \
280	*t_cp   = t_s; \
281	(cp) += INT16SZ; \
282}
283
284#define	PUTLONG(l, cp) { \
285	register u_int32_t t_l = (u_int32_t)(l); \
286	register u_char *t_cp = (u_char *)(cp); \
287	*t_cp++ = t_l >> 24; \
288	*t_cp++ = t_l >> 16; \
289	*t_cp++ = t_l >> 8; \
290	*t_cp   = t_l; \
291	(cp) += INT32SZ; \
292}
293
294#endif /* !_ARPA_NAMESER_H_ */
295