1177162Sjkoshy/* 2145256Sjkoshy * ++Copyright++ 1983, 1989, 1993 3145256Sjkoshy * - 4145256Sjkoshy * Copyright (c) 1983, 1989, 1993 5145256Sjkoshy * The Regents of the University of California. All rights reserved. 6145256Sjkoshy * 7145256Sjkoshy * Redistribution and use in source and binary forms, with or without 8145256Sjkoshy * modification, are permitted provided that the following conditions 9145256Sjkoshy * are met: 10145256Sjkoshy * 1. Redistributions of source code must retain the above copyright 11145256Sjkoshy * notice, this list of conditions and the following disclaimer. 12231871Sbrueffer * 2. Redistributions in binary form must reproduce the above copyright 13231871Sbrueffer * notice, this list of conditions and the following disclaimer in the 14231871Sbrueffer * documentation and/or other materials provided with the distribution. 15231871Sbrueffer * 3. All advertising materials mentioning features or use of this software 16231871Sbrueffer * must display the following acknowledgement: 17231871Sbrueffer * This product includes software developed by the University of 18231871Sbrueffer * California, Berkeley and its contributors. 19231871Sbrueffer * 4. Neither the name of the University nor the names of its contributors 20231871Sbrueffer * may be used to endorse or promote products derived from this software 21231871Sbrueffer * without specific prior written permission. 22231871Sbrueffer * 23145256Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24145256Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25145256Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26183595Sjkoshy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27206622Suqs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28145256Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29145256Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30183084Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31183084Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32183084Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33183084Sjkoshy * SUCH DAMAGE. 34183084Sjkoshy * - 35145256Sjkoshy * Portions Copyright (c) 1993 by Digital Equipment Corporation. 36145256Sjkoshy * 37145256Sjkoshy * Permission to use, copy, modify, and distribute this software for any 38145256Sjkoshy * purpose with or without fee is hereby granted, provided that the above 39145256Sjkoshy * copyright notice and this permission notice appear in all copies, and that 40183084Sjkoshy * the name of Digital Equipment Corporation not be used in advertising or 41173900Sjkoshy * publicity pertaining to distribution of the document or software without 42145256Sjkoshy * specific, written prior permission. 43145256Sjkoshy * 44145256Sjkoshy * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 45145256Sjkoshy * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 46145256Sjkoshy * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 47147586Sru * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 48145256Sjkoshy * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 49183084Sjkoshy * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 50183084Sjkoshy * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 51183084Sjkoshy * SOFTWARE. 52183084Sjkoshy * - 53183084Sjkoshy * --Copyright-- 54183084Sjkoshy */ 55183084Sjkoshy 56183084Sjkoshy/* 57183084Sjkoshy * @(#)nameser.h 8.1 (Berkeley) 6/2/93 58183084Sjkoshy * nameser.h,v 1.2 1995/05/06 14:23:54 hjl Exp 59183084Sjkoshy */ 60183084Sjkoshy 61183084Sjkoshy#ifndef _NAMESER_H_ 62183084Sjkoshy#define _NAMESER_H_ 63183084Sjkoshy 64183084Sjkoshy#ifndef WIN32 65183084Sjkoshy#include <sys/param.h> 66183084Sjkoshy#if (!defined(BSD)) || (BSD < 199306) 67145256Sjkoshy# include <sys/bitypes.h> 68145256Sjkoshy#else 69145256Sjkoshy# include <sys/types.h> 70145256Sjkoshy#endif 71145256Sjkoshy#include <sys/cdefs.h> 72145256Sjkoshy#else 73145256Sjkoshy#include <pcap-stdinc.h> 74145256Sjkoshy#define __LITTLE_ENDIAN 1 75145256Sjkoshy#define __BYTE_ORDER __LITTLE_ENDIAN 76145256Sjkoshy#endif 77145256Sjkoshy 78145256Sjkoshy/* 79145256Sjkoshy * revision information. this is the release date in YYYYMMDD format. 80145256Sjkoshy * it can change every day so the right thing to do with it is use it 81196446Sjkoshy * in preprocessor commands such as "#if (__BIND > 19931104)". do not 82147586Sru * compare for equality; rather, use it to determine whether your resolver 83145256Sjkoshy * is new enough to contain a certain feature. 84145256Sjkoshy */ 85145256Sjkoshy 86147586Sru#define __BIND 19940417 /* interface version stamp */ 87145256Sjkoshy 88145256Sjkoshy/* 89145256Sjkoshy * Define constants based on rfc883 90145256Sjkoshy */ 91145256Sjkoshy#define PACKETSZ 512 /* maximum packet size */ 92147586Sru#define MAXDNAME 256 /* maximum domain name */ 93147586Sru#define MAXCDNAME 255 /* maximum compressed domain name */ 94145256Sjkoshy#define MAXLABEL 63 /* maximum length of domain label */ 95147586Sru#define HFIXEDSZ 12 /* #/bytes of fixed data in header */ 96145256Sjkoshy#define QFIXEDSZ 4 /* #/bytes of fixed data in query */ 97145256Sjkoshy#define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ 98147586Sru#define INT32SZ 4 /* for systems without 32-bit ints */ 99147586Sru#define INT16SZ 2 /* for systems without 16-bit ints */ 100145256Sjkoshy#define INADDRSZ 4 /* for sizeof(struct inaddr) != 4 */ 101147586Sru 102145256Sjkoshy/* 103145256Sjkoshy * Internet nameserver port number 104145256Sjkoshy */ 105145256Sjkoshy#define NAMESERVER_PORT 53 106145256Sjkoshy 107145256Sjkoshy/* 108145256Sjkoshy * Currently defined opcodes 109145256Sjkoshy */ 110145256Sjkoshy#define QUERY 0x0 /* standard query */ 111145256Sjkoshy#define IQUERY 0x1 /* inverse query */ 112145256Sjkoshy#define STATUS 0x2 /* nameserver status query */ 113145256Sjkoshy/*#define xxx 0x3 *//* 0x3 reserved */ 114145256Sjkoshy#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */ 115145256Sjkoshy#ifdef ALLOW_UPDATES 116145256Sjkoshy /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */ 117145256Sjkoshy# define UPDATEA 0x9 /* add resource record */ 118145256Sjkoshy# define UPDATED 0xa /* delete a specific resource record */ 119145256Sjkoshy# define UPDATEDA 0xb /* delete all named resource record */ 120145256Sjkoshy# define UPDATEM 0xc /* modify a specific resource record */ 121145256Sjkoshy# define UPDATEMA 0xd /* modify all named resource record */ 122145256Sjkoshy# define ZONEINIT 0xe /* initial zone transfer */ 123145256Sjkoshy# define ZONEREF 0xf /* incremental zone referesh */ 124147586Sru#endif 125145256Sjkoshy 126147586Sru/* 127145256Sjkoshy * Currently defined response codes 128145256Sjkoshy */ 129145256Sjkoshy#ifdef HAVE_ADDRINFO 130145256Sjkoshy#define NOERROR 0 /* no error */ 131145256Sjkoshy#endif /* HAVE_ADDRINFO */ 132145256Sjkoshy#define FORMERR 1 /* format error */ 133147586Sru#define SERVFAIL 2 /* server failure */ 134145256Sjkoshy#define NXDOMAIN 3 /* non existent domain */ 135147586Sru#define NOTIMP 4 /* not implemented */ 136145256Sjkoshy#define REFUSED 5 /* query refused */ 137147586Sru#ifdef ALLOW_UPDATES 138145256Sjkoshy /* non standard */ 139183084Sjkoshy# define NOCHANGE 0xf /* update failed to change db */ 140147586Sru#endif 141145256Sjkoshy 142145256Sjkoshy/* 143183540Sjkoshy * Type values for resources and queries 144145256Sjkoshy */ 145145256Sjkoshy#define T_A 1 /* host address */ 146183540Sjkoshy#define T_NS 2 /* authoritative server */ 147145256Sjkoshy#define T_MD 3 /* mail destination */ 148145256Sjkoshy#define T_MF 4 /* mail forwarder */ 149183540Sjkoshy#define T_CNAME 5 /* canonical name */ 150145256Sjkoshy#define T_SOA 6 /* start of authority zone */ 151145256Sjkoshy#define T_MB 7 /* mailbox domain name */ 152147586Sru#define T_MG 8 /* mail group member */ 153145256Sjkoshy#define T_MR 9 /* mail rename name */ 154145256Sjkoshy#define T_NULL 10 /* null resource record */ 155183540Sjkoshy#define T_WKS 11 /* well known service */ 156145256Sjkoshy#define T_PTR 12 /* domain name pointer */ 157145256Sjkoshy#define T_HINFO 13 /* host information */ 158147586Sru#define T_MINFO 14 /* mailbox information */ 159145256Sjkoshy#define T_MX 15 /* mail routing information */ 160145256Sjkoshy#define T_TXT 16 /* text strings */ 161183540Sjkoshy#define T_RP 17 /* responsible person */ 162145256Sjkoshy#define T_AFSDB 18 /* AFS cell database */ 163145256Sjkoshy#define T_X25 19 /* X_25 calling address */ 164147586Sru#define T_ISDN 20 /* ISDN calling address */ 165145256Sjkoshy#define T_RT 21 /* router */ 166183540Sjkoshy#define T_NSAP 22 /* NSAP address */ 167183540Sjkoshy#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ 168183540Sjkoshy#define T_SIG 24 /* security signature */ 169145256Sjkoshy#define T_KEY 25 /* security key */ 170183540Sjkoshy#define T_PX 26 /* X.400 mail mapping */ 171145256Sjkoshy#define T_GPOS 27 /* geographical position (withdrawn) */ 172145256Sjkoshy#define T_AAAA 28 /* IP6 Address */ 173183540Sjkoshy#define T_LOC 29 /* Location Information */ 174145256Sjkoshy /* non standard */ 175183540Sjkoshy#define T_UINFO 100 /* user (finger) information */ 176183540Sjkoshy#define T_UID 101 /* user ID */ 177183540Sjkoshy#define T_GID 102 /* group ID */ 178183540Sjkoshy#define T_UNSPEC 103 /* Unspecified format (binary data) */ 179183540Sjkoshy /* Query type values which do not appear in resource records */ 180183540Sjkoshy#define T_AXFR 252 /* transfer zone of authority */ 181183540Sjkoshy#define T_MAILB 253 /* transfer mailbox records */ 182183540Sjkoshy#define T_MAILA 254 /* transfer mail agent records */ 183183540Sjkoshy#define T_ANY 255 /* wildcard match */ 184183540Sjkoshy 185183540Sjkoshy/* 186183540Sjkoshy * Values for class field 187183540Sjkoshy */ 188183540Sjkoshy 189183540Sjkoshy#define C_IN 1 /* the arpa internet */ 190183540Sjkoshy#define C_CHAOS 3 /* for chaos net (MIT) */ 191183540Sjkoshy#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ 192145256Sjkoshy /* Query class values which do not appear in resource records */ 193183540Sjkoshy#define C_ANY 255 /* wildcard match */ 194145256Sjkoshy 195145256Sjkoshy/* 196183540Sjkoshy * Status return codes for T_UNSPEC conversion routines 197145256Sjkoshy */ 198183540Sjkoshy#define CONV_SUCCESS 0 199183540Sjkoshy#define CONV_OVERFLOW (-1) 200183540Sjkoshy#define CONV_BADFMT (-2) 201145256Sjkoshy#define CONV_BADCKSUM (-3) 202183540Sjkoshy#define CONV_BADBUFLEN (-4) 203145256Sjkoshy 204145256Sjkoshy#ifndef __BYTE_ORDER 205145256Sjkoshy#if (BSD >= 199103) 206183540Sjkoshy# include <machine/endian.h> 207196446Sjkoshy#else 208183540Sjkoshy#ifdef linux 209183540Sjkoshy# include <endian.h> 210183540Sjkoshy#else 211183540Sjkoshy#define __LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */ 212183540Sjkoshy#define __BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ 213183540Sjkoshy#define __PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/ 214183540Sjkoshy 215183540Sjkoshy#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \ 216183540Sjkoshy defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ 217183540Sjkoshy defined(__alpha__) || defined(__alpha) 218183540Sjkoshy#define __BYTE_ORDER __LITTLE_ENDIAN 219183540Sjkoshy#endif 220145256Sjkoshy 221183540Sjkoshy#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \ 222145256Sjkoshy defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \ 223145256Sjkoshy defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\ 224183540Sjkoshy defined(apollo) || defined(__convex__) || defined(_CRAY) || \ 225145256Sjkoshy defined(__hppa) || defined(__hp9000) || \ 226145256Sjkoshy defined(__hp9000s300) || defined(__hp9000s700) || \ 227183084Sjkoshy defined (BIT_ZERO_ON_LEFT) || defined(m68k) 228183084Sjkoshy#define __BYTE_ORDER __BIG_ENDIAN 229183084Sjkoshy#endif 230183084Sjkoshy#endif /* linux */ 231183084Sjkoshy#endif /* BSD */ 232183084Sjkoshy#endif /* __BYTE_ORDER */ 233183084Sjkoshy 234183084Sjkoshy#if !defined(__BYTE_ORDER) || \ 235183084Sjkoshy (__BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN && \ 236183084Sjkoshy __BYTE_ORDER != __PDP_ENDIAN) 237183084Sjkoshy /* you must determine what the correct bit order is for 238183084Sjkoshy * your compiler - the next line is an intentional error 239183084Sjkoshy * which will force your compiles to bomb until you fix 240183084Sjkoshy * the above macros. 241145256Sjkoshy */ 242145256Sjkoshy error "Undefined or invalid __BYTE_ORDER"; 243183084Sjkoshy#endif 244183595Sjkoshy 245183595Sjkoshy/* 246183595Sjkoshy * Structure for query header. The order of the fields is machine- and 247183595Sjkoshy * compiler-dependent, depending on the byte/bit order and the layout 248183084Sjkoshy * of bit fields. We use bit fields only in int variables, as this 249183084Sjkoshy * is all ANSI requires. This requires a somewhat confusing rearrangement. 250183084Sjkoshy */ 251183084Sjkoshy 252233628Sfabienttypedef struct { 253183084Sjkoshy unsigned id :16; /* query identification number */ 254147191Sjkoshy#if __BYTE_ORDER == __BIG_ENDIAN 255183084Sjkoshy /* fields in third byte */ 256148223Sjkoshy unsigned qr: 1; /* response flag */ 257148223Sjkoshy unsigned opcode: 4; /* purpose of message */ 258152551Sru unsigned aa: 1; /* authoritive answer */ 259148223Sjkoshy unsigned tc: 1; /* truncated message */ 260148223Sjkoshy unsigned rd: 1; /* recursion desired */ 261173900Sjkoshy /* fields in fourth byte */ 262173900Sjkoshy unsigned ra: 1; /* recursion available */ 263173900Sjkoshy unsigned pr: 1; /* primary server req'd (!standard) */ 264173900Sjkoshy unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */ 265173900Sjkoshy unsigned rcode :4; /* response code */ 266173900Sjkoshy#endif 267#if __BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __PDP_ENDIAN 268 /* fields in third byte */ 269 unsigned rd :1; /* recursion desired */ 270 unsigned tc :1; /* truncated message */ 271 unsigned aa :1; /* authoritive answer */ 272 unsigned opcode :4; /* purpose of message */ 273 unsigned qr :1; /* response flag */ 274 /* fields in fourth byte */ 275 unsigned rcode :4; /* response code */ 276 unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */ 277 unsigned pr :1; /* primary server req'd (!standard) */ 278 unsigned ra :1; /* recursion available */ 279#endif 280 /* remaining bytes */ 281 unsigned qdcount :16; /* number of question entries */ 282 unsigned ancount :16; /* number of answer entries */ 283 unsigned nscount :16; /* number of authority entries */ 284 unsigned arcount :16; /* number of resource entries */ 285} HEADER; 286 287/* 288 * Defines for handling compressed domain names 289 */ 290#define INDIR_MASK 0xc0 291 292/* 293 * Structure for passing resource records around. 294 */ 295struct rrec { 296 int16_t r_zone; /* zone number */ 297 int16_t r_class; /* class number */ 298 int16_t r_type; /* type number */ 299 u_int32_t r_ttl; /* time to live */ 300 int r_size; /* size of data area */ 301 char *r_data; /* pointer to data */ 302}; 303 304//extern u_int16_t _getshort __P((const u_char *)); 305//extern u_int32_t _getlong __P((const u_char *)); 306 307/* 308 * Inline versions of get/put short/long. Pointer is advanced. 309 * 310 * These macros demonstrate the property of C whereby it can be 311 * portable or it can be elegant but rarely both. 312 */ 313#define GETSHORT(s, cp) { \ 314 register u_char *t_cp = (u_char *)(cp); \ 315 (s) = ((u_int16_t)t_cp[0] << 8) \ 316 | ((u_int16_t)t_cp[1]) \ 317 ; \ 318 (cp) += INT16SZ; \ 319} 320 321#define GETLONG(l, cp) { \ 322 register u_char *t_cp = (u_char *)(cp); \ 323 (l) = ((u_int32_t)t_cp[0] << 24) \ 324 | ((u_int32_t)t_cp[1] << 16) \ 325 | ((u_int32_t)t_cp[2] << 8) \ 326 | ((u_int32_t)t_cp[3]) \ 327 ; \ 328 (cp) += INT32SZ; \ 329} 330 331#define PUTSHORT(s, cp) { \ 332 register u_int16_t t_s = (u_int16_t)(s); \ 333 register u_char *t_cp = (u_char *)(cp); \ 334 *t_cp++ = t_s >> 8; \ 335 *t_cp = t_s; \ 336 (cp) += INT16SZ; \ 337} 338 339#define PUTLONG(l, cp) { \ 340 register u_int32_t t_l = (u_int32_t)(l); \ 341 register u_char *t_cp = (u_char *)(cp); \ 342 *t_cp++ = t_l >> 24; \ 343 *t_cp++ = t_l >> 16; \ 344 *t_cp++ = t_l >> 8; \ 345 *t_cp = t_l; \ 346 (cp) += INT32SZ; \ 347} 348 349#endif /* !_NAMESER_H_ */ 350