2 * Copyright (c) 1983, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
32 * Copyright (c) 1996-1999 by Internet Software Consortium.
34 * Permission to use, copy, modify, and distribute this software for any
35 * purpose with or without fee is hereby granted, provided that the above
36 * copyright notice and this permission notice appear in all copies.
38 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
39 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
41 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
42 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
43 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
44 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48 #ifndef _ARPA_NAMESER_H_
49 #define _ARPA_NAMESER_H_
51 #include <sys/param.h>
52 #include <sys/types.h>
56 # define __NAMESER_DEPRECATED
58 # define __NAMESER_DEPRECATED __attribute_deprecated__
62 * Define constants based on RFC 883, RFC 1034, RFC 1035
64 #define NS_PACKETSZ 512 /*%< default UDP packet size */
65 #define NS_MAXDNAME 1025 /*%< maximum domain name */
66 #define NS_MAXMSG 65535 /*%< maximum message size */
67 #define NS_MAXCDNAME 255 /*%< maximum compressed domain name */
68 #define NS_MAXLABEL 63 /*%< maximum length of domain label */
69 #define NS_HFIXEDSZ 12 /*%< #/bytes of fixed data in header */
70 #define NS_QFIXEDSZ 4 /*%< #/bytes of fixed data in query */
71 #define NS_RRFIXEDSZ 10 /*%< #/bytes of fixed data in r record */
72 #define NS_INT32SZ 4 /*%< #/bytes of data in a uint32_t */
73 #define NS_INT16SZ 2 /*%< #/bytes of data in a uint16_t */
74 #define NS_INT8SZ 1 /*%< #/bytes of data in a uint8_t */
75 #define NS_INADDRSZ 4 /*%< IPv4 T_A */
76 #define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */
77 #define NS_CMPRSFLGS 0xc0 /*%< Flag bits indicating name compression. */
78 #define NS_DEFAULTPORT 53 /*%< For both TCP and UDP. */
80 * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
83 typedef enum __ns_sect
{
84 ns_s_qd
= 0, /*%< Query: Question. */
85 ns_s_zn
= 0, /*%< Update: Zone. */
86 ns_s_an
= 1, /*%< Query: Answer. */
87 ns_s_pr
= 1, /*%< Update: Prerequisites. */
88 ns_s_ns
= 2, /*%< Query: Name servers. */
89 ns_s_ud
= 2, /*%< Update: Update. */
90 ns_s_ar
= 3, /*%< Query|Update: Additional records. */
95 * This is a message handle. It is caller allocated and has no dynamic data.
96 * This structure is intended to be opaque to all but ns_parse.c, thus the
97 * leading _'s on the member names. Use the accessor functions, not the _'s.
99 typedef struct __ns_msg
{
100 const unsigned char *_msg
, *_eom
;
101 uint16_t _id
, _flags
, _counts
[ns_s_max
];
102 const unsigned char *_sections
[ns_s_max
];
105 const unsigned char *_msg_ptr
;
108 /* Private data structure - do not use from outside library. */
109 struct _ns_flagdata
{ int mask
, shift
; };
110 extern const struct _ns_flagdata _ns_flagdata
[];
112 /* Accessor macros - this is part of the public interface. */
114 #define ns_msg_id(handle) ((handle)._id + 0)
115 #define ns_msg_base(handle) ((handle)._msg + 0)
116 #define ns_msg_end(handle) ((handle)._eom + 0)
117 #define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
118 #define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
121 * This is a parsed record. It is caller allocated and has no dynamic data.
123 typedef struct __ns_rr
{
124 char name
[NS_MAXDNAME
];
129 const unsigned char * rdata
;
132 /* Accessor macros - this is part of the public interface. */
133 #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
134 #define ns_rr_type(rr) ((ns_type)((rr).type + 0))
135 #define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0))
136 #define ns_rr_ttl(rr) ((rr).ttl + 0)
137 #define ns_rr_rdlen(rr) ((rr).rdlength + 0)
138 #define ns_rr_rdata(rr) ((rr).rdata + 0)
141 * These don't have to be in the same order as in the packet flags word,
142 * and they can even overlap in some cases, but they will need to be kept
143 * in synch with ns_parse.c:ns_flagdata[].
145 typedef enum __ns_flag
{
146 ns_f_qr
, /*%< Question/Response. */
147 ns_f_opcode
, /*%< Operation code. */
148 ns_f_aa
, /*%< Authoritative Answer. */
149 ns_f_tc
, /*%< Truncation occurred. */
150 ns_f_rd
, /*%< Recursion Desired. */
151 ns_f_ra
, /*%< Recursion Available. */
153 ns_f_ad
, /*%< Authentic Data (DNSSEC). */
154 ns_f_cd
, /*%< Checking Disabled (DNSSEC). */
155 ns_f_rcode
, /*%< Response code. */
160 * Currently defined opcodes.
162 typedef enum __ns_opcode
{
163 ns_o_query
= 0, /*%< Standard query. */
164 ns_o_iquery
= 1, /*%< Inverse query (deprecated/unsupported). */
165 ns_o_status
= 2, /*%< Name server status query (unsupported). */
166 /* Opcode 3 is undefined/reserved. */
167 ns_o_notify
= 4, /*%< Zone change notification. */
168 ns_o_update
= 5, /*%< Zone update message. */
173 * Currently defined response codes.
175 typedef enum __ns_rcode
{
176 ns_r_noerror
= 0, /*%< No error occurred. */
177 ns_r_formerr
= 1, /*%< Format error. */
178 ns_r_servfail
= 2, /*%< Server failure. */
179 ns_r_nxdomain
= 3, /*%< Name error. */
180 ns_r_notimpl
= 4, /*%< Unimplemented. */
181 ns_r_refused
= 5, /*%< Operation refused. */
182 /* these are for BIND_UPDATE */
183 ns_r_yxdomain
= 6, /*%< Name exists */
184 ns_r_yxrrset
= 7, /*%< RRset exists */
185 ns_r_nxrrset
= 8, /*%< RRset does not exist */
186 ns_r_notauth
= 9, /*%< Not authoritative for zone */
187 ns_r_notzone
= 10, /*%< Zone of record different from zone section */
189 /* The following are EDNS extended rcodes */
191 /* The following are TSIG errors */
198 typedef enum __ns_update_operation
{
202 } ns_update_operation
;
205 * This structure is used for TSIG authenticated messages
208 char name
[NS_MAXDNAME
], alg
[NS_MAXDNAME
];
212 typedef struct ns_tsig_key ns_tsig_key
;
215 * This structure is used for TSIG authenticated TCP messages
217 struct ns_tcp_tsig_state
{
221 unsigned char sig
[NS_PACKETSZ
];
224 typedef struct ns_tcp_tsig_state ns_tcp_tsig_state
;
226 #define NS_TSIG_FUDGE 300
227 #define NS_TSIG_TCP_COUNT 100
228 #define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
230 #define NS_TSIG_ERROR_NO_TSIG -10
231 #define NS_TSIG_ERROR_NO_SPACE -11
232 #define NS_TSIG_ERROR_FORMERR -12
235 * Currently defined type values for resources and queries.
237 typedef enum __ns_type
291 ns_t_nsec3param
= 51,
300 ns_t_openpgpkey
= 61,
330 * Values for class field
332 typedef enum __ns_class
{
333 ns_c_invalid
= 0, /*%< Cookie. */
334 ns_c_in
= 1, /*%< Internet. */
335 ns_c_2
= 2, /*%< unallocated/unsupported. */
336 ns_c_chaos
= 3, /*%< MIT Chaos-net. */
337 ns_c_hs
= 4, /*%< MIT Hesiod. */
338 /* Query class values which do not appear in resource records */
339 ns_c_none
= 254, /*%< for prereq. sections in update requests */
340 ns_c_any
= 255, /*%< Wildcard match. */
344 /* Certificate type values in CERT resource records. */
345 typedef enum __ns_cert_types
{
346 cert_t_pkix
= 1, /*%< PKIX (X.509v3) */
347 cert_t_spki
= 2, /*%< SPKI */
348 cert_t_pgp
= 3, /*%< PGP */
349 cert_t_url
= 253, /*%< URL private type */
350 cert_t_oid
= 254 /*%< OID private type */
354 * EDNS0 extended flags and option codes, host order.
356 #define NS_OPT_DNSSEC_OK 0x8000U
357 #define NS_OPT_NSID 3
360 * Inline versions of get/put short/long. Pointer is advanced.
362 #define NS_GET16(s, cp) do { \
363 const unsigned char *t_cp = (const unsigned char *)(cp); \
364 (s) = ((uint16_t)t_cp[0] << 8) \
365 | ((uint16_t)t_cp[1]) \
367 (cp) += NS_INT16SZ; \
370 #define NS_GET32(l, cp) do { \
371 const unsigned char *t_cp = (const unsigned char *)(cp); \
372 (l) = ((uint32_t)t_cp[0] << 24) \
373 | ((uint32_t)t_cp[1] << 16) \
374 | ((uint32_t)t_cp[2] << 8) \
375 | ((uint32_t)t_cp[3]) \
377 (cp) += NS_INT32SZ; \
380 #define NS_PUT16(s, cp) do { \
381 uint16_t t_s = (uint16_t)(s); \
382 unsigned char *t_cp = (unsigned char *)(cp); \
383 *t_cp++ = t_s >> 8; \
385 (cp) += NS_INT16SZ; \
388 #define NS_PUT32(l, cp) do { \
389 uint32_t t_l = (uint32_t)(l); \
390 unsigned char *t_cp = (unsigned char *)(cp); \
391 *t_cp++ = t_l >> 24; \
392 *t_cp++ = t_l >> 16; \
393 *t_cp++ = t_l >> 8; \
395 (cp) += NS_INT32SZ; \
399 int ns_msg_getflag (ns_msg
, int) __THROW
;
400 unsigned int ns_get16 (const unsigned char *) __THROW
;
401 unsigned long ns_get32 (const unsigned char *) __THROW
;
402 void ns_put16 (unsigned int, unsigned char *) __THROW
;
403 void ns_put32 (unsigned long, unsigned char *) __THROW
;
404 int ns_initparse (const unsigned char *, int, ns_msg
*) __THROW
;
405 int ns_skiprr (const unsigned char *, const unsigned char *,
406 ns_sect
, int) __THROW
;
407 int ns_parserr (ns_msg
*, ns_sect
, int, ns_rr
*) __THROW
;
408 int ns_sprintrr (const ns_msg
*, const ns_rr
*,
409 const char *, const char *, char *, size_t)
410 __THROW __NAMESER_DEPRECATED
;
411 int ns_sprintrrf (const unsigned char *, size_t, const char *,
412 ns_class
, ns_type
, unsigned long,
413 const unsigned char *, size_t, const char *,
414 const char *, char *, size_t)
415 __THROW __NAMESER_DEPRECATED
;
416 int ns_format_ttl (unsigned long, char *, size_t)
417 __THROW __NAMESER_DEPRECATED
;
418 int ns_parse_ttl (const char *, unsigned long *)
419 __THROW __NAMESER_DEPRECATED
;
420 uint32_t ns_datetosecs (const char *, int *)
421 __THROW __NAMESER_DEPRECATED
;
422 int ns_name_ntol (const unsigned char *, unsigned char *, size_t)
424 int ns_name_ntop (const unsigned char *, char *, size_t) __THROW
;
425 int ns_name_pton (const char *, unsigned char *, size_t) __THROW
;
426 int ns_name_unpack (const unsigned char *, const unsigned char *,
427 const unsigned char *, unsigned char *, size_t)
429 int ns_name_pack (const unsigned char *, unsigned char *, int,
430 const unsigned char **, const unsigned char **)
432 int ns_name_uncompress (const unsigned char *,
433 const unsigned char *,
434 const unsigned char *,
435 char *, size_t) __THROW
;
436 int ns_name_compress (const char *, unsigned char *, size_t,
437 const unsigned char **,
438 const unsigned char **) __THROW
;
439 int ns_name_skip (const unsigned char **, const unsigned char *)
441 void ns_name_rollback (const unsigned char *,
442 const unsigned char **,
443 const unsigned char **) __THROW
;
445 int ns_samedomain (const char *, const char *) __THROW
446 __NAMESER_DEPRECATED
;
447 int ns_subdomain (const char *, const char *) __THROW
448 __NAMESER_DEPRECATED
;
449 int ns_makecanon (const char *, char *, size_t) __THROW
450 __NAMESER_DEPRECATED
;
451 int ns_samename (const char *, const char *) __THROW
452 __NAMESER_DEPRECATED
;
455 #include <arpa/nameser_compat.h>
457 #endif /* !_ARPA_NAMESER_H_ */