xref: /original-bsd/include/arpa/nameser.h (revision c3e32dec)
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.1 (Berkeley) 06/02/93
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 	/* non standard */
102 #define T_UINFO		100		/* user (finger) information */
103 #define T_UID		101		/* user ID */
104 #define T_GID		102		/* group ID */
105 #define T_UNSPEC	103		/* Unspecified format (binary data) */
106 	/* Query type values which do not appear in resource records */
107 #define T_AXFR		252		/* transfer zone of authority */
108 #define T_MAILB		253		/* transfer mailbox records */
109 #define T_MAILA		254		/* transfer mail agent records */
110 #define T_ANY		255		/* wildcard match */
111 
112 /*
113  * Values for class field
114  */
115 
116 #define C_IN		1		/* the arpa internet */
117 #define C_CHAOS		3		/* for chaos net (MIT) */
118 #define C_HS		4		/* for Hesiod name server (MIT) (XXX) */
119 	/* Query class values which do not appear in resource records */
120 #define C_ANY		255		/* wildcard match */
121 
122 /*
123  * Status return codes for T_UNSPEC conversion routines
124  */
125 #define CONV_SUCCESS 0
126 #define CONV_OVERFLOW -1
127 #define CONV_BADFMT -2
128 #define CONV_BADCKSUM -3
129 #define CONV_BADBUFLEN -4
130 
131 #ifndef BYTE_ORDER
132 #define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax, pc) */
133 #define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
134 #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp)*/
135 
136 #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
137     defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
138     defined(__alpha__) || defined(__alpha)
139 #define BYTE_ORDER	LITTLE_ENDIAN
140 #endif
141 
142 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
143     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
144     defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || \
145     defined(apollo) || defined(hp9000) || defined(hp9000s300) || \
146     defined (BIT_ZERO_ON_LEFT)
147 #define BYTE_ORDER	BIG_ENDIAN
148 #endif
149 #endif /* BYTE_ORDER */
150 
151 #if !defined(BYTE_ORDER) || \
152     (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
153     BYTE_ORDER != PDP_ENDIAN)
154 	/* you must determine what the correct bit order is for
155 	 * your compiler - the next line is an intentional error
156 	 * which will force your compiles to bomb until you fix
157 	 * the above macros.
158 	 */
159   #error "Undefined or invalid BYTE_ORDER";
160 #endif
161 
162 /*
163  * Structure for query header.  The order of the fields is machine- and
164  * compiler-dependent, depending on the byte/bit order and the layout
165  * of bit fields.  We use bit fields only in int variables, as this
166  * is all ANSI requires.  This requires a somewhat confusing rearrangement.
167  */
168 
169 typedef struct {
170 	u_int16_t id;		/* query identification number */
171 #if BYTE_ORDER == BIG_ENDIAN
172 			/* fields in third byte */
173 	u_int	qr:1;		/* response flag */
174 	u_int	opcode:4;	/* purpose of message */
175 	u_int	aa:1;		/* authoritive answer */
176 	u_int	tc:1;		/* truncated message */
177 	u_int	rd:1;		/* recursion desired */
178 			/* fields in fourth byte */
179 	u_int	ra:1;		/* recursion available */
180 	u_int	pr:1;		/* primary server required (non standard) */
181 	u_int	unused:2;	/* unused bits */
182 	u_int	rcode:4;	/* response code */
183 #endif
184 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
185 			/* fields in third byte */
186 	u_int	rd:1;		/* recursion desired */
187 	u_int	tc:1;		/* truncated message */
188 	u_int	aa:1;		/* authoritive answer */
189 	u_int	opcode:4;	/* purpose of message */
190 	u_int	qr:1;		/* response flag */
191 			/* fields in fourth byte */
192 	u_int	rcode:4;	/* response code */
193 	u_int	unused:2;	/* unused bits */
194 	u_int	pr:1;		/* primary server required (non standard) */
195 	u_int	ra:1;		/* recursion available */
196 #endif
197 			/* remaining bytes */
198 	u_int16_t qdcount;	/* number of question entries */
199 	u_int16_t ancount;	/* number of answer entries */
200 	u_int16_t nscount;	/* number of authority entries */
201 	u_int16_t arcount;	/* number of resource entries */
202 } HEADER;
203 
204 /*
205  * Defines for handling compressed domain names
206  */
207 #define INDIR_MASK	0xc0
208 
209 /*
210  * Structure for passing resource records around.
211  */
212 struct rrec {
213 	int16_t	r_zone;			/* zone number */
214 	int16_t	r_class;		/* class number */
215 	int16_t	r_type;			/* type number */
216 	u_int32_t	r_ttl;			/* time to live */
217 	int	r_size;			/* size of data area */
218 	char	*r_data;		/* pointer to data */
219 };
220 
221 extern	u_int16_t	_getshort();
222 extern	u_int32_t	_getlong();
223 
224 /*
225  * Inline versions of get/put short/long.  Pointer is advanced.
226  * We also assume that a "u_int16_t" holds 2 "chars"
227  * and that a "u_int32_t" holds 4 "chars".
228  *
229  * These macros demonstrate the property of C whereby it can be
230  * portable or it can be elegant but never both.
231  */
232 #define GETSHORT(s, cp) { \
233 	register u_char *t_cp = (u_char *)(cp); \
234 	(s) = ((u_int16_t)t_cp[0] << 8) | (u_int16_t)t_cp[1]; \
235 	(cp) += 2; \
236 }
237 
238 #define GETLONG(l, cp) { \
239 	register u_char *t_cp = (u_char *)(cp); \
240 	(l) = (((u_int32_t)t_cp[0]) << 24) \
241 	    | (((u_int32_t)t_cp[1]) << 16) \
242 	    | (((u_int32_t)t_cp[2]) << 8) \
243 	    | (((u_int32_t)t_cp[3])); \
244 	(cp) += 4; \
245 }
246 
247 #define PUTSHORT(s, cp) { \
248 	register u_int16_t t_s = (u_int16_t)(s); \
249 	register u_char *t_cp = (u_char *)(cp); \
250 	*t_cp++ = t_s >> 8; \
251 	*t_cp   = t_s; \
252 	(cp) += 2; \
253 }
254 
255 /*
256  * Warning: PUTLONG --no-longer-- destroys its first argument.  if you
257  * were depending on this "feature", you will lose.
258  */
259 #define PUTLONG(l, cp) { \
260 	register u_int32_t t_l = (u_int32_t)(l); \
261 	register u_char *t_cp = (u_char *)(cp); \
262 	*t_cp++ = t_l >> 24; \
263 	*t_cp++ = t_l >> 16; \
264 	*t_cp++ = t_l >> 8; \
265 	*t_cp   = t_l; \
266 	(cp) += 4; \
267 }
268 
269 #endif /* !_NAMESER_H_ */
270