Home | History | Annotate | Line # | Download | only in arpa
nameser.h revision 1.3
      1 /*
      2  * Copyright (c) 1983, 1989 Regents of the University of California.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      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  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  *
     33  *	from: @(#)nameser.h	5.25 (Berkeley) 4/3/91
     34  *	$Id: nameser.h,v 1.3 1993/08/01 18:46:21 mycroft Exp $
     35  */
     36 
     37 #ifndef _NAMESER_H_
     38 #define	_NAMESER_H_
     39 
     40 /*
     41  * Define constants based on rfc883
     42  */
     43 #define PACKETSZ	512		/* maximum packet size */
     44 #define MAXDNAME	256		/* maximum domain name */
     45 #define MAXCDNAME	255		/* maximum compressed domain name */
     46 #define MAXLABEL	63		/* maximum length of domain label */
     47 	/* Number of bytes of fixed size data in query structure */
     48 #define QFIXEDSZ	4
     49 	/* number of bytes of fixed size data in resource record */
     50 #define RRFIXEDSZ	10
     51 
     52 /*
     53  * Internet nameserver port number
     54  */
     55 #define NAMESERVER_PORT	53
     56 
     57 /*
     58  * Currently defined opcodes
     59  */
     60 #define QUERY		0x0		/* standard query */
     61 #define IQUERY		0x1		/* inverse query */
     62 #define STATUS		0x2		/* nameserver status query */
     63 /*#define xxx		0x3		/* 0x3 reserved */
     64 	/* non standard */
     65 #define UPDATEA		0x9		/* add resource record */
     66 #define UPDATED		0xa		/* delete a specific resource record */
     67 #define UPDATEDA	0xb		/* delete all nemed resource record */
     68 #define UPDATEM		0xc		/* modify a specific resource record */
     69 #define UPDATEMA	0xd		/* modify all named resource record */
     70 
     71 #define ZONEINIT	0xe		/* initial zone transfer */
     72 #define ZONEREF		0xf		/* incremental zone referesh */
     73 
     74 /*
     75  * Currently defined response codes
     76  */
     77 #define NOERROR		0		/* no error */
     78 #define FORMERR		1		/* format error */
     79 #define SERVFAIL	2		/* server failure */
     80 #define NXDOMAIN	3		/* non existent domain */
     81 #define NOTIMP		4		/* not implemented */
     82 #define REFUSED		5		/* query refused */
     83 	/* non standard */
     84 #define NOCHANGE	0xf		/* update failed to change db */
     85 
     86 /*
     87  * Type values for resources and queries
     88  */
     89 #define T_A		1		/* host address */
     90 #define T_NS		2		/* authoritative server */
     91 #define T_MD		3		/* mail destination */
     92 #define T_MF		4		/* mail forwarder */
     93 #define T_CNAME		5		/* connonical name */
     94 #define T_SOA		6		/* start of authority zone */
     95 #define T_MB		7		/* mailbox domain name */
     96 #define T_MG		8		/* mail group member */
     97 #define T_MR		9		/* mail rename name */
     98 #define T_NULL		10		/* null resource record */
     99 #define T_WKS		11		/* well known service */
    100 #define T_PTR		12		/* domain name pointer */
    101 #define T_HINFO		13		/* host information */
    102 #define T_MINFO		14		/* mailbox information */
    103 #define T_MX		15		/* mail routing information */
    104 #define T_TXT		16		/* text strings */
    105 	/* non standard */
    106 #define T_UINFO		100		/* user (finger) information */
    107 #define T_UID		101		/* user ID */
    108 #define T_GID		102		/* group ID */
    109 #define T_UNSPEC	103		/* Unspecified format (binary data) */
    110 	/* Query type values which do not appear in resource records */
    111 #define T_AXFR		252		/* transfer zone of authority */
    112 #define T_MAILB		253		/* transfer mailbox records */
    113 #define T_MAILA		254		/* transfer mail agent records */
    114 #define T_ANY		255		/* wildcard match */
    115 
    116 /*
    117  * Values for class field
    118  */
    119 
    120 #define C_IN		1		/* the arpa internet */
    121 #define C_CHAOS		3		/* for chaos net at MIT */
    122 #define C_HS		4		/* for Hesiod name server at MIT */
    123 	/* Query class values which do not appear in resource records */
    124 #define C_ANY		255		/* wildcard match */
    125 
    126 /*
    127  * Status return codes for T_UNSPEC conversion routines
    128  */
    129 #define CONV_SUCCESS 0
    130 #define CONV_OVERFLOW -1
    131 #define CONV_BADFMT -2
    132 #define CONV_BADCKSUM -3
    133 #define CONV_BADBUFLEN -4
    134 
    135 #ifndef BYTE_ORDER
    136 #define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax) */
    137 #define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
    138 #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp) */
    139 
    140 #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
    141     defined(MIPSEL) || defined(BIT_ZERO_ON_RIGHT)
    142 #define BYTE_ORDER	LITTLE_ENDIAN
    143 
    144 #endif
    145 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
    146     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
    147     defined(MIPSEB) || defined (BIT_ZERO_ON_LEFT)
    148 #define BYTE_ORDER	BIG_ENDIAN
    149 #endif
    150 #endif /* BYTE_ORDER */
    151 
    152 #ifndef BYTE_ORDER
    153 	/* you must determine what the correct bit order is for your compiler */
    154 	UNDEFINED_BIT_ORDER;
    155 #endif
    156 /*
    157  * Structure for query header, the order of the fields is machine and
    158  * compiler dependent, in our case, the bits within a byte are assignd
    159  * least significant first, while the order of transmition is most
    160  * significant first.  This requires a somewhat confusing rearrangement.
    161  */
    162 
    163 typedef struct {
    164 	u_short	id;		/* query identification number */
    165 #if BYTE_ORDER == BIG_ENDIAN
    166 			/* fields in third byte */
    167 	u_char	qr:1;		/* response flag */
    168 	u_char	opcode:4;	/* purpose of message */
    169 	u_char	aa:1;		/* authoritive answer */
    170 	u_char	tc:1;		/* truncated message */
    171 	u_char	rd:1;		/* recursion desired */
    172 			/* fields in fourth byte */
    173 	u_char	ra:1;		/* recursion available */
    174 	u_char	pr:1;		/* primary server required (non standard) */
    175 	u_char	unused:2;	/* unused bits */
    176 	u_char	rcode:4;	/* response code */
    177 #endif
    178 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
    179 			/* fields in third byte */
    180 	u_char	rd:1;		/* recursion desired */
    181 	u_char	tc:1;		/* truncated message */
    182 	u_char	aa:1;		/* authoritive answer */
    183 	u_char	opcode:4;	/* purpose of message */
    184 	u_char	qr:1;		/* response flag */
    185 			/* fields in fourth byte */
    186 	u_char	rcode:4;	/* response code */
    187 	u_char	unused:2;	/* unused bits */
    188 	u_char	pr:1;		/* primary server required (non standard) */
    189 	u_char	ra:1;		/* recursion available */
    190 #endif
    191 			/* remaining bytes */
    192 	u_short	qdcount;	/* number of question entries */
    193 	u_short	ancount;	/* number of answer entries */
    194 	u_short	nscount;	/* number of authority entries */
    195 	u_short	arcount;	/* number of resource entries */
    196 } HEADER;
    197 
    198 /*
    199  * Defines for handling compressed domain names
    200  */
    201 #define INDIR_MASK	0xc0
    202 
    203 /*
    204  * Structure for passing resource records around.
    205  */
    206 struct rrec {
    207 	short	r_zone;			/* zone number */
    208 	short	r_class;		/* class number */
    209 	short	r_type;			/* type number */
    210 	u_long	r_ttl;			/* time to live */
    211 	int	r_size;			/* size of data area */
    212 	char	*r_data;		/* pointer to data */
    213 };
    214 
    215 extern	u_short	_getshort();
    216 extern	u_long	_getlong();
    217 
    218 /*
    219  * Inline versions of get/put short/long.
    220  * Pointer is advanced; we assume that both arguments
    221  * are lvalues and will already be in registers.
    222  * cp MUST be u_char *.
    223  */
    224 #define GETSHORT(s, cp) { \
    225 	(s) = *(cp)++ << 8; \
    226 	(s) |= *(cp)++; \
    227 }
    228 
    229 #define GETLONG(l, cp) { \
    230 	(l) = *(cp)++ << 8; \
    231 	(l) |= *(cp)++; (l) <<= 8; \
    232 	(l) |= *(cp)++; (l) <<= 8; \
    233 	(l) |= *(cp)++; \
    234 }
    235 
    236 
    237 #define PUTSHORT(s, cp) { \
    238 	*(cp)++ = (s) >> 8; \
    239 	*(cp)++ = (s); \
    240 }
    241 
    242 /*
    243  * Warning: PUTLONG destroys its first argument.
    244  */
    245 #define PUTLONG(l, cp) { \
    246 	(cp)[3] = l; \
    247 	(cp)[2] = (l >>= 8); \
    248 	(cp)[1] = (l >>= 8); \
    249 	(cp)[0] = l >> 8; \
    250 	(cp) += sizeof(u_long); \
    251 }
    252 
    253 #endif /* !_NAMESER_H_ */
    254