Home | History | Annotate | Line # | Download | only in dist
nameser.h revision 1.1
      1  1.1  christos /* @(#) Header: /tcpdump/master/tcpdump/nameser.h,v 1.16 2006-11-10 03:18:21 guy Exp (LBL) */
      2  1.1  christos /*
      3  1.1  christos  * Copyright (c) 1983, 1989, 1993
      4  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      5  1.1  christos  *
      6  1.1  christos  * Redistribution and use in source and binary forms, with or without
      7  1.1  christos  * modification, are permitted provided that the following conditions
      8  1.1  christos  * are met:
      9  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  christos  *    documentation and/or other materials provided with the distribution.
     14  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     15  1.1  christos  *    must display the following acknowledgement:
     16  1.1  christos  *	This product includes software developed by the University of
     17  1.1  christos  *	California, Berkeley and its contributors.
     18  1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     19  1.1  christos  *    may be used to endorse or promote products derived from this software
     20  1.1  christos  *    without specific prior written permission.
     21  1.1  christos  *
     22  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  christos  * SUCH DAMAGE.
     33  1.1  christos  *
     34  1.1  christos  *      @(#)nameser.h	8.2 (Berkeley) 2/16/94
     35  1.1  christos  * -
     36  1.1  christos  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
     37  1.1  christos  *
     38  1.1  christos  * Permission to use, copy, modify, and distribute this software for any
     39  1.1  christos  * purpose with or without fee is hereby granted, provided that the above
     40  1.1  christos  * copyright notice and this permission notice appear in all copies, and that
     41  1.1  christos  * the name of Digital Equipment Corporation not be used in advertising or
     42  1.1  christos  * publicity pertaining to distribution of the document or software without
     43  1.1  christos  * specific, written prior permission.
     44  1.1  christos  *
     45  1.1  christos  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
     46  1.1  christos  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
     47  1.1  christos  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
     48  1.1  christos  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
     49  1.1  christos  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
     50  1.1  christos  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
     51  1.1  christos  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     52  1.1  christos  * SOFTWARE.
     53  1.1  christos  * -
     54  1.1  christos  * --Copyright--
     55  1.1  christos  */
     56  1.1  christos 
     57  1.1  christos #ifndef _NAMESER_H_
     58  1.1  christos #define	_NAMESER_H_
     59  1.1  christos 
     60  1.1  christos #include <sys/types.h>
     61  1.1  christos 
     62  1.1  christos /*
     63  1.1  christos  * Define constants based on rfc883
     64  1.1  christos  */
     65  1.1  christos #define PACKETSZ	512		/* maximum packet size */
     66  1.1  christos #define MAXDNAME	256		/* maximum domain name */
     67  1.1  christos #define MAXCDNAME	255		/* maximum compressed domain name */
     68  1.1  christos #define MAXLABEL	63		/* maximum length of domain label */
     69  1.1  christos 	/* Number of bytes of fixed size data in query structure */
     70  1.1  christos #define QFIXEDSZ	4
     71  1.1  christos 	/* number of bytes of fixed size data in resource record */
     72  1.1  christos #define RRFIXEDSZ	10
     73  1.1  christos 
     74  1.1  christos /*
     75  1.1  christos  * Internet nameserver port number
     76  1.1  christos  */
     77  1.1  christos #define NAMESERVER_PORT	53
     78  1.1  christos 
     79  1.1  christos /*
     80  1.1  christos  * Port for multicast DNS; see
     81  1.1  christos  *
     82  1.1  christos  *	http://files.multicastdns.org/draft-cheshire-dnsext-multicastdns.txt
     83  1.1  christos  *
     84  1.1  christos  * for the current mDNS spec.
     85  1.1  christos  */
     86  1.1  christos #define MULTICASTDNS_PORT	5353
     87  1.1  christos 
     88  1.1  christos /*
     89  1.1  christos  * Currently defined opcodes
     90  1.1  christos  */
     91  1.1  christos #define QUERY		0x0		/* standard query */
     92  1.1  christos #define IQUERY		0x1		/* inverse query */
     93  1.1  christos #define STATUS		0x2		/* nameserver status query */
     94  1.1  christos #if 0
     95  1.1  christos #define xxx		0x3		/* 0x3 reserved */
     96  1.1  christos #endif
     97  1.1  christos 	/* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
     98  1.1  christos #define UPDATEA		0x9		/* add resource record */
     99  1.1  christos #define UPDATED		0xa		/* delete a specific resource record */
    100  1.1  christos #define UPDATEDA	0xb		/* delete all named resource record */
    101  1.1  christos #define UPDATEM		0xc		/* modify a specific resource record */
    102  1.1  christos #define UPDATEMA	0xd		/* modify all named resource record */
    103  1.1  christos 
    104  1.1  christos #define ZONEINIT	0xe		/* initial zone transfer */
    105  1.1  christos #define ZONEREF		0xf		/* incremental zone referesh */
    106  1.1  christos 
    107  1.1  christos /*
    108  1.1  christos  * Undefine various #defines from various System V-flavored OSes (Solaris,
    109  1.1  christos  * SINIX, HP-UX) so the compiler doesn't whine that we redefine them.
    110  1.1  christos  */
    111  1.1  christos #ifdef T_NULL
    112  1.1  christos #undef T_NULL
    113  1.1  christos #endif
    114  1.1  christos #ifdef T_OPT
    115  1.1  christos #undef T_OPT
    116  1.1  christos #endif
    117  1.1  christos #ifdef T_UNSPEC
    118  1.1  christos #undef T_UNSPEC
    119  1.1  christos #endif
    120  1.1  christos #ifdef NOERROR
    121  1.1  christos #undef NOERROR
    122  1.1  christos #endif
    123  1.1  christos 
    124  1.1  christos /*
    125  1.1  christos  * Currently defined response codes
    126  1.1  christos  */
    127  1.1  christos #define NOERROR		0		/* no error */
    128  1.1  christos #define FORMERR		1		/* format error */
    129  1.1  christos #define SERVFAIL	2		/* server failure */
    130  1.1  christos #define NXDOMAIN	3		/* non existent domain */
    131  1.1  christos #define NOTIMP		4		/* not implemented */
    132  1.1  christos #define REFUSED		5		/* query refused */
    133  1.1  christos 	/* non standard */
    134  1.1  christos #define NOCHANGE	0xf		/* update failed to change db */
    135  1.1  christos 
    136  1.1  christos /*
    137  1.1  christos  * Type values for resources and queries
    138  1.1  christos  */
    139  1.1  christos #define T_A		1		/* host address */
    140  1.1  christos #define T_NS		2		/* authoritative server */
    141  1.1  christos #define T_MD		3		/* mail destination */
    142  1.1  christos #define T_MF		4		/* mail forwarder */
    143  1.1  christos #define T_CNAME		5		/* connonical name */
    144  1.1  christos #define T_SOA		6		/* start of authority zone */
    145  1.1  christos #define T_MB		7		/* mailbox domain name */
    146  1.1  christos #define T_MG		8		/* mail group member */
    147  1.1  christos #define T_MR		9		/* mail rename name */
    148  1.1  christos #define T_NULL		10		/* null resource record */
    149  1.1  christos #define T_WKS		11		/* well known service */
    150  1.1  christos #define T_PTR		12		/* domain name pointer */
    151  1.1  christos #define T_HINFO		13		/* host information */
    152  1.1  christos #define T_MINFO		14		/* mailbox information */
    153  1.1  christos #define T_MX		15		/* mail routing information */
    154  1.1  christos #define T_TXT		16		/* text strings */
    155  1.1  christos #define	T_RP		17		/* responsible person */
    156  1.1  christos #define	T_AFSDB		18		/* AFS cell database */
    157  1.1  christos #define T_X25		19		/* X_25 calling address */
    158  1.1  christos #define T_ISDN		20		/* ISDN calling address */
    159  1.1  christos #define T_RT		21		/* router */
    160  1.1  christos #define	T_NSAP		22		/* NSAP address */
    161  1.1  christos #define	T_NSAP_PTR	23		/* reverse lookup for NSAP */
    162  1.1  christos #define T_SIG		24		/* security signature */
    163  1.1  christos #define T_KEY		25		/* security key */
    164  1.1  christos #define T_PX		26		/* X.400 mail mapping */
    165  1.1  christos #define T_GPOS		27		/* geographical position (withdrawn) */
    166  1.1  christos #define T_AAAA		28		/* IP6 Address */
    167  1.1  christos #define T_LOC		29		/* Location Information */
    168  1.1  christos #define T_NXT		30		/* Next Valid Name in Zone */
    169  1.1  christos #define T_EID		31		/* Endpoint identifier */
    170  1.1  christos #define T_NIMLOC	32		/* Nimrod locator */
    171  1.1  christos #define T_SRV		33		/* Server selection */
    172  1.1  christos #define T_ATMA		34		/* ATM Address */
    173  1.1  christos #define T_NAPTR		35		/* Naming Authority PoinTeR */
    174  1.1  christos #define T_KX		36		/* Key Exchanger */
    175  1.1  christos #define T_CERT		37		/* Certificates in the DNS */
    176  1.1  christos #define T_A6		38		/* IP6 address */
    177  1.1  christos #define T_DNAME		39		/* non-terminal redirection */
    178  1.1  christos #define T_SINK		40		/* unknown */
    179  1.1  christos #define T_OPT		41		/* EDNS0 option (meta-RR) */
    180  1.1  christos #define T_APL		42		/* lists of address prefixes */
    181  1.1  christos #define T_DS		43		/* Delegation Signer */
    182  1.1  christos #define T_SSHFP		44		/* SSH Fingerprint */
    183  1.1  christos #define T_IPSECKEY	45		/* IPsec keying material */
    184  1.1  christos #define T_RRSIG		46		/* new security signature */
    185  1.1  christos #define T_NSEC		47		/* provable insecure information */
    186  1.1  christos #define T_DNSKEY	48		/* new security key */
    187  1.1  christos 	/* non standard */
    188  1.1  christos #define T_SPF		99		/* sender policy framework */
    189  1.1  christos #define T_UINFO		100		/* user (finger) information */
    190  1.1  christos #define T_UID		101		/* user ID */
    191  1.1  christos #define T_GID		102		/* group ID */
    192  1.1  christos #define T_UNSPEC	103		/* Unspecified format (binary data) */
    193  1.1  christos #define T_UNSPECA	104		/* "unspecified ascii". Ugly MIT hack */
    194  1.1  christos 	/* Query type values which do not appear in resource records */
    195  1.1  christos #define T_TKEY		249		/* Transaction Key [RFC2930] */
    196  1.1  christos #define T_TSIG		250		/* Transaction Signature [RFC2845] */
    197  1.1  christos #define T_IXFR		251		/* incremental transfer [RFC1995] */
    198  1.1  christos #define T_AXFR		252		/* transfer zone of authority */
    199  1.1  christos #define T_MAILB		253		/* transfer mailbox records */
    200  1.1  christos #define T_MAILA		254		/* transfer mail agent records */
    201  1.1  christos #define T_ANY		255		/* wildcard match */
    202  1.1  christos 
    203  1.1  christos /*
    204  1.1  christos  * Values for class field
    205  1.1  christos  */
    206  1.1  christos 
    207  1.1  christos #define C_IN		1		/* the arpa internet */
    208  1.1  christos #define C_CHAOS		3		/* for chaos net (MIT) */
    209  1.1  christos #define C_HS		4		/* for Hesiod name server (MIT) (XXX) */
    210  1.1  christos 	/* Query class values which do not appear in resource records */
    211  1.1  christos #define C_ANY		255		/* wildcard match */
    212  1.1  christos #define C_QU		0x8000		/* mDNS QU flag in queries */
    213  1.1  christos #define C_CACHE_FLUSH	0x8000		/* mDNS cache flush flag in replies */
    214  1.1  christos 
    215  1.1  christos /*
    216  1.1  christos  * Status return codes for T_UNSPEC conversion routines
    217  1.1  christos  */
    218  1.1  christos #define CONV_SUCCESS 0
    219  1.1  christos #define CONV_OVERFLOW -1
    220  1.1  christos #define CONV_BADFMT -2
    221  1.1  christos #define CONV_BADCKSUM -3
    222  1.1  christos #define CONV_BADBUFLEN -4
    223  1.1  christos 
    224  1.1  christos /*
    225  1.1  christos  * Structure for query header.
    226  1.1  christos  */
    227  1.1  christos typedef struct {
    228  1.1  christos 	u_int16_t id;		/* query identification number */
    229  1.1  christos 	u_int8_t  flags1;	/* first byte of flags */
    230  1.1  christos 	u_int8_t  flags2;	/* second byte of flags */
    231  1.1  christos 	u_int16_t qdcount;	/* number of question entries */
    232  1.1  christos 	u_int16_t ancount;	/* number of answer entries */
    233  1.1  christos 	u_int16_t nscount;	/* number of authority entries */
    234  1.1  christos 	u_int16_t arcount;	/* number of resource entries */
    235  1.1  christos } HEADER;
    236  1.1  christos 
    237  1.1  christos /*
    238  1.1  christos  * Macros for subfields of flag fields.
    239  1.1  christos  */
    240  1.1  christos #define DNS_QR(np)	((np)->flags1 & 0x80)		/* response flag */
    241  1.1  christos #define DNS_OPCODE(np)	((((np)->flags1) >> 3) & 0xF)	/* purpose of message */
    242  1.1  christos #define DNS_AA(np)	((np)->flags1 & 0x04)		/* authoritative answer */
    243  1.1  christos #define DNS_TC(np)	((np)->flags1 & 0x02)		/* truncated message */
    244  1.1  christos #define DNS_RD(np)	((np)->flags1 & 0x01)		/* recursion desired */
    245  1.1  christos 
    246  1.1  christos #define DNS_RA(np)	((np)->flags2 & 0x80)	/* recursion available */
    247  1.1  christos #define DNS_AD(np)	((np)->flags2 & 0x20)	/* authentic data from named */
    248  1.1  christos #define DNS_CD(np)	((np)->flags2 & 0x10)	/* checking disabled by resolver */
    249  1.1  christos #define DNS_RCODE(np)	((np)->flags2 & 0xF)	/* response code */
    250  1.1  christos 
    251  1.1  christos /*
    252  1.1  christos  * Defines for handling compressed domain names, EDNS0 labels, etc.
    253  1.1  christos  */
    254  1.1  christos #define INDIR_MASK	0xc0	/* 11.... */
    255  1.1  christos #define EDNS0_MASK	0x40	/* 01.... */
    256  1.1  christos #  define EDNS0_ELT_BITLABEL 0x01
    257  1.1  christos 
    258  1.1  christos /*
    259  1.1  christos  * Structure for passing resource records around.
    260  1.1  christos  */
    261  1.1  christos struct rrec {
    262  1.1  christos 	int16_t	r_zone;			/* zone number */
    263  1.1  christos 	int16_t	r_class;		/* class number */
    264  1.1  christos 	int16_t	r_type;			/* type number */
    265  1.1  christos 	u_int32_t	r_ttl;			/* time to live */
    266  1.1  christos 	int	r_size;			/* size of data area */
    267  1.1  christos 	char	*r_data;		/* pointer to data */
    268  1.1  christos };
    269  1.1  christos 
    270  1.1  christos /*
    271  1.1  christos  * Inline versions of get/put short/long.  Pointer is advanced.
    272  1.1  christos  * We also assume that a "u_int16_t" holds 2 "chars"
    273  1.1  christos  * and that a "u_int32_t" holds 4 "chars".
    274  1.1  christos  *
    275  1.1  christos  * These macros demonstrate the property of C whereby it can be
    276  1.1  christos  * portable or it can be elegant but never both.
    277  1.1  christos  */
    278  1.1  christos #define GETSHORT(s, cp) { \
    279  1.1  christos 	register u_char *t_cp = (u_char *)(cp); \
    280  1.1  christos 	(s) = ((u_int16_t)t_cp[0] << 8) | (u_int16_t)t_cp[1]; \
    281  1.1  christos 	(cp) += 2; \
    282  1.1  christos }
    283  1.1  christos 
    284  1.1  christos #define GETLONG(l, cp) { \
    285  1.1  christos 	register u_char *t_cp = (u_char *)(cp); \
    286  1.1  christos 	(l) = (((u_int32_t)t_cp[0]) << 24) \
    287  1.1  christos 	    | (((u_int32_t)t_cp[1]) << 16) \
    288  1.1  christos 	    | (((u_int32_t)t_cp[2]) << 8) \
    289  1.1  christos 	    | (((u_int32_t)t_cp[3])); \
    290  1.1  christos 	(cp) += 4; \
    291  1.1  christos }
    292  1.1  christos 
    293  1.1  christos #define PUTSHORT(s, cp) { \
    294  1.1  christos 	register u_int16_t t_s = (u_int16_t)(s); \
    295  1.1  christos 	register u_char *t_cp = (u_char *)(cp); \
    296  1.1  christos 	*t_cp++ = t_s >> 8; \
    297  1.1  christos 	*t_cp   = t_s; \
    298  1.1  christos 	(cp) += 2; \
    299  1.1  christos }
    300  1.1  christos 
    301  1.1  christos /*
    302  1.1  christos  * Warning: PUTLONG --no-longer-- destroys its first argument.  if you
    303  1.1  christos  * were depending on this "feature", you will lose.
    304  1.1  christos  */
    305  1.1  christos #define PUTLONG(l, cp) { \
    306  1.1  christos 	register u_int32_t t_l = (u_int32_t)(l); \
    307  1.1  christos 	register u_char *t_cp = (u_char *)(cp); \
    308  1.1  christos 	*t_cp++ = t_l >> 24; \
    309  1.1  christos 	*t_cp++ = t_l >> 16; \
    310  1.1  christos 	*t_cp++ = t_l >> 8; \
    311  1.1  christos 	*t_cp   = t_l; \
    312  1.1  christos 	(cp) += 4; \
    313  1.1  christos }
    314  1.1  christos 
    315  1.1  christos #endif /* !_NAMESER_H_ */
    316