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