xref: /original-bsd/include/arpa/nameser.h (revision 468915a8)
1 /*
2  * Copyright (c) 1983, 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *      @(#)nameser.h	8.2 (Berkeley) 02/16/94
8  * -
9  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
10  *
11  * Permission to use, copy, modify, and distribute this software for any
12  * purpose with or without fee is hereby granted, provided that the above
13  * copyright notice and this permission notice appear in all copies, and that
14  * the name of Digital Equipment Corporation not be used in advertising or
15  * publicity pertaining to distribution of the document or software without
16  * specific, written prior permission.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
19  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
21  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
22  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
23  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
24  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
25  * SOFTWARE.
26  * -
27  * --Copyright--
28  */
29 
30 #ifndef _NAMESER_H_
31 #define	_NAMESER_H_
32 
33 #include <sys/types.h>
34 
35 /*
36  * Define constants based on rfc883
37  */
38 #define PACKETSZ	512		/* maximum packet size */
39 #define MAXDNAME	256		/* maximum domain name */
40 #define MAXCDNAME	255		/* maximum compressed domain name */
41 #define MAXLABEL	63		/* maximum length of domain label */
42 	/* Number of bytes of fixed size data in query structure */
43 #define QFIXEDSZ	4
44 	/* number of bytes of fixed size data in resource record */
45 #define RRFIXEDSZ	10
46 
47 /*
48  * Internet nameserver port number
49  */
50 #define NAMESERVER_PORT	53
51 
52 /*
53  * Currently defined opcodes
54  */
55 #define QUERY		0x0		/* standard query */
56 #define IQUERY		0x1		/* inverse query */
57 #define STATUS		0x2		/* nameserver status query */
58 /*#define xxx		0x3		/* 0x3 reserved */
59 	/* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
60 #define UPDATEA		0x9		/* add resource record */
61 #define UPDATED		0xa		/* delete a specific resource record */
62 #define UPDATEDA	0xb		/* delete all named resource record */
63 #define UPDATEM		0xc		/* modify a specific resource record */
64 #define UPDATEMA	0xd		/* modify all named resource record */
65 
66 #define ZONEINIT	0xe		/* initial zone transfer */
67 #define ZONEREF		0xf		/* incremental zone referesh */
68 
69 /*
70  * Currently defined response codes
71  */
72 #define NOERROR		0		/* no error */
73 #define FORMERR		1		/* format error */
74 #define SERVFAIL	2		/* server failure */
75 #define NXDOMAIN	3		/* non existent domain */
76 #define NOTIMP		4		/* not implemented */
77 #define REFUSED		5		/* query refused */
78 	/* non standard */
79 #define NOCHANGE	0xf		/* update failed to change db */
80 
81 /*
82  * Type values for resources and queries
83  */
84 #define T_A		1		/* host address */
85 #define T_NS		2		/* authoritative server */
86 #define T_MD		3		/* mail destination */
87 #define T_MF		4		/* mail forwarder */
88 #define T_CNAME		5		/* connonical name */
89 #define T_SOA		6		/* start of authority zone */
90 #define T_MB		7		/* mailbox domain name */
91 #define T_MG		8		/* mail group member */
92 #define T_MR		9		/* mail rename name */
93 #define T_NULL		10		/* null resource record */
94 #define T_WKS		11		/* well known service */
95 #define T_PTR		12		/* domain name pointer */
96 #define T_HINFO		13		/* host information */
97 #define T_MINFO		14		/* mailbox information */
98 #define T_MX		15		/* mail routing information */
99 #define T_TXT		16		/* text strings */
100 #define	T_RP		17		/* responsible person */
101 #define	T_AFSDB		18		/* AFS cell database */
102 #define	T_NSAP		22		/* NSAP address */
103 #define	T_NSAP_PTR	23		/* reverse lookup for NSAP */
104 	/* non standard */
105 #define T_UINFO		100		/* user (finger) information */
106 #define T_UID		101		/* user ID */
107 #define T_GID		102		/* group ID */
108 #define T_UNSPEC	103		/* Unspecified format (binary data) */
109 	/* Query type values which do not appear in resource records */
110 #define T_AXFR		252		/* transfer zone of authority */
111 #define T_MAILB		253		/* transfer mailbox records */
112 #define T_MAILA		254		/* transfer mail agent records */
113 #define T_ANY		255		/* wildcard match */
114 
115 /*
116  * Values for class field
117  */
118 
119 #define C_IN		1		/* the arpa internet */
120 #define C_CHAOS		3		/* for chaos net (MIT) */
121 #define C_HS		4		/* for Hesiod name server (MIT) (XXX) */
122 	/* Query class values which do not appear in resource records */
123 #define C_ANY		255		/* wildcard match */
124 
125 /*
126  * Status return codes for T_UNSPEC conversion routines
127  */
128 #define CONV_SUCCESS 0
129 #define CONV_OVERFLOW -1
130 #define CONV_BADFMT -2
131 #define CONV_BADCKSUM -3
132 #define CONV_BADBUFLEN -4
133 
134 #ifndef BYTE_ORDER
135 #define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax, pc) */
136 #define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
137 #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp)*/
138 
139 #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
140     defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
141     defined(__alpha__) || defined(__alpha)
142 #define BYTE_ORDER	LITTLE_ENDIAN
143 #endif
144 
145 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
146     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
147     defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || \
148     defined(apollo) || defined(hp9000) || defined(hp9000s300) || \
149     defined (BIT_ZERO_ON_LEFT)
150 #define BYTE_ORDER	BIG_ENDIAN
151 #endif
152 #endif /* BYTE_ORDER */
153 
154 #if !defined(BYTE_ORDER) || \
155     (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
156     BYTE_ORDER != PDP_ENDIAN)
157 	/* you must determine what the correct bit order is for
158 	 * your compiler - the next line is an intentional error
159 	 * which will force your compiles to bomb until you fix
160 	 * the above macros.
161 	 */
162   #error "Undefined or invalid BYTE_ORDER";
163 #endif
164 
165 /*
166  * Structure for query header.  The order of the fields is machine- and
167  * compiler-dependent, depending on the byte/bit order and the layout
168  * of bit fields.  We use bit fields only in int variables, as this
169  * is all ANSI requires.  This requires a somewhat confusing rearrangement.
170  */
171 
172 typedef struct {
173 	u_int16_t id;		/* query identification number */
174 #if BYTE_ORDER == BIG_ENDIAN
175 			/* fields in third byte */
176 	u_int	qr:1;		/* response flag */
177 	u_int	opcode:4;	/* purpose of message */
178 	u_int	aa:1;		/* authoritive answer */
179 	u_int	tc:1;		/* truncated message */
180 	u_int	rd:1;		/* recursion desired */
181 			/* fields in fourth byte */
182 	u_int	ra:1;		/* recursion available */
183 	u_int	pr:1;		/* primary server required (non standard) */
184 	u_int	unused:2;	/* unused bits */
185 	u_int	rcode:4;	/* response code */
186 #endif
187 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
188 			/* fields in third byte */
189 	u_int	rd:1;		/* recursion desired */
190 	u_int	tc:1;		/* truncated message */
191 	u_int	aa:1;		/* authoritive answer */
192 	u_int	opcode:4;	/* purpose of message */
193 	u_int	qr:1;		/* response flag */
194 			/* fields in fourth byte */
195 	u_int	rcode:4;	/* response code */
196 	u_int	unused:2;	/* unused bits */
197 	u_int	pr:1;		/* primary server required (non standard) */
198 	u_int	ra:1;		/* recursion available */
199 #endif
200 			/* remaining bytes */
201 	u_int16_t qdcount;	/* number of question entries */
202 	u_int16_t ancount;	/* number of answer entries */
203 	u_int16_t nscount;	/* number of authority entries */
204 	u_int16_t arcount;	/* number of resource entries */
205 } HEADER;
206 
207 /*
208  * Defines for handling compressed domain names
209  */
210 #define INDIR_MASK	0xc0
211 
212 /*
213  * Structure for passing resource records around.
214  */
215 struct rrec {
216 	int16_t	r_zone;			/* zone number */
217 	int16_t	r_class;		/* class number */
218 	int16_t	r_type;			/* type number */
219 	u_int32_t	r_ttl;			/* time to live */
220 	int	r_size;			/* size of data area */
221 	char	*r_data;		/* pointer to data */
222 };
223 
224 extern	u_int16_t	_getshort();
225 extern	u_int32_t	_getlong();
226 
227 /*
228  * Inline versions of get/put short/long.  Pointer is advanced.
229  * We also assume that a "u_int16_t" holds 2 "chars"
230  * and that a "u_int32_t" holds 4 "chars".
231  *
232  * These macros demonstrate the property of C whereby it can be
233  * portable or it can be elegant but never both.
234  */
235 #define GETSHORT(s, cp) { \
236 	register u_char *t_cp = (u_char *)(cp); \
237 	(s) = ((u_int16_t)t_cp[0] << 8) | (u_int16_t)t_cp[1]; \
238 	(cp) += 2; \
239 }
240 
241 #define GETLONG(l, cp) { \
242 	register u_char *t_cp = (u_char *)(cp); \
243 	(l) = (((u_int32_t)t_cp[0]) << 24) \
244 	    | (((u_int32_t)t_cp[1]) << 16) \
245 	    | (((u_int32_t)t_cp[2]) << 8) \
246 	    | (((u_int32_t)t_cp[3])); \
247 	(cp) += 4; \
248 }
249 
250 #define PUTSHORT(s, cp) { \
251 	register u_int16_t t_s = (u_int16_t)(s); \
252 	register u_char *t_cp = (u_char *)(cp); \
253 	*t_cp++ = t_s >> 8; \
254 	*t_cp   = t_s; \
255 	(cp) += 2; \
256 }
257 
258 /*
259  * Warning: PUTLONG --no-longer-- destroys its first argument.  if you
260  * were depending on this "feature", you will lose.
261  */
262 #define PUTLONG(l, cp) { \
263 	register u_int32_t t_l = (u_int32_t)(l); \
264 	register u_char *t_cp = (u_char *)(cp); \
265 	*t_cp++ = t_l >> 24; \
266 	*t_cp++ = t_l >> 16; \
267 	*t_cp++ = t_l >> 8; \
268 	*t_cp   = t_l; \
269 	(cp) += 4; \
270 }
271 
272 #endif /* !_NAMESER_H_ */
273