1 | /* Modified for emx by hv 1994,1996
|
---|
2 | * Modified for gcc/os2 by bird 2003
|
---|
3 | *
|
---|
4 | * Copyright (c) 1983, 1989 Regents of the University of California.
|
---|
5 | * All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | * 1. Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * 3. All advertising materials mentioning features or use of this software
|
---|
16 | * must display the following acknowledgement:
|
---|
17 | * This product includes software developed by the University of
|
---|
18 | * California, Berkeley and its contributors.
|
---|
19 | * 4. Neither the name of the University nor the names of its contributors
|
---|
20 | * may be used to endorse or promote products derived from this software
|
---|
21 | * without specific prior written permission.
|
---|
22 | *
|
---|
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
33 | * SUCH DAMAGE.
|
---|
34 | *
|
---|
35 | * from: @(#)nameser.h 5.25 (Berkeley) 4/3/91
|
---|
36 | * $Id: nameser.h,v 1.4 1993/10/27 00:10:40 mycroft Exp $
|
---|
37 | */
|
---|
38 |
|
---|
39 | #ifndef _NAMESER_H_
|
---|
40 | #define _NAMESER_H_
|
---|
41 |
|
---|
42 | #if defined (__cplusplus)
|
---|
43 | extern "C" {
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | #include <sys/param.h> /* htons() etc. */
|
---|
47 | #include <machine/endian.h> /* BYTE ORDER etc. */
|
---|
48 | #ifndef TCPV40HDRS
|
---|
49 | #include "../types.h" /* #include <types.h> frequently includes the wrong header. */
|
---|
50 | #include <sys/cdefs.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * Define constants based on rfc883
|
---|
55 | */
|
---|
56 | #define PACKETSZ 512 /* maximum packet size */
|
---|
57 | #ifdef TCPV40HDRS
|
---|
58 | #define MAXDNAME 256 /* maximum domain name */
|
---|
59 | #else
|
---|
60 | #define MAXDNAME 1025 /* maximum presentation domain name */
|
---|
61 | #endif
|
---|
62 | #define MAXCDNAME 255 /* maximum compressed domain name */
|
---|
63 | #define MAXLABEL 63 /* maximum length of domain label */
|
---|
64 | /* Number of bytes of fixed size data in query structure */
|
---|
65 | #define QFIXEDSZ 4
|
---|
66 | /* number of bytes of fixed size data in resource record */
|
---|
67 | #define RRFIXEDSZ 10
|
---|
68 | #ifndef TCPV40HDRS
|
---|
69 | #define HFIXEDSZ 12 /* #/bytes of fixed data in header */
|
---|
70 | #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
|
---|
71 | #define INT32SZ 4 /* for systems without 32-bit ints */
|
---|
72 | #define INT16SZ 2 /* for systems without 16-bit ints */
|
---|
73 | #define INADDRSZ 4 /* IPv4 T_A */
|
---|
74 | #define IN6ADDRSZ 16 /* IPv6 T_AAAA */
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | /*
|
---|
78 | * Internet nameserver port number
|
---|
79 | */
|
---|
80 | #define NAMESERVER_PORT 53
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * Currently defined opcodes
|
---|
84 | */
|
---|
85 | #define QUERY 0x0 /* standard query */
|
---|
86 | #define IQUERY 0x1 /* inverse query */
|
---|
87 | #ifdef TCPV40HDRS
|
---|
88 | #define CQUERYM 2 /* completion query (multiple) */
|
---|
89 | #define CQUERYU 3 /* completion query (unique) */
|
---|
90 | #endif
|
---|
91 | #define STATUS 0x2 /* nameserver status query */
|
---|
92 | /*#define xxx 0x3 0x3 reserved */
|
---|
93 | /* non standard */
|
---|
94 | #ifdef TCPV40HDRS
|
---|
95 | /* IBM has changed these codes in TCP/IP for OS/2 */
|
---|
96 | #define UPDATEA 100 /* add resource record */
|
---|
97 | #define UPDATED 101 /* delete a specific resource record */
|
---|
98 | #define UPDATEM 102 /* modify a specific resource record */
|
---|
99 | #define ZONEINIT 103 /* initial zone transfer */
|
---|
100 | #define ZONEREF 104 /* incremental zone referesh */
|
---|
101 | #else
|
---|
102 | #define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * Currently defined response codes
|
---|
107 | */
|
---|
108 | #define NOERROR 0 /* no error */
|
---|
109 | #define FORMERR 1 /* format error */
|
---|
110 | #define SERVFAIL 2 /* server failure */
|
---|
111 | #define NXDOMAIN 3 /* non existent domain */
|
---|
112 | #define NOTIMP 4 /* not implemented */
|
---|
113 | #define REFUSED 5 /* query refused */
|
---|
114 | /* non standard */
|
---|
115 | #ifdef TCPV40HDRS
|
---|
116 | #define NOCHANGE 100 /* update failed to change db */
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | /*
|
---|
120 | * Type values for resources and queries
|
---|
121 | */
|
---|
122 | #define T_A 1 /* host address */
|
---|
123 | #define T_NS 2 /* authoritative server */
|
---|
124 | #define T_MD 3 /* mail destination */
|
---|
125 | #define T_MF 4 /* mail forwarder */
|
---|
126 | #define T_CNAME 5 /* connonical name */
|
---|
127 | #define T_SOA 6 /* start of authority zone */
|
---|
128 | #define T_MB 7 /* mailbox domain name */
|
---|
129 | #define T_MG 8 /* mail group member */
|
---|
130 | #define T_MR 9 /* mail rename name */
|
---|
131 | #define T_NULL 10 /* null resource record */
|
---|
132 | #define T_WKS 11 /* well known service */
|
---|
133 | #define T_PTR 12 /* domain name pointer */
|
---|
134 | #define T_HINFO 13 /* host information */
|
---|
135 | #define T_MINFO 14 /* mailbox information */
|
---|
136 | #define T_MX 15 /* mail routing information */
|
---|
137 | #ifndef TCPV40HDRS
|
---|
138 | #define T_TXT 16 /* text strings */
|
---|
139 | #define T_RP 17 /* responsible person */
|
---|
140 | #define T_AFSDB 18 /* AFS cell database */
|
---|
141 | #define T_X25 19 /* X_25 calling address */
|
---|
142 | #define T_ISDN 20 /* ISDN calling address */
|
---|
143 | #define T_RT 21 /* router */
|
---|
144 | #define T_NSAP 22 /* NSAP address */
|
---|
145 | #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
|
---|
146 | #define T_SIG 24 /* security signature */
|
---|
147 | #define T_KEY 25 /* security key */
|
---|
148 | #define T_PX 26 /* X.400 mail mapping */
|
---|
149 | #define T_GPOS 27 /* geographical position (withdrawn) */
|
---|
150 | #define T_AAAA 28 /* IP6 Address */
|
---|
151 | #define T_LOC 29 /* Location Information */
|
---|
152 | #define T_NXT 30 /* Next Valid Name in Zone */
|
---|
153 | #define T_EID 31 /* Endpoint identifier */
|
---|
154 | #define T_NIMLOC 32 /* Nimrod locator */
|
---|
155 | #define T_SRV 33 /* Server selection */
|
---|
156 | #define T_ATMA 34 /* ATM Address */
|
---|
157 | #define T_NAPTR 35 /* Naming Authority PoinTeR */
|
---|
158 | #endif
|
---|
159 | /* non standard */
|
---|
160 | #define T_UINFO 100 /* user (finger) information */
|
---|
161 | #define T_UID 101 /* user ID */
|
---|
162 | #define T_GID 102 /* group ID */
|
---|
163 | #ifndef TCPV40HDRS
|
---|
164 | #define T_UNSPEC 103 /* Unspecified format (binary data) */
|
---|
165 | #endif
|
---|
166 | /* Query type values which do not appear in resource records */
|
---|
167 | #ifndef TCPV40HDRS
|
---|
168 | #define T_IXFR 251 /* incremental zone transfer */
|
---|
169 | #endif
|
---|
170 | #define T_AXFR 252 /* transfer zone of authority */
|
---|
171 | #define T_MAILB 253 /* transfer mailbox records */
|
---|
172 | #define T_MAILA 254 /* transfer mail agent records */
|
---|
173 | #define T_ANY 255 /* wildcard match */
|
---|
174 |
|
---|
175 | /*
|
---|
176 | * Values for class field
|
---|
177 | */
|
---|
178 | #define C_IN 1 /* the arpa internet */
|
---|
179 | #define C_CHAOS 3 /* for chaos net at MIT */
|
---|
180 | #ifndef TCPV40HDRS
|
---|
181 | #define C_HS 4 /* for Hesiod name server at MIT */
|
---|
182 | #endif
|
---|
183 | /* Query class values which do not appear in resource records */
|
---|
184 | #define C_ANY 255 /* wildcard match */
|
---|
185 |
|
---|
186 | /*
|
---|
187 | * Flags field of the KEY RR rdata
|
---|
188 | */
|
---|
189 | #define KEYFLAG_TYPEMASK 0xC000 /* Mask for "type" bits */
|
---|
190 | #define KEYFLAG_TYPE_AUTH_CONF 0x0000 /* Key usable for both */
|
---|
191 | #define KEYFLAG_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */
|
---|
192 | #define KEYFLAG_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */
|
---|
193 | #define KEYFLAG_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */
|
---|
194 | /* The type bits can also be interpreted independently, as single bits: */
|
---|
195 | #define KEYFLAG_NO_AUTH 0x8000 /* Key not usable for authentication */
|
---|
196 | #define KEYFLAG_NO_CONF 0x4000 /* Key not usable for confidentiality */
|
---|
197 |
|
---|
198 | #define KEYFLAG_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */
|
---|
199 | #define KEYFLAG_RESERVED3 0x1000 /* reserved - must be zero */
|
---|
200 | #define KEYFLAG_RESERVED4 0x0800 /* reserved - must be zero */
|
---|
201 | #define KEYFLAG_USERACCOUNT 0x0400 /* key is assoc. with a user acct */
|
---|
202 | #define KEYFLAG_ENTITY 0x0200 /* key is assoc. with entity eg host */
|
---|
203 | #define KEYFLAG_ZONEKEY 0x0100 /* key is zone key for the zone named */
|
---|
204 | #define KEYFLAG_IPSEC 0x0080 /* key is for IPSEC use (host or user)*/
|
---|
205 | #define KEYFLAG_EMAIL 0x0040 /* key is for email (MIME security) */
|
---|
206 | #define KEYFLAG_RESERVED10 0x0020 /* reserved - must be zero */
|
---|
207 | #define KEYFLAG_RESERVED11 0x0010 /* reserved - must be zero */
|
---|
208 | #define KEYFLAG_SIGNATORYMASK 0x000F /* key can sign DNS RR's of same name */
|
---|
209 |
|
---|
210 | #define KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
|
---|
211 | KEYFLAG_RESERVED4 | \
|
---|
212 | KEYFLAG_RESERVED10| KEYFLAG_RESERVED11)
|
---|
213 |
|
---|
214 | /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
|
---|
215 | #define ALGORITHM_MD5RSA 1 /* MD5 with RSA */
|
---|
216 | #define ALGORITHM_EXPIRE_ONLY 253 /* No alg, no security */
|
---|
217 | #define ALGORITHM_PRIVATE_OID 254 /* Key begins with OID indicating alg */
|
---|
218 |
|
---|
219 | /* Signatures */
|
---|
220 | /* Size of a mod or exp in bits */
|
---|
221 | #define MIN_MD5RSA_KEY_PART_BITS 512
|
---|
222 | #define MAX_MD5RSA_KEY_PART_BITS 2552
|
---|
223 | /* Total of binary mod and exp, bytes */
|
---|
224 | #define MAX_MD5RSA_KEY_BYTES ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
|
---|
225 | /* Max length of text sig block */
|
---|
226 | #define MAX_KEY_BASE64 (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
|
---|
227 |
|
---|
228 | #ifndef TCPV40HDRS
|
---|
229 | /*
|
---|
230 | * Status return codes for T_UNSPEC conversion routines
|
---|
231 | */
|
---|
232 | #define CONV_SUCCESS 0
|
---|
233 | #define CONV_OVERFLOW -1
|
---|
234 | #define CONV_BADFMT -2
|
---|
235 | #define CONV_BADCKSUM -3
|
---|
236 | #define CONV_BADBUFLEN -4
|
---|
237 | #endif
|
---|
238 |
|
---|
239 | /*
|
---|
240 | * Structure for query header, the order of the fields is machine and
|
---|
241 | * compiler dependent, in our case, the bits within a byte are assignd
|
---|
242 | * least significant first, while the order of transmition is most
|
---|
243 | * significant first. This requires a somewhat confusing rearrangement.
|
---|
244 | */
|
---|
245 | #ifndef TCPV40HDRS
|
---|
246 | #pragma pack(1)
|
---|
247 | #endif
|
---|
248 | typedef struct {
|
---|
249 | u_short id; /* query identification number */
|
---|
250 | #if BYTE_ORDER == BIG_ENDIAN
|
---|
251 | /* fields in third byte */
|
---|
252 | u_char qr:1; /* response flag */
|
---|
253 | u_char opcode:4; /* purpose of message */
|
---|
254 | u_char aa:1; /* authoritive answer */
|
---|
255 | u_char tc:1; /* truncated message */
|
---|
256 | u_char rd:1; /* recursion desired */
|
---|
257 | /* fields in fourth byte */
|
---|
258 | u_char ra:1; /* recursion available */
|
---|
259 | #ifdef TCPV40HDRS
|
---|
260 | u_char pr:1; /* primary server required (non standard) */
|
---|
261 | u_char unused:2; /* unused bits */
|
---|
262 | #else
|
---|
263 | u_char unused :1; /* unused bits (MBZ as of 4.9.3a3) */
|
---|
264 | u_char ad: 1; /* authentic data from named */
|
---|
265 | u_char cd: 1; /* checking disabled by resolver */
|
---|
266 | #endif
|
---|
267 | u_char rcode:4; /* response code */
|
---|
268 | #endif
|
---|
269 | #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
|
---|
270 | /* fields in third byte */
|
---|
271 | u_char rd:1; /* recursion desired */
|
---|
272 | u_char tc:1; /* truncated message */
|
---|
273 | u_char aa:1; /* authoritive answer */
|
---|
274 | u_char opcode:4; /* purpose of message */
|
---|
275 | u_char qr:1; /* response flag */
|
---|
276 | /* fields in fourth byte */
|
---|
277 | u_char rcode:4; /* response code */
|
---|
278 | #ifdef TCPV40HDRS
|
---|
279 | u_char unused:2; /* unused bits */
|
---|
280 | u_char pr:1; /* primary server required (non standard) */
|
---|
281 | #else
|
---|
282 | u_char cd: 1; /* checking disabled by resolver */
|
---|
283 | u_char ad: 1; /* authentic data from named */
|
---|
284 | u_char unused :1; /* unused bits (MBZ as of 4.9.3a3) */
|
---|
285 | #endif
|
---|
286 | u_char ra:1; /* recursion available */
|
---|
287 | #endif
|
---|
288 | /* remaining bytes */
|
---|
289 | u_short qdcount; /* number of question entries */
|
---|
290 | u_short ancount; /* number of answer entries */
|
---|
291 | u_short nscount; /* number of authority entries */
|
---|
292 | u_short arcount; /* number of resource entries */
|
---|
293 | } HEADER;
|
---|
294 | #ifndef TCPV40HDRS
|
---|
295 | #pragma pack()
|
---|
296 | #endif
|
---|
297 |
|
---|
298 | /*
|
---|
299 | * Defines for handling compressed domain names
|
---|
300 | */
|
---|
301 | #define INDIR_MASK 0xc0
|
---|
302 |
|
---|
303 | #ifdef TCPV40HDRS
|
---|
304 | /*
|
---|
305 | * Structure for passing resource records around.
|
---|
306 | */
|
---|
307 | #pragma pack(4)
|
---|
308 | struct rrec {
|
---|
309 | short r_zone; /* zone number */
|
---|
310 | short r_class; /* class number */
|
---|
311 | short r_type; /* type number */
|
---|
312 | u_long r_ttl; /* time to live */
|
---|
313 | int r_size; /* size of data area */
|
---|
314 | char *r_data; /* pointer to data */
|
---|
315 | };
|
---|
316 | #pragma pack()
|
---|
317 | #endif
|
---|
318 |
|
---|
319 | #ifndef TCPV40HDRS
|
---|
320 | /*
|
---|
321 | * Inline versions of get/put short/long. Pointer is advanced.
|
---|
322 | *
|
---|
323 | * These macros demonstrate the property of C whereby it can be
|
---|
324 | * portable or it can be elegant but rarely both.
|
---|
325 | */
|
---|
326 | #define GETSHORT(s, cp) { \
|
---|
327 | register u_char *t_cp = (u_char *)(cp); \
|
---|
328 | (s) = ((u_int16_t)t_cp[0] << 8) \
|
---|
329 | | ((u_int16_t)t_cp[1]) \
|
---|
330 | ; \
|
---|
331 | (cp) += INT16SZ; \
|
---|
332 | }
|
---|
333 |
|
---|
334 | #define GETLONG(l, cp) { \
|
---|
335 | register u_char *t_cp = (u_char *)(cp); \
|
---|
336 | (l) = ((u_int32_t)t_cp[0] << 24) \
|
---|
337 | | ((u_int32_t)t_cp[1] << 16) \
|
---|
338 | | ((u_int32_t)t_cp[2] << 8) \
|
---|
339 | | ((u_int32_t)t_cp[3]) \
|
---|
340 | ; \
|
---|
341 | (cp) += INT32SZ; \
|
---|
342 | }
|
---|
343 |
|
---|
344 | #define PUTSHORT(s, cp) { \
|
---|
345 | register u_int16_t t_s = (u_int16_t)(s); \
|
---|
346 | register u_char *t_cp = (u_char *)(cp); \
|
---|
347 | *t_cp++ = t_s >> 8; \
|
---|
348 | *t_cp = t_s; \
|
---|
349 | (cp) += INT16SZ; \
|
---|
350 | }
|
---|
351 |
|
---|
352 | #define PUTLONG(l, cp) { \
|
---|
353 | register u_int32_t t_l = (u_int32_t)(l); \
|
---|
354 | register u_char *t_cp = (u_char *)(cp); \
|
---|
355 | *t_cp++ = t_l >> 24; \
|
---|
356 | *t_cp++ = t_l >> 16; \
|
---|
357 | *t_cp++ = t_l >> 8; \
|
---|
358 | *t_cp = t_l; \
|
---|
359 | (cp) += INT32SZ; \
|
---|
360 | }
|
---|
361 | #endif /*!TCPV40HDRS*/
|
---|
362 |
|
---|
363 |
|
---|
364 | /* function prototypes */
|
---|
365 | u_short TCPCALL _getshort(u_char*);
|
---|
366 | u_long TCPCALL _getlong(u_char*);
|
---|
367 | #ifdef TCPV40HDRS /* newer have this in resolver */
|
---|
368 | void TCPCALL putshort(u_short, u_char *);
|
---|
369 | void TCPCALL putlong(u_long, u_char *);
|
---|
370 | int TCPCALL dn_expand(const u_char*, const u_char*, const u_char*, u_char*, int);
|
---|
371 | int TCPCALL dn_comp(const u_char*, u_char*, int, u_char**, u_char**);
|
---|
372 | int TCPCALL dn_find(u_char*, u_char*, u_char**, u_char**);
|
---|
373 | int TCPCALL dn_skipname(const u_char*, const u_char*);
|
---|
374 | int TCPCALL res_init(void);
|
---|
375 | int TCPCALL res_mkquery(int, const char*, int, int, const char*, int, const struct rrec*, char*, int);
|
---|
376 | int TCPCALL res_send(const char*, int, char*, int);
|
---|
377 | int TCPCALL res_query(char*, int, int, u_char*, int);
|
---|
378 | int TCPCALL res_search(char*, int, int, u_char*, int);
|
---|
379 | int TCPCALL res_querydomain(char*, char*, int, int, u_char*, int);
|
---|
380 | #endif
|
---|
381 |
|
---|
382 | #if defined (__cplusplus)
|
---|
383 | }
|
---|
384 | #endif
|
---|
385 |
|
---|
386 | #endif /* !_NAMESER_H_ */
|
---|