nameser.h revision 10132
11539Srgrimes/*
21539Srgrimes * Copyright (c) 1983, 1989, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes * 1. Redistributions of source code must retain the above copyright
91539Srgrimes *    notice, this list of conditions and the following disclaimer.
101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111539Srgrimes *    notice, this list of conditions and the following disclaimer in the
121539Srgrimes *    documentation and/or other materials provided with the distribution.
131539Srgrimes * 3. All advertising materials mentioning features or use of this software
141539Srgrimes *    must display the following acknowledgement:
151539Srgrimes *	This product includes software developed by the University of
161539Srgrimes *	California, Berkeley and its contributors.
171539Srgrimes * 4. Neither the name of the University nor the names of its contributors
181539Srgrimes *    may be used to endorse or promote products derived from this software
191539Srgrimes *    without specific prior written permission.
201539Srgrimes *
211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311539Srgrimes * SUCH DAMAGE.
321539Srgrimes *
331539Srgrimes * -
341539Srgrimes * Portions Copyright (c) 1993 by Digital Equipment Corporation.
358858Srgrimes *
361539Srgrimes * Permission to use, copy, modify, and distribute this software for any
371539Srgrimes * purpose with or without fee is hereby granted, provided that the above
381539Srgrimes * copyright notice and this permission notice appear in all copies, and that
391539Srgrimes * the name of Digital Equipment Corporation not be used in advertising or
401539Srgrimes * publicity pertaining to distribution of the document or software without
411539Srgrimes * specific, written prior permission.
428858Srgrimes *
431539Srgrimes * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
441539Srgrimes * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
451539Srgrimes * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
461539Srgrimes * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
471539Srgrimes * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
481539Srgrimes * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
491539Srgrimes * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
501539Srgrimes * SOFTWARE.
511539Srgrimes * -
521539Srgrimes * --Copyright--
533070Spst *
543070Spst *      @(#)nameser.h	8.2 (Berkeley) 2/16/94
553070Spst *	From Id: nameser.h,v 4.9.1.15 1994/07/19 22:51:24 vixie Exp
561539Srgrimes */
571539Srgrimes
5810132Speter#ifndef _ARPA_NAMESER_H_
5910132Speter#define	_ARPA_NAMESER_H_
601539Srgrimes
613070Spst#include <sys/param.h>
621539Srgrimes#include <sys/types.h>
633070Spst#include <sys/cdefs.h>
643070Spst#include <machine/endian.h>
651539Srgrimes
663070Spst
671539Srgrimes/*
683070Spst * revision information.  this is the release date in YYYYMMDD format.
693070Spst * it can change every day so the right thing to do with it is use it
703070Spst * in preprocessor commands such as "#if (__BIND > 19931104)".  do not
713070Spst * compare for equality; rather, use it to determine whether your resolver
723070Spst * is new enough to contain a certain feature.
733070Spst */
743070Spst
7510132Speter#define	__BIND		19950621	/* interface version stamp */
763070Spst
773070Spst/*
781539Srgrimes * Define constants based on rfc883
791539Srgrimes */
803070Spst#define	PACKETSZ	512		/* maximum packet size */
813070Spst#define	MAXDNAME	256		/* maximum domain name */
823070Spst#define	MAXCDNAME	255		/* maximum compressed domain name */
833070Spst#define	MAXLABEL	63		/* maximum length of domain label */
843070Spst#define	HFIXEDSZ	12		/* #/bytes of fixed data in header */
853070Spst#define	QFIXEDSZ	4		/* #/bytes of fixed data in query */
863070Spst#define	RRFIXEDSZ	10		/* #/bytes of fixed data in r record */
873070Spst#define	INT32SZ		4		/* for systems without 32-bit ints */
883070Spst#define	INT16SZ		2		/* for systems without 16-bit ints */
893070Spst#define	INADDRSZ	4		/* for sizeof(struct inaddr) != 4 */
901539Srgrimes
911539Srgrimes/*
921539Srgrimes * Internet nameserver port number
931539Srgrimes */
943070Spst#define	NAMESERVER_PORT	53
951539Srgrimes
961539Srgrimes/*
9710132Speter * Currently defined opcodes
981539Srgrimes */
993070Spst#define	QUERY		0x0		/* standard query */
1003070Spst#define	IQUERY		0x1		/* inverse query */
1013070Spst#define	STATUS		0x2		/* nameserver status query */
10210132Speter/*#define xxx		0x3 */		/* 0x3 reserved */
10310132Speter#define	NS_NOTIFY_OP	0x4		/* notify secondary of SOA change */
10410132Speter#ifdef ALLOW_UPDATES
1051539Srgrimes	/* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
10610132Speter# define UPDATEA	0x9		/* add resource record */
10710132Speter# define UPDATED	0xa		/* delete a specific resource record */
10810132Speter# define UPDATEDA	0xb		/* delete all named resource record */
10910132Speter# define UPDATEM	0xc		/* modify a specific resource record */
11010132Speter# define UPDATEMA	0xd		/* modify all named resource record */
11110132Speter# define ZONEINIT	0xe		/* initial zone transfer */
11210132Speter# define ZONEREF	0xf		/* incremental zone referesh */
11310132Speter#endif
1141539Srgrimes
1151539Srgrimes/*
11610132Speter * Currently defined response codes
1171539Srgrimes */
1183070Spst#define	NOERROR		0		/* no error */
1193070Spst#define	FORMERR		1		/* format error */
1203070Spst#define	SERVFAIL	2		/* server failure */
1213070Spst#define	NXDOMAIN	3		/* non existent domain */
1223070Spst#define	NOTIMP		4		/* not implemented */
1233070Spst#define	REFUSED		5		/* query refused */
12410132Speter#ifdef ALLOW_UPDATES
1251539Srgrimes	/* non standard */
12610132Speter# define NOCHANGE	0xf		/* update failed to change db */
12710132Speter#endif
1281539Srgrimes
1291539Srgrimes/*
1301539Srgrimes * Type values for resources and queries
1311539Srgrimes */
1323070Spst#define	T_A		1		/* host address */
1333070Spst#define	T_NS		2		/* authoritative server */
1343070Spst#define	T_MD		3		/* mail destination */
1353070Spst#define	T_MF		4		/* mail forwarder */
13610132Speter#define T_CNAME		5		/* canonical name */
1373070Spst#define	T_SOA		6		/* start of authority zone */
1383070Spst#define	T_MB		7		/* mailbox domain name */
1393070Spst#define	T_MG		8		/* mail group member */
1403070Spst#define	T_MR		9		/* mail rename name */
1413070Spst#define	T_NULL		10		/* null resource record */
1423070Spst#define	T_WKS		11		/* well known service */
1433070Spst#define	T_PTR		12		/* domain name pointer */
1443070Spst#define	T_HINFO		13		/* host information */
1453070Spst#define	T_MINFO		14		/* mailbox information */
1463070Spst#define	T_MX		15		/* mail routing information */
1473070Spst#define	T_TXT		16		/* text strings */
1481539Srgrimes#define	T_RP		17		/* responsible person */
1491539Srgrimes#define	T_AFSDB		18		/* AFS cell database */
1503070Spst#define	T_X25		19		/* X_25 calling address */
1513070Spst#define	T_ISDN		20		/* ISDN calling address */
1523070Spst#define	T_RT		21		/* router */
1531539Srgrimes#define	T_NSAP		22		/* NSAP address */
1543070Spst#define	T_NSAP_PTR	23		/* reverse NSAP lookup (deprecated) */
15510132Speter#define	T_SIG		24		/* security signature */
15610132Speter#define	T_KEY		25		/* security key */
15710132Speter#define	T_PX		26		/* X.400 mail mapping */
15810132Speter#define	T_GPOS		27		/* geographical position (withdrawn) */
15910132Speter#define	T_AAAA		28		/* IP6 Address */
16010132Speter#define	T_LOC		29		/* Location Information */
1611539Srgrimes	/* non standard */
1623070Spst#define	T_UINFO		100		/* user (finger) information */
1633070Spst#define	T_UID		101		/* user ID */
1643070Spst#define	T_GID		102		/* group ID */
1653070Spst#define	T_UNSPEC	103		/* Unspecified format (binary data) */
1661539Srgrimes	/* Query type values which do not appear in resource records */
1673070Spst#define	T_AXFR		252		/* transfer zone of authority */
1683070Spst#define	T_MAILB		253		/* transfer mailbox records */
1693070Spst#define	T_MAILA		254		/* transfer mail agent records */
1703070Spst#define	T_ANY		255		/* wildcard match */
1711539Srgrimes
1721539Srgrimes/*
1731539Srgrimes * Values for class field
1741539Srgrimes */
1751539Srgrimes
1763070Spst#define	C_IN		1		/* the arpa internet */
1773070Spst#define	C_CHAOS		3		/* for chaos net (MIT) */
1783070Spst#define	C_HS		4		/* for Hesiod name server (MIT) (XXX) */
1791539Srgrimes	/* Query class values which do not appear in resource records */
1803070Spst#define	C_ANY		255		/* wildcard match */
1811539Srgrimes
1821539Srgrimes/*
1831539Srgrimes * Status return codes for T_UNSPEC conversion routines
1841539Srgrimes */
1853070Spst#define	CONV_SUCCESS	0
1863070Spst#define	CONV_OVERFLOW	(-1)
1873070Spst#define	CONV_BADFMT	(-2)
1883070Spst#define	CONV_BADCKSUM	(-3)
1893070Spst#define	CONV_BADBUFLEN	(-4)
1901539Srgrimes
1911539Srgrimes/*
1921539Srgrimes * Structure for query header.  The order of the fields is machine- and
1931539Srgrimes * compiler-dependent, depending on the byte/bit order and the layout
1941539Srgrimes * of bit fields.  We use bit fields only in int variables, as this
1951539Srgrimes * is all ANSI requires.  This requires a somewhat confusing rearrangement.
1961539Srgrimes */
1971539Srgrimes
1981539Srgrimestypedef struct {
1993070Spst	unsigned	id :16;		/* query identification number */
2001539Srgrimes#if BYTE_ORDER == BIG_ENDIAN
2011539Srgrimes			/* fields in third byte */
2023070Spst	unsigned	qr: 1;		/* response flag */
2033070Spst	unsigned	opcode: 4;	/* purpose of message */
2043070Spst	unsigned	aa: 1;		/* authoritive answer */
2053070Spst	unsigned	tc: 1;		/* truncated message */
2063070Spst	unsigned	rd: 1;		/* recursion desired */
2071539Srgrimes			/* fields in fourth byte */
2083070Spst	unsigned	ra: 1;		/* recursion available */
20910132Speter	unsigned	unused :3;	/* unused bits (MBZ as of 4.9.3a3) */
2103070Spst	unsigned	rcode :4;	/* response code */
2111539Srgrimes#endif
2121539Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
2131539Srgrimes			/* fields in third byte */
2143070Spst	unsigned	rd :1;		/* recursion desired */
2153070Spst	unsigned	tc :1;		/* truncated message */
2163070Spst	unsigned	aa :1;		/* authoritive answer */
2173070Spst	unsigned	opcode :4;	/* purpose of message */
2183070Spst	unsigned	qr :1;		/* response flag */
2191539Srgrimes			/* fields in fourth byte */
2203070Spst	unsigned	rcode :4;	/* response code */
22110132Speter	unsigned	unused :3;	/* unused bits (MBZ as of 4.9.3a3) */
2223070Spst	unsigned	ra :1;		/* recursion available */
2231539Srgrimes#endif
2241539Srgrimes			/* remaining bytes */
2253070Spst	unsigned	qdcount :16;	/* number of question entries */
2263070Spst	unsigned	ancount :16;	/* number of answer entries */
2273070Spst	unsigned	nscount :16;	/* number of authority entries */
2283070Spst	unsigned	arcount :16;	/* number of resource entries */
2291539Srgrimes} HEADER;
2301539Srgrimes
2311539Srgrimes/*
2321539Srgrimes * Defines for handling compressed domain names
2331539Srgrimes */
2343070Spst#define	INDIR_MASK	0xc0
2351539Srgrimes
2361539Srgrimes/*
2371539Srgrimes * Structure for passing resource records around.
2381539Srgrimes */
2391539Srgrimesstruct rrec {
2403070Spst	int16_t		r_zone;			/* zone number */
2413070Spst	int16_t		r_class;		/* class number */
2423070Spst	int16_t		r_type;			/* type number */
2431539Srgrimes	u_int32_t	r_ttl;			/* time to live */
2443070Spst	int		r_size;			/* size of data area */
2453070Spst	char		*r_data;		/* pointer to data */
2461539Srgrimes};
2471539Srgrimes
2483070Spstextern	u_int16_t	_getshort __P((const u_char *));
2493070Spstextern	u_int32_t	_getlong __P((const u_char *));
2501539Srgrimes
2511539Srgrimes/*
2521539Srgrimes * Inline versions of get/put short/long.  Pointer is advanced.
2531539Srgrimes *
2541539Srgrimes * These macros demonstrate the property of C whereby it can be
2553070Spst * portable or it can be elegant but rarely both.
2561539Srgrimes */
2573070Spst#define	GETSHORT(s, cp) { \
2581539Srgrimes	register u_char *t_cp = (u_char *)(cp); \
2593070Spst	(s) = ((u_int16_t)t_cp[0] << 8) \
2603070Spst	    | ((u_int16_t)t_cp[1]) \
2613070Spst	    ; \
2623070Spst	(cp) += INT16SZ; \
2631539Srgrimes}
2641539Srgrimes
2653070Spst#define	GETLONG(l, cp) { \
2661539Srgrimes	register u_char *t_cp = (u_char *)(cp); \
2673070Spst	(l) = ((u_int32_t)t_cp[0] << 24) \
2683070Spst	    | ((u_int32_t)t_cp[1] << 16) \
2693070Spst	    | ((u_int32_t)t_cp[2] << 8) \
2703070Spst	    | ((u_int32_t)t_cp[3]) \
2713070Spst	    ; \
2723070Spst	(cp) += INT32SZ; \
2731539Srgrimes}
2741539Srgrimes
2753070Spst#define	PUTSHORT(s, cp) { \
2761539Srgrimes	register u_int16_t t_s = (u_int16_t)(s); \
2771539Srgrimes	register u_char *t_cp = (u_char *)(cp); \
2781539Srgrimes	*t_cp++ = t_s >> 8; \
2791539Srgrimes	*t_cp   = t_s; \
2803070Spst	(cp) += INT16SZ; \
2811539Srgrimes}
2821539Srgrimes
2833070Spst#define	PUTLONG(l, cp) { \
2841539Srgrimes	register u_int32_t t_l = (u_int32_t)(l); \
2851539Srgrimes	register u_char *t_cp = (u_char *)(cp); \
2861539Srgrimes	*t_cp++ = t_l >> 24; \
2871539Srgrimes	*t_cp++ = t_l >> 16; \
2881539Srgrimes	*t_cp++ = t_l >> 8; \
2891539Srgrimes	*t_cp   = t_l; \
2903070Spst	(cp) += INT32SZ; \
2911539Srgrimes}
2921539Srgrimes
29310132Speter#endif /* !_ARPA_NAMESER_H_ */
294