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