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