xref: /illumos-gate/usr/src/lib/libresolv/arpa/nameser.h (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 #ifndef _ARPA_NAMESER_H
36 #define	_ARPA_NAMESER_H
37 
38 #include <sys/isa_defs.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Define constants based on rfc883
46  */
47 #define	PACKETSZ	512		/* maximum packet size */
48 #define	MAXDNAME	256		/* maximum domain name */
49 #define	MAXCDNAME	255		/* maximum compressed domain name */
50 #define	MAXLABEL	63		/* maximum length of domain label */
51 	/* Number of bytes of fixed size data in query structure */
52 #define	QFIXEDSZ	4
53 	/* number of bytes of fixed size data in resource record */
54 #define	RRFIXEDSZ	10
55 
56 /*
57  * Internet nameserver port number
58  */
59 #define	NAMESERVER_PORT	53
60 
61 /*
62  * Currently defined opcodes
63  */
64 #define	QUERY		0x0		/* standard query */
65 #define	IQUERY		0x1		/* inverse query */
66 #define	STATUS		0x2		/* nameserver status query */
67 /* #define	xxx		0x3 */	/* 0x3 reserved */
68 	/* non standard */
69 #define	UPDATEA		0x9		/* add resource record */
70 #define	UPDATED		0xa		/* delete a specific resource record */
71 #define	UPDATEDA	0xb		/* delete all nemed resource record */
72 #define	UPDATEM		0xc		/* modify a specific resource record */
73 #define	UPDATEMA	0xd		/* modify all named resource record */
74 
75 #define	ZONEINIT	0xe		/* initial zone transfer */
76 #define	ZONEREF		0xf		/* incremental zone referesh */
77 
78 /*
79  * Currently defined response codes
80  */
81 #define	NOERROR		0		/* no error */
82 #define	FORMERR		1		/* format error */
83 #define	SERVFAIL	2		/* server failure */
84 #define	NXDOMAIN	3		/* non existent domain */
85 #define	NOTIMP		4		/* not implemented */
86 #define	REFUSED		5		/* query refused */
87 	/* non standard */
88 #define	NOCHANGE	0xf		/* update failed to change db */
89 
90 /*
91  * Type values for resources and queries
92  */
93 #define	T_A		1		/* host address */
94 #define	T_NS		2		/* authoritative server */
95 #define	T_MD		3		/* mail destination */
96 #define	T_MF		4		/* mail forwarder */
97 #define	T_CNAME		5		/* connonical name */
98 #define	T_SOA		6		/* start of authority zone */
99 #define	T_MB		7		/* mailbox domain name */
100 #define	T_MG		8		/* mail group member */
101 #define	T_MR		9		/* mail rename name */
102 #define	T_NULL		10		/* null resource record */
103 #define	T_WKS		11		/* well known service */
104 #define	T_PTR		12		/* domain name pointer */
105 #define	T_HINFO		13		/* host information */
106 #define	T_MINFO		14		/* mailbox information */
107 #define	T_MX		15		/* mail routing information */
108 #define	T_TXT		16		/* text strings */
109 	/* non standard */
110 #define	T_UINFO		100		/* user (finger) information */
111 #define	T_UID		101		/* user ID */
112 #define	T_GID		102		/* group ID */
113 #define	T_UNSPEC	103		/* Unspecified format (binary data) */
114 	/* Query type values which do not appear in resource records */
115 #define	T_AXFR		252		/* transfer zone of authority */
116 #define	T_MAILB		253		/* transfer mailbox records */
117 #define	T_MAILA		254		/* transfer mail agent records */
118 #define	T_ANY		255		/* wildcard match */
119 
120 /*
121  * Values for class field
122  */
123 
124 #define	C_IN		1		/* the arpa internet */
125 #define	C_CHAOS		3		/* for chaos net at MIT */
126 #define	C_HS		4		/* for Hesiod name server at MIT */
127 	/* Query class values which do not appear in resource records */
128 #define	C_ANY		255		/* wildcard match */
129 
130 /*
131  * Status return codes for T_UNSPEC conversion routines
132  */
133 #define	CONV_SUCCESS 0
134 #define	CONV_OVERFLOW -1
135 #define	CONV_BADFMT -2
136 #define	CONV_BADCKSUM -3
137 #define	CONV_BADBUFLEN -4
138 
139 /*
140  * Structure for query header, the order of the fields is machine and
141  * compiler dependent, in our case, the bits within a byte are assignd
142  * least significant first, while the order of transmition is most
143  * significant first.  This requires a somewhat confusing rearrangement.
144  */
145 
146 typedef struct {
147 	u_short	id;		/* query identification number */
148 #if defined(_BIT_FIELDS_HTOL) || defined(BIT_ZERO_ON_LEFT)
149 	/* Bit zero on left:  SPARC and similar architectures */
150 			/* fields in third byte */
151 	u_char	qr:1;		/* response flag */
152 	u_char	opcode:4;	/* purpose of message */
153 	u_char	aa:1;		/* authoritive answer */
154 	u_char	tc:1;		/* truncated message */
155 	u_char	rd:1;		/* recursion desired */
156 			/* fields in fourth byte */
157 	u_char	ra:1;		/* recursion available */
158 	u_char	pr:1;		/* primary server required (non standard) */
159 	u_char	unused:2;	/* unused bits */
160 	u_char	rcode:4;	/* response code */
161 #else
162 #if defined(_BIT_FIELDS_LTOH) || defined(BIT_ZERO_ON_RIGHT)
163 	/* Bit zero on right:  Intel x86 and similar architectures */
164 			/* fields in third byte */
165 	u_char	rd:1;		/* recursion desired */
166 	u_char	tc:1;		/* truncated message */
167 	u_char	aa:1;		/* authoritive answer */
168 	u_char	opcode:4;	/* purpose of message */
169 	u_char	qr:1;		/* response flag */
170 			/* fields in fourth byte */
171 	u_char	rcode:4;	/* response code */
172 	u_char	unused:2;	/* unused bits */
173 	u_char	pr:1;		/* primary server required (non standard) */
174 	u_char	ra:1;		/* recursion available */
175 #else
176 	/* you must determine what the correct bit order is for your compiler */
177 	UNDEFINED_BIT_ORDER;
178 #endif
179 #endif
180 			/* remaining bytes */
181 	u_short	qdcount;	/* number of question entries */
182 	u_short	ancount;	/* number of answer entries */
183 	u_short	nscount;	/* number of authority entries */
184 	u_short	arcount;	/* number of resource entries */
185 } HEADER;
186 
187 /*
188  * Defines for handling compressed domain names
189  */
190 #define	INDIR_MASK	0xc0
191 
192 /*
193  * Structure for passing resource records around.
194  */
195 struct rrec {
196 	short	r_zone;			/* zone number */
197 	short	r_class;		/* class number */
198 	short	r_type;			/* type number */
199 	u_long	r_ttl;			/* time to live */
200 	int	r_size;			/* size of data area */
201 	char	*r_data;		/* pointer to data */
202 };
203 
204 extern	u_short	_getshort();
205 extern	u_long	_getlong();
206 
207 /*
208  * Inline versions of get/put short/long.
209  * Pointer is advanced; we assume that both arguments
210  * are lvalues and will already be in registers.
211  * cp MUST be u_char *.
212  */
213 #define	GETSHORT(s, cp) { \
214 	(s) = *(cp)++ << 8; \
215 	(s) |= *(cp)++; \
216 }
217 
218 #define	GETLONG(l, cp) { \
219 	(l) = *(cp)++ << 8; \
220 	(l) |= *(cp)++; (l) <<= 8; \
221 	(l) |= *(cp)++; (l) <<= 8; \
222 	(l) |= *(cp)++; \
223 }
224 
225 
226 #define	PUTSHORT(s, cp) { \
227 	*(cp)++ = (s) >> 8; \
228 	*(cp)++ = (s); \
229 }
230 
231 /*
232  * Warning: PUTLONG destroys its first argument.
233  */
234 #define	PUTLONG(l, cp) { \
235 	(cp)[3] = l; \
236 	(cp)[2] = (l >>= 8); \
237 	(cp)[1] = (l >>= 8); \
238 	(cp)[0] = l >> 8; \
239 	(cp) += sizeof (u_long); \
240 }
241 
242 #ifdef	__cplusplus
243 }
244 #endif
245 
246 #endif /* _ARPA_NAMESER_H */
247