Commit | Line | Data |
---|---|---|
bb0cfa24 DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
f4f66d2c | 3 | * All rights reserved. |
bb0cfa24 | 4 | * |
f4f66d2c KB |
5 | * Redistribution and use in source and binary forms are permitted |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
16 | * | |
5e4ee6d2 | 17 | * @(#)nameser.h 5.20 (Berkeley) %G% |
bb0cfa24 DF |
18 | */ |
19 | ||
af0a941b RC |
20 | /* |
21 | * Define constants based on rfc883 | |
22 | */ | |
23 | #define PACKETSZ 512 /* maximum packet size */ | |
24 | #define MAXDNAME 256 /* maximum domain name */ | |
25 | #define MAXCDNAME 255 /* maximum compressed domain name */ | |
26 | #define MAXLABEL 63 /* maximum length of domain label */ | |
27 | /* Number of bytes of fixed size data in query structure */ | |
28 | #define QFIXEDSZ 4 | |
29 | /* number of bytes of fixed size data in resource record */ | |
30 | #define RRFIXEDSZ 10 | |
31 | ||
c789adbd RC |
32 | /* |
33 | * Internet nameserver port number | |
34 | */ | |
35 | #define NAMESERVER_PORT 53 | |
36 | ||
af0a941b RC |
37 | /* |
38 | * Currently defined opcodes | |
39 | */ | |
ee6b5faf KD |
40 | #define QUERY 0x0 /* standard query */ |
41 | #define IQUERY 0x1 /* inverse query */ | |
7fce374b DK |
42 | #define STATUS 0x2 /* nameserver status query */ |
43 | /*#define xxx 0x3 /* 0x3 reserved */ | |
af0a941b | 44 | /* non standard */ |
9ea790ce KD |
45 | #define UPDATEA 0x9 /* add resource record */ |
46 | #define UPDATED 0xa /* delete a specific resource record */ | |
47 | #define UPDATEDA 0xb /* delete all nemed resource record */ | |
48 | #define UPDATEM 0xc /* modify a specific resource record */ | |
49 | #define UPDATEMA 0xd /* modify all named resource record */ | |
50 | ||
ee6b5faf KD |
51 | #define ZONEINIT 0xe /* initial zone transfer */ |
52 | #define ZONEREF 0xf /* incremental zone referesh */ | |
af0a941b RC |
53 | |
54 | /* | |
55 | * Currently defined response codes | |
56 | */ | |
57 | #define NOERROR 0 /* no error */ | |
58 | #define FORMERR 1 /* format error */ | |
59 | #define SERVFAIL 2 /* server failure */ | |
60 | #define NXDOMAIN 3 /* non existent domain */ | |
61 | #define NOTIMP 4 /* not implemented */ | |
62 | #define REFUSED 5 /* query refused */ | |
63 | /* non standard */ | |
ee6b5faf | 64 | #define NOCHANGE 0xf /* update failed to change db */ |
af0a941b RC |
65 | |
66 | /* | |
67 | * Type values for resources and queries | |
68 | */ | |
69 | #define T_A 1 /* host address */ | |
70 | #define T_NS 2 /* authoritative server */ | |
71 | #define T_MD 3 /* mail destination */ | |
72 | #define T_MF 4 /* mail forwarder */ | |
73 | #define T_CNAME 5 /* connonical name */ | |
74 | #define T_SOA 6 /* start of authority zone */ | |
75 | #define T_MB 7 /* mailbox domain name */ | |
76 | #define T_MG 8 /* mail group member */ | |
77 | #define T_MR 9 /* mail rename name */ | |
78 | #define T_NULL 10 /* null resource record */ | |
79 | #define T_WKS 11 /* well known service */ | |
80 | #define T_PTR 12 /* domain name pointer */ | |
81 | #define T_HINFO 13 /* host information */ | |
82 | #define T_MINFO 14 /* mailbox information */ | |
73546a32 | 83 | #define T_MX 15 /* mail routing information */ |
af0a941b | 84 | /* non standard */ |
d18857b8 KD |
85 | #define T_UINFO 100 /* user (finger) information */ |
86 | #define T_UID 101 /* user ID */ | |
87 | #define T_GID 102 /* group ID */ | |
9ea790ce | 88 | #define T_UNSPEC 103 /* Unspecified format (binary data) */ |
af0a941b RC |
89 | /* Query type values which do not appear in resource records */ |
90 | #define T_AXFR 252 /* transfer zone of authority */ | |
91 | #define T_MAILB 253 /* transfer mailbox records */ | |
92 | #define T_MAILA 254 /* transfer mail agent records */ | |
93 | #define T_ANY 255 /* wildcard match */ | |
94 | ||
95 | /* | |
96 | * Values for class field | |
97 | */ | |
98 | ||
99 | #define C_IN 1 /* the arpa internet */ | |
4ee0749d | 100 | #define C_CHAOS 3 /* for chaos net at MIT */ |
af0a941b RC |
101 | /* Query class values which do not appear in resource records */ |
102 | #define C_ANY 255 /* wildcard match */ | |
103 | ||
9ea790ce KD |
104 | /* |
105 | * Status return codes for T_UNSPEC conversion routines | |
106 | */ | |
107 | #define CONV_SUCCESS 0 | |
108 | #define CONV_OVERFLOW -1 | |
109 | #define CONV_BADFMT -2 | |
110 | #define CONV_BADCKSUM -3 | |
111 | #define CONV_BADBUFLEN -4 | |
112 | ||
d12659fb | 113 | #ifndef BYTE_ORDER |
452ae192 MK |
114 | #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax) */ |
115 | #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ | |
116 | #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */ | |
117 | ||
118 | #if defined(vax) || defined(ns32000) || defined(sun386) || \ | |
119 | defined(BIT_ZERO_ON_RIGHT) | |
d12659fb | 120 | #define BYTE_ORDER LITTLE_ENDIAN |
452ae192 | 121 | |
d12659fb | 122 | #endif |
452ae192 | 123 | #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \ |
d12659fb MK |
124 | defined(is68k) || defined (tahoe) || defined (BIT_ZERO_ON_LEFT) |
125 | #define BYTE_ORDER BIG_ENDIAN | |
126 | #endif | |
127 | #endif /* BYTE_ORDER */ | |
452ae192 | 128 | |
d12659fb MK |
129 | #ifndef BYTE_ORDER |
130 | /* you must determine what the correct bit order is for your compiler */ | |
131 | UNDEFINED_BIT_ORDER; | |
132 | #endif | |
af0a941b RC |
133 | /* |
134 | * Structure for query header, the order of the fields is machine and | |
135 | * compiler dependent, in our case, the bits within a byte are assignd | |
136 | * least significant first, while the order of transmition is most | |
137 | * significant first. This requires a somewhat confusing rearrangement. | |
138 | */ | |
139 | ||
140 | typedef struct { | |
141 | u_short id; /* query identification number */ | |
d12659fb | 142 | #if BYTE_ORDER == BIG_ENDIAN |
77c647f2 KD |
143 | /* fields in third byte */ |
144 | u_char qr:1; /* response flag */ | |
145 | u_char opcode:4; /* purpose of message */ | |
146 | u_char aa:1; /* authoritive answer */ | |
147 | u_char tc:1; /* truncated message */ | |
148 | u_char rd:1; /* recursion desired */ | |
4608f6ee | 149 | /* fields in fourth byte */ |
77c647f2 KD |
150 | u_char ra:1; /* recursion available */ |
151 | u_char pr:1; /* primary server required (non standard) */ | |
152 | u_char unused:2; /* unused bits */ | |
153 | u_char rcode:4; /* response code */ | |
d12659fb MK |
154 | #endif |
155 | #if BYTE_ORDER == LITTLE_ENDIAN | |
af0a941b RC |
156 | /* fields in third byte */ |
157 | u_char rd:1; /* recursion desired */ | |
158 | u_char tc:1; /* truncated message */ | |
159 | u_char aa:1; /* authoritive answer */ | |
160 | u_char opcode:4; /* purpose of message */ | |
161 | u_char qr:1; /* response flag */ | |
4608f6ee | 162 | /* fields in fourth byte */ |
af0a941b RC |
163 | u_char rcode:4; /* response code */ |
164 | u_char unused:2; /* unused bits */ | |
165 | u_char pr:1; /* primary server required (non standard) */ | |
166 | u_char ra:1; /* recursion available */ | |
77c647f2 | 167 | #endif |
af0a941b RC |
168 | /* remaining bytes */ |
169 | u_short qdcount; /* number of question entries */ | |
170 | u_short ancount; /* number of answer entries */ | |
171 | u_short nscount; /* number of authority entries */ | |
172 | u_short arcount; /* number of resource entries */ | |
173 | } HEADER; | |
174 | ||
175 | /* | |
176 | * Defines for handling compressed domain names | |
177 | */ | |
178 | #define INDIR_MASK 0xc0 | |
179 | ||
180 | /* | |
181 | * Structure for passing resource records around. | |
182 | */ | |
183 | struct rrec { | |
184 | short r_zone; /* zone number */ | |
185 | short r_class; /* class number */ | |
186 | short r_type; /* type number */ | |
187 | u_long r_ttl; /* time to live */ | |
188 | int r_size; /* size of data area */ | |
189 | char *r_data; /* pointer to data */ | |
190 | }; | |
fff51773 | 191 | |
5da53d29 KD |
192 | extern u_short _getshort(); |
193 | extern u_long _getlong(); | |
92a1935e MK |
194 | |
195 | /* | |
196 | * Inline versions of get/put short/long. | |
197 | * Pointer is advanced; we assume that both arguments | |
198 | * are lvalues and will already be in registers. | |
199 | * cp MUST be u_char *. | |
200 | */ | |
201 | #define GETSHORT(s, cp) { \ | |
202 | (s) = *(cp)++ << 8; \ | |
203 | (s) |= *(cp)++; \ | |
204 | } | |
205 | ||
206 | #define GETLONG(l, cp) { \ | |
207 | (l) = *(cp)++ << 8; \ | |
208 | (l) |= *(cp)++; (l) <<= 8; \ | |
209 | (l) |= *(cp)++; (l) <<= 8; \ | |
210 | (l) |= *(cp)++; \ | |
211 | } | |
212 | ||
213 | ||
214 | #define PUTSHORT(s, cp) { \ | |
215 | *(cp)++ = (s) >> 8; \ | |
216 | *(cp)++ = (s); \ | |
217 | } | |
218 | ||
219 | /* | |
220 | * Warning: PUTLONG destroys its first argument. | |
221 | */ | |
222 | #define PUTLONG(l, cp) { \ | |
223 | (cp)[3] = l; \ | |
224 | (cp)[2] = (l >>= 8); \ | |
225 | (cp)[1] = (l >>= 8); \ | |
226 | (cp)[0] = l >> 8; \ | |
227 | (cp) += sizeof(u_long); \ | |
228 | } |