nameser.h revision 10132
1192886Sedwin/* 2192886Sedwin * Copyright (c) 1983, 1989, 1993 367578Swollman * The Regents of the University of California. All rights reserved. 4273719Sedwin * 52742Swollman * Redistribution and use in source and binary forms, with or without 6273719Sedwin * modification, are permitted provided that the following conditions 7273719Sedwin * are met: 82742Swollman * 1. Redistributions of source code must retain the above copyright 9274563Sedwin * notice, this list of conditions and the following disclaimer. 102742Swollman * 2. Redistributions in binary form must reproduce the above copyright 11274563Sedwin * notice, this list of conditions and the following disclaimer in the 12158421Swollman * documentation and/or other materials provided with the distribution. 13158421Swollman * 3. All advertising materials mentioning features or use of this software 14274563Sedwin * must display the following acknowledgement: 152742Swollman * This product includes software developed by the University of 1686222Swollman * California, Berkeley and its contributors. 1720094Swollman * 4. Neither the name of the University nor the names of its contributors 1820094Swollman * may be used to endorse or promote products derived from this software 1920094Swollman * without specific prior written permission. 20274563Sedwin * 21274563Sedwin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2220094Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 232742Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 242742Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 252742Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 262742Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27248307Sedwin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28273719Sedwin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29273719Sedwin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30248307Sedwin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3114343Swollman * SUCH DAMAGE. 3258787Sru * 3314343Swollman * - 3430711Swollman * Portions Copyright (c) 1993 by Digital Equipment Corporation. 3530711Swollman * 36149514Swollman * Permission to use, copy, modify, and distribute this software for any 37270817Spluknet * purpose with or without fee is hereby granted, provided that the above 38270817Spluknet * copyright notice and this permission notice appear in all copies, and that 39270817Spluknet * the name of Digital Equipment Corporation not be used in advertising or 40270817Spluknet * publicity pertaining to distribution of the document or software without 41270817Spluknet * specific, written prior permission. 422742Swollman * 43270817Spluknet * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 4430711Swollman * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 4530711Swollman * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 4630711Swollman * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 4730711Swollman * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 482742Swollman * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 4930711Swollman * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 5030711Swollman * SOFTWARE. 5130711Swollman * - 5230711Swollman * --Copyright-- 5330711Swollman * 5430711Swollman * @(#)nameser.h 8.2 (Berkeley) 2/16/94 5530711Swollman * From Id: nameser.h,v 4.9.1.15 1994/07/19 22:51:24 vixie Exp 56270817Spluknet */ 5730711Swollman 5830711Swollman#ifndef _ARPA_NAMESER_H_ 592742Swollman#define _ARPA_NAMESER_H_ 6030711Swollman 6130711Swollman#include <sys/param.h> 6230711Swollman#include <sys/types.h> 63226289Sedwin#include <sys/cdefs.h> 6430711Swollman#include <machine/endian.h> 6530711Swollman 662742Swollman 672742Swollman/* 682742Swollman * revision information. this is the release date in YYYYMMDD format. 692742Swollman * it can change every day so the right thing to do with it is use it 7019878Swollman * in preprocessor commands such as "#if (__BIND > 19931104)". do not 71158421Swollman * compare for equality; rather, use it to determine whether your resolver 7219878Swollman * is new enough to contain a certain feature. 7319878Swollman */ 7419878Swollman 7519878Swollman#define __BIND 19950621 /* interface version stamp */ 762742Swollman 7719878Swollman/* 782742Swollman * Define constants based on rfc883 7919878Swollman */ 802742Swollman#define PACKETSZ 512 /* maximum packet size */ 81158421Swollman#define MAXDNAME 256 /* maximum domain name */ 822742Swollman#define MAXCDNAME 255 /* maximum compressed domain name */ 832742Swollman#define MAXLABEL 63 /* maximum length of domain label */ 8419878Swollman#define HFIXEDSZ 12 /* #/bytes of fixed data in header */ 852742Swollman#define QFIXEDSZ 4 /* #/bytes of fixed data in query */ 8619878Swollman#define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ 872742Swollman#define INT32SZ 4 /* for systems without 32-bit ints */ 8819878Swollman#define INT16SZ 2 /* for systems without 16-bit ints */ 892742Swollman#define INADDRSZ 4 /* for sizeof(struct inaddr) != 4 */ 9019878Swollman 912742Swollman/* 92158421Swollman * Internet nameserver port number 93158421Swollman */ 942742Swollman#define NAMESERVER_PORT 53 95273719Sedwin 96273719Sedwin/* 97273719Sedwin * Currently defined opcodes 9819878Swollman */ 992742Swollman#define QUERY 0x0 /* standard query */ 10019878Swollman#define IQUERY 0x1 /* inverse query */ 10119878Swollman#define STATUS 0x2 /* nameserver status query */ 10219878Swollman/*#define xxx 0x3 */ /* 0x3 reserved */ 10319878Swollman#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */ 10419878Swollman#ifdef ALLOW_UPDATES 1052742Swollman /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */ 1062742Swollman# define UPDATEA 0x9 /* add resource record */ 1072742Swollman# define UPDATED 0xa /* delete a specific resource record */ 108273719Sedwin# define UPDATEDA 0xb /* delete all named resource record */ 1092742Swollman# define UPDATEM 0xc /* modify a specific resource record */ 1102742Swollman# define UPDATEMA 0xd /* modify all named resource record */ 111273719Sedwin# define ZONEINIT 0xe /* initial zone transfer */ 1122742Swollman# define ZONEREF 0xf /* incremental zone referesh */ 1132742Swollman#endif 114270817Spluknet 1152742Swollman/* 1162742Swollman * Currently defined response codes 117273719Sedwin */ 1182742Swollman#define NOERROR 0 /* no error */ 1192742Swollman#define FORMERR 1 /* format error */ 120273719Sedwin#define SERVFAIL 2 /* server failure */ 1212742Swollman#define NXDOMAIN 3 /* non existent domain */ 1222742Swollman#define NOTIMP 4 /* not implemented */ 123273719Sedwin#define REFUSED 5 /* query refused */ 124273719Sedwin#ifdef ALLOW_UPDATES 125273719Sedwin /* non standard */ 126273719Sedwin# define NOCHANGE 0xf /* update failed to change db */ 127273719Sedwin#endif 128273719Sedwin 1292742Swollman/* 130273719Sedwin * Type values for resources and queries 1312742Swollman */ 1322742Swollman#define T_A 1 /* host address */ 133273719Sedwin#define T_NS 2 /* authoritative server */ 13419878Swollman#define T_MD 3 /* mail destination */ 1352742Swollman#define T_MF 4 /* mail forwarder */ 1362742Swollman#define T_CNAME 5 /* canonical name */ 137273719Sedwin#define T_SOA 6 /* start of authority zone */ 1382742Swollman#define T_MB 7 /* mailbox domain name */ 1392742Swollman#define T_MG 8 /* mail group member */ 1402742Swollman#define T_MR 9 /* mail rename name */ 141273719Sedwin#define T_NULL 10 /* null resource record */ 14230711Swollman#define T_WKS 11 /* well known service */ 14330711Swollman#define T_PTR 12 /* domain name pointer */ 14430711Swollman#define T_HINFO 13 /* host information */ 1452742Swollman#define T_MINFO 14 /* mailbox information */ 1462742Swollman#define T_MX 15 /* mail routing information */ 147274563Sedwin#define T_TXT 16 /* text strings */ 1482742Swollman#define T_RP 17 /* responsible person */ 149273719Sedwin#define T_AFSDB 18 /* AFS cell database */ 150273719Sedwin#define T_X25 19 /* X_25 calling address */ 15130711Swollman#define T_ISDN 20 /* ISDN calling address */ 15230711Swollman#define T_RT 21 /* router */ 153273719Sedwin#define T_NSAP 22 /* NSAP address */ 1542742Swollman#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ 155273719Sedwin#define T_SIG 24 /* security signature */ 1562742Swollman#define T_KEY 25 /* security key */ 1572742Swollman#define T_PX 26 /* X.400 mail mapping */ 15830711Swollman#define T_GPOS 27 /* geographical position (withdrawn) */ 159270817Spluknet#define T_AAAA 28 /* IP6 Address */ 160270817Spluknet#define T_LOC 29 /* Location Information */ 161270817Spluknet /* non standard */ 162270817Spluknet#define T_UINFO 100 /* user (finger) information */ 163270817Spluknet#define T_UID 101 /* user ID */ 164270817Spluknet#define T_GID 102 /* group ID */ 165270817Spluknet#define T_UNSPEC 103 /* Unspecified format (binary data) */ 166270817Spluknet /* Query type values which do not appear in resource records */ 167270817Spluknet#define T_AXFR 252 /* transfer zone of authority */ 168270817Spluknet#define T_MAILB 253 /* transfer mailbox records */ 1692742Swollman#define T_MAILA 254 /* transfer mail agent records */ 1702742Swollman#define T_ANY 255 /* wildcard match */ 171274563Sedwin 1722742Swollman/* 1732742Swollman * Values for class field 1742742Swollman */ 1752742Swollman 1762742Swollman#define C_IN 1 /* the arpa internet */ 177248307Sedwin#define C_CHAOS 3 /* for chaos net (MIT) */ 178248307Sedwin#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ 179248307Sedwin /* Query class values which do not appear in resource records */ 180248307Sedwin#define C_ANY 255 /* wildcard match */ 181248307Sedwin 1822742Swollman/* 18319878Swollman * Status return codes for T_UNSPEC conversion routines 1842742Swollman */ 18519878Swollman#define CONV_SUCCESS 0 1862742Swollman#define CONV_OVERFLOW (-1) 18719878Swollman#define CONV_BADFMT (-2) 1882742Swollman#define CONV_BADCKSUM (-3) 1892742Swollman#define CONV_BADBUFLEN (-4) 19019878Swollman 19119878Swollman/* 1922742Swollman * Structure for query header. The order of the fields is machine- and 19319878Swollman * compiler-dependent, depending on the byte/bit order and the layout 19419878Swollman * of bit fields. We use bit fields only in int variables, as this 1952742Swollman * is all ANSI requires. This requires a somewhat confusing rearrangement. 19630711Swollman */ 19719878Swollman 19819878Swollmantypedef struct { 19919878Swollman unsigned id :16; /* query identification number */ 20019878Swollman#if BYTE_ORDER == BIG_ENDIAN 20130711Swollman /* fields in third byte */ 20243014Swollman unsigned qr: 1; /* response flag */ 20343543Swollman unsigned opcode: 4; /* purpose of message */ 204221092Sedwin unsigned aa: 1; /* authoritive answer */ 205221092Sedwin unsigned tc: 1; /* truncated message */ 206221092Sedwin unsigned rd: 1; /* recursion desired */ 207221092Sedwin /* fields in fourth byte */ 208221092Sedwin unsigned ra: 1; /* recursion available */ 209221092Sedwin unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */ 210221092Sedwin unsigned rcode :4; /* response code */ 211221092Sedwin#endif 212221092Sedwin#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN 213221092Sedwin /* fields in third byte */ 214221092Sedwin unsigned rd :1; /* recursion desired */ 215267477Sedwin unsigned tc :1; /* truncated message */ 216163302Sru unsigned aa :1; /* authoritive answer */ 217163302Sru unsigned opcode :4; /* purpose of message */ 218163302Sru unsigned qr :1; /* response flag */ 219163302Sru /* fields in fourth byte */ 220163302Sru unsigned rcode :4; /* response code */ 221267477Sedwin unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */ 222171948Sedwin unsigned ra :1; /* recursion available */ 223171948Sedwin#endif 224171948Sedwin /* remaining bytes */ 225270817Spluknet unsigned qdcount :16; /* number of question entries */ 226240457Sedwin unsigned ancount :16; /* number of answer entries */ 227171948Sedwin unsigned nscount :16; /* number of authority entries */ 228172479Sedwin unsigned arcount :16; /* number of resource entries */ 229172479Sedwin} HEADER; 230267477Sedwin 231172479Sedwin/* 232172479Sedwin * Defines for handling compressed domain names 233172479Sedwin */ 234172479Sedwin#define INDIR_MASK 0xc0 235172479Sedwin 236172479Sedwin/* 237172479Sedwin * Structure for passing resource records around. 238171948Sedwin */ 239172479Sedwinstruct rrec { 24020094Swollman int16_t r_zone; /* zone number */ 241191618Sedwin int16_t r_class; /* class number */ 242191618Sedwin int16_t r_type; /* type number */ 243191618Sedwin u_int32_t r_ttl; /* time to live */ 244191618Sedwin int r_size; /* size of data area */ 245192886Sedwin char *r_data; /* pointer to data */ 246191618Sedwin}; 247192886Sedwin 248192886Sedwinextern u_int16_t _getshort __P((const u_char *)); 249191618Sedwinextern u_int32_t _getlong __P((const u_char *)); 250192886Sedwin 251192886Sedwin/* 252191618Sedwin * Inline versions of get/put short/long. Pointer is advanced. 253192886Sedwin * 254192886Sedwin * These macros demonstrate the property of C whereby it can be 255191618Sedwin * portable or it can be elegant but rarely both. 256192886Sedwin */ 257191618Sedwin#define GETSHORT(s, cp) { \ 258191618Sedwin register u_char *t_cp = (u_char *)(cp); \ 259191618Sedwin (s) = ((u_int16_t)t_cp[0] << 8) \ 260191618Sedwin | ((u_int16_t)t_cp[1]) \ 261191618Sedwin ; \ 262191618Sedwin (cp) += INT16SZ; \ 263191618Sedwin} 264270817Spluknet 265270817Spluknet#define GETLONG(l, cp) { \ 266270817Spluknet register u_char *t_cp = (u_char *)(cp); \ 267191618Sedwin (l) = ((u_int32_t)t_cp[0] << 24) \ 268191618Sedwin | ((u_int32_t)t_cp[1] << 16) \ 269191618Sedwin | ((u_int32_t)t_cp[2] << 8) \ 270191618Sedwin | ((u_int32_t)t_cp[3]) \ 271191618Sedwin ; \ 272196582Sedwin (cp) += INT32SZ; \ 273196582Sedwin} 274240457Sedwin 275196582Sedwin#define PUTSHORT(s, cp) { \ 276196582Sedwin register u_int16_t t_s = (u_int16_t)(s); \ 277240457Sedwin register u_char *t_cp = (u_char *)(cp); \ 278196582Sedwin *t_cp++ = t_s >> 8; \ 279196582Sedwin *t_cp = t_s; \ 280196582Sedwin (cp) += INT16SZ; \ 281240457Sedwin} 282196582Sedwin 283196582Sedwin#define PUTLONG(l, cp) { \ 284196582Sedwin register u_int32_t t_l = (u_int32_t)(l); \ 285196582Sedwin register u_char *t_cp = (u_char *)(cp); \ 286210718Sedwin *t_cp++ = t_l >> 24; \ 287270817Spluknet *t_cp++ = t_l >> 16; \ 288210718Sedwin *t_cp++ = t_l >> 8; \ 289210718Sedwin *t_cp = t_l; \ 290210718Sedwin (cp) += INT32SZ; \ 291210718Sedwin} 292270817Spluknet 293210718Sedwin#endif /* !_ARPA_NAMESER_H_ */ 294210718Sedwin