diff options
Diffstat (limited to 'src/lib/libc/net/res_debug.c')
-rw-r--r-- | src/lib/libc/net/res_debug.c | 1443 |
1 files changed, 1106 insertions, 337 deletions
diff --git a/src/lib/libc/net/res_debug.c b/src/lib/libc/net/res_debug.c index d841293f18..c2725395a0 100644 --- a/src/lib/libc/net/res_debug.c +++ b/src/lib/libc/net/res_debug.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* $NetBSD: res_debug.c,v 1.7 1995/02/25 06:20:56 cgd Exp $ */ | 1 | /* $OpenBSD: res_debug.c,v 1.9 1998/03/19 00:30:06 millert Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /* |
4 | * ++Copyright++ 1985, 1990, 1993 | ||
5 | * - | ||
4 | * Copyright (c) 1985, 1990, 1993 | 6 | * Copyright (c) 1985, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
6 | * | 8 | * |
7 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
9 | * are met: | 11 | * are met: |
@@ -50,174 +52,185 @@ | |||
50 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | 52 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
51 | * SOFTWARE. | 53 | * SOFTWARE. |
52 | * - | 54 | * - |
55 | * Portions Copyright (c) 1995 by International Business Machines, Inc. | ||
56 | * | ||
57 | * International Business Machines, Inc. (hereinafter called IBM) grants | ||
58 | * permission under its copyrights to use, copy, modify, and distribute this | ||
59 | * Software with or without fee, provided that the above copyright notice and | ||
60 | * all paragraphs of this notice appear in all copies, and that the name of IBM | ||
61 | * not be used in connection with the marketing of any product incorporating | ||
62 | * the Software or modifications thereof, without specific, written prior | ||
63 | * permission. | ||
64 | * | ||
65 | * To the extent it has a right to do so, IBM grants an immunity from suit | ||
66 | * under its patents, if any, for the use, sale or manufacture of products to | ||
67 | * the extent that such products are used for performing Domain Name System | ||
68 | * dynamic updates in TCP/IP networks by means of the Software. No immunity is | ||
69 | * granted for any product per se or for any other function of any product. | ||
70 | * | ||
71 | * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, | ||
72 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
73 | * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | ||
74 | * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | ||
75 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | ||
76 | * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | ||
53 | * --Copyright-- | 77 | * --Copyright-- |
54 | */ | 78 | */ |
55 | 79 | ||
56 | #if defined(LIBC_SCCS) && !defined(lint) | 80 | #if defined(LIBC_SCCS) && !defined(lint) |
57 | #if 0 | 81 | #if 0 |
58 | static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; | 82 | static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; |
83 | static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; | ||
59 | #else | 84 | #else |
60 | static char rcsid[] = "$NetBSD: res_debug.c,v 1.7 1995/02/25 06:20:56 cgd Exp $"; | 85 | static char rcsid[] = "$OpenBSD: res_debug.c,v 1.9 1998/03/19 00:30:06 millert Exp $"; |
61 | #endif | 86 | #endif |
62 | #endif /* LIBC_SCCS and not lint */ | 87 | #endif /* LIBC_SCCS and not lint */ |
63 | 88 | ||
64 | #include <sys/param.h> | 89 | #include <sys/param.h> |
90 | #include <sys/types.h> | ||
91 | #include <sys/socket.h> | ||
65 | #include <netinet/in.h> | 92 | #include <netinet/in.h> |
66 | #include <arpa/inet.h> | 93 | #include <arpa/inet.h> |
67 | #include <arpa/nameser.h> | 94 | #include <arpa/nameser.h> |
95 | |||
96 | #include <ctype.h> | ||
97 | #include <netdb.h> | ||
68 | #include <resolv.h> | 98 | #include <resolv.h> |
69 | #include <stdio.h> | 99 | #include <stdio.h> |
70 | #include <string.h> | 100 | #include <time.h> |
71 | 101 | ||
72 | void __fp_query(); | 102 | #include <stdlib.h> |
73 | char *__p_class(), *__p_time(), *__p_type(); | 103 | #include <string.h> |
74 | char *p_cdname(), *p_fqname(), *p_rr(); | ||
75 | static char *p_option __P((u_int32_t)); | ||
76 | |||
77 | char *_res_opcodes[] = { | ||
78 | "QUERY", | ||
79 | "IQUERY", | ||
80 | "CQUERYM", | ||
81 | "CQUERYU", | ||
82 | "4", | ||
83 | "5", | ||
84 | "6", | ||
85 | "7", | ||
86 | "8", | ||
87 | "UPDATEA", | ||
88 | "UPDATED", | ||
89 | "UPDATEDA", | ||
90 | "UPDATEM", | ||
91 | "UPDATEMA", | ||
92 | "ZONEINIT", | ||
93 | "ZONEREF", | ||
94 | }; | ||
95 | |||
96 | char *_res_resultcodes[] = { | ||
97 | "NOERROR", | ||
98 | "FORMERR", | ||
99 | "SERVFAIL", | ||
100 | "NXDOMAIN", | ||
101 | "NOTIMP", | ||
102 | "REFUSED", | ||
103 | "6", | ||
104 | "7", | ||
105 | "8", | ||
106 | "9", | ||
107 | "10", | ||
108 | "11", | ||
109 | "12", | ||
110 | "13", | ||
111 | "14", | ||
112 | "NOCHANGE", | ||
113 | }; | ||
114 | 104 | ||
115 | static char retbuf[16]; | 105 | extern const char *_res_opcodes[]; |
106 | extern const char *_res_resultcodes[]; | ||
116 | 107 | ||
117 | static char * | 108 | /* XXX: we should use getservbyport() instead. */ |
109 | static const char * | ||
118 | dewks(wks) | 110 | dewks(wks) |
119 | int wks; | 111 | int wks; |
120 | { | 112 | { |
113 | static char nbuf[20]; | ||
114 | |||
121 | switch (wks) { | 115 | switch (wks) { |
122 | case 5: return("rje"); | 116 | case 5: return "rje"; |
123 | case 7: return("echo"); | 117 | case 7: return "echo"; |
124 | case 9: return("discard"); | 118 | case 9: return "discard"; |
125 | case 11: return("systat"); | 119 | case 11: return "systat"; |
126 | case 13: return("daytime"); | 120 | case 13: return "daytime"; |
127 | case 15: return("netstat"); | 121 | case 15: return "netstat"; |
128 | case 17: return("qotd"); | 122 | case 17: return "qotd"; |
129 | case 19: return("chargen"); | 123 | case 19: return "chargen"; |
130 | case 20: return("ftp-data"); | 124 | case 20: return "ftp-data"; |
131 | case 21: return("ftp"); | 125 | case 21: return "ftp"; |
132 | case 23: return("telnet"); | 126 | case 23: return "telnet"; |
133 | case 25: return("smtp"); | 127 | case 25: return "smtp"; |
134 | case 37: return("time"); | 128 | case 37: return "time"; |
135 | case 39: return("rlp"); | 129 | case 39: return "rlp"; |
136 | case 42: return("name"); | 130 | case 42: return "name"; |
137 | case 43: return("whois"); | 131 | case 43: return "whois"; |
138 | case 53: return("domain"); | 132 | case 53: return "domain"; |
139 | case 57: return("apts"); | 133 | case 57: return "apts"; |
140 | case 59: return("apfs"); | 134 | case 59: return "apfs"; |
141 | case 67: return("bootps"); | 135 | case 67: return "bootps"; |
142 | case 68: return("bootpc"); | 136 | case 68: return "bootpc"; |
143 | case 69: return("tftp"); | 137 | case 69: return "tftp"; |
144 | case 77: return("rje"); | 138 | case 77: return "rje"; |
145 | case 79: return("finger"); | 139 | case 79: return "finger"; |
146 | case 87: return("link"); | 140 | case 87: return "link"; |
147 | case 95: return("supdup"); | 141 | case 95: return "supdup"; |
148 | case 100: return("newacct"); | 142 | case 100: return "newacct"; |
149 | case 101: return("hostnames"); | 143 | case 101: return "hostnames"; |
150 | case 102: return("iso-tsap"); | 144 | case 102: return "iso-tsap"; |
151 | case 103: return("x400"); | 145 | case 103: return "x400"; |
152 | case 104: return("x400-snd"); | 146 | case 104: return "x400-snd"; |
153 | case 105: return("csnet-ns"); | 147 | case 105: return "csnet-ns"; |
154 | case 109: return("pop-2"); | 148 | case 109: return "pop-2"; |
155 | case 111: return("sunrpc"); | 149 | case 111: return "sunrpc"; |
156 | case 113: return("auth"); | 150 | case 113: return "auth"; |
157 | case 115: return("sftp"); | 151 | case 115: return "sftp"; |
158 | case 117: return("uucp-path"); | 152 | case 117: return "uucp-path"; |
159 | case 119: return("nntp"); | 153 | case 119: return "nntp"; |
160 | case 121: return("erpc"); | 154 | case 121: return "erpc"; |
161 | case 123: return("ntp"); | 155 | case 123: return "ntp"; |
162 | case 133: return("statsrv"); | 156 | case 133: return "statsrv"; |
163 | case 136: return("profile"); | 157 | case 136: return "profile"; |
164 | case 144: return("NeWS"); | 158 | case 144: return "NeWS"; |
165 | case 161: return("snmp"); | 159 | case 161: return "snmp"; |
166 | case 162: return("snmp-trap"); | 160 | case 162: return "snmp-trap"; |
167 | case 170: return("print-srv"); | 161 | case 170: return "print-srv"; |
168 | default: (void) sprintf(retbuf, "%d", wks); return(retbuf); | 162 | default: (void) sprintf(nbuf, "%d", wks); return (nbuf); |
169 | } | 163 | } |
170 | } | 164 | } |
171 | 165 | ||
172 | static char * | 166 | /* XXX: we should use getprotobynumber() instead. */ |
167 | static const char * | ||
173 | deproto(protonum) | 168 | deproto(protonum) |
174 | int protonum; | 169 | int protonum; |
175 | { | 170 | { |
171 | static char nbuf[20]; | ||
172 | |||
176 | switch (protonum) { | 173 | switch (protonum) { |
177 | case 1: return("icmp"); | 174 | case 1: return "icmp"; |
178 | case 2: return("igmp"); | 175 | case 2: return "igmp"; |
179 | case 3: return("ggp"); | 176 | case 3: return "ggp"; |
180 | case 5: return("st"); | 177 | case 5: return "st"; |
181 | case 6: return("tcp"); | 178 | case 6: return "tcp"; |
182 | case 7: return("ucl"); | 179 | case 7: return "ucl"; |
183 | case 8: return("egp"); | 180 | case 8: return "egp"; |
184 | case 9: return("igp"); | 181 | case 9: return "igp"; |
185 | case 11: return("nvp-II"); | 182 | case 11: return "nvp-II"; |
186 | case 12: return("pup"); | 183 | case 12: return "pup"; |
187 | case 16: return("chaos"); | 184 | case 16: return "chaos"; |
188 | case 17: return("udp"); | 185 | case 17: return "udp"; |
189 | default: (void) sprintf(retbuf, "%d", protonum); return(retbuf); | 186 | default: (void) sprintf(nbuf, "%d", protonum); return (nbuf); |
190 | } | 187 | } |
191 | } | 188 | } |
192 | 189 | ||
193 | static char * | 190 | static const u_char * |
194 | do_rrset(msg, cp, cnt, pflag, file, hs) | 191 | do_rrset(msg, len, cp, cnt, pflag, file, hs) |
195 | int cnt, pflag; | 192 | int cnt, pflag, len; |
196 | char *cp,*msg, *hs; | 193 | const u_char *cp, *msg; |
194 | const char *hs; | ||
197 | FILE *file; | 195 | FILE *file; |
198 | { | 196 | { |
199 | int n; | 197 | int n; |
200 | int sflag; | 198 | int sflag; |
199 | |||
201 | /* | 200 | /* |
202 | * Print answer records | 201 | * Print answer records. |
203 | */ | 202 | */ |
204 | sflag = (_res.pfcode & pflag); | 203 | sflag = (_res.pfcode & pflag); |
205 | if (n = ntohs(cnt)) { | 204 | if ((n = ntohs(cnt))) { |
206 | if ((!_res.pfcode) || ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | 205 | if ((!_res.pfcode) || |
206 | ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | ||
207 | fprintf(file, hs); | 207 | fprintf(file, hs); |
208 | while (--n >= 0) { | 208 | while (--n >= 0) { |
209 | cp = p_rr(cp, msg, file); | 209 | if ((!_res.pfcode) || sflag) { |
210 | if ((cp-msg) > PACKETSZ) | 210 | cp = p_rr(cp, msg, file); |
211 | } else { | ||
212 | unsigned int dlen; | ||
213 | cp += __dn_skipname(cp, cp + MAXCDNAME); | ||
214 | cp += INT16SZ; | ||
215 | cp += INT16SZ; | ||
216 | cp += INT32SZ; | ||
217 | dlen = _getshort((u_char*)cp); | ||
218 | cp += INT16SZ; | ||
219 | cp += dlen; | ||
220 | } | ||
221 | if ((cp - msg) > len) | ||
211 | return (NULL); | 222 | return (NULL); |
212 | } | 223 | } |
213 | if ((!_res.pfcode) || ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | 224 | if ((!_res.pfcode) || |
225 | ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) | ||
214 | putc('\n', file); | 226 | putc('\n', file); |
215 | } | 227 | } |
216 | return(cp); | 228 | return (cp); |
217 | } | 229 | } |
218 | 230 | ||
231 | void | ||
219 | __p_query(msg) | 232 | __p_query(msg) |
220 | char *msg; | 233 | const u_char *msg; |
221 | { | 234 | { |
222 | __fp_query(msg, stdout); | 235 | __fp_query(msg, stdout); |
223 | } | 236 | } |
@@ -231,15 +244,14 @@ __fp_resstat(statp, file) | |||
231 | struct __res_state *statp; | 244 | struct __res_state *statp; |
232 | FILE *file; | 245 | FILE *file; |
233 | { | 246 | { |
234 | int bit; | 247 | register u_long mask; |
235 | 248 | ||
236 | fprintf(file, ";; res options:"); | 249 | fprintf(file, ";; res options:"); |
237 | if (!statp) | 250 | if (!statp) |
238 | statp = &_res; | 251 | statp = &_res; |
239 | for (bit = 0; bit < 32; bit++) { /* XXX 32 - bad assumption! */ | 252 | for (mask = 1; mask != 0; mask <<= 1) |
240 | if (statp->options & (1<<bit)) | 253 | if (statp->options & mask) |
241 | fprintf(file, " %s", p_option(1<<bit)); | 254 | fprintf(file, " %s", p_option(mask)); |
242 | } | ||
243 | putc('\n', file); | 255 | putc('\n', file); |
244 | } | 256 | } |
245 | 257 | ||
@@ -248,109 +260,151 @@ __fp_resstat(statp, file) | |||
248 | * This is intended to be primarily a debugging routine. | 260 | * This is intended to be primarily a debugging routine. |
249 | */ | 261 | */ |
250 | void | 262 | void |
251 | __fp_query(msg,file) | 263 | __fp_nquery(msg, len, file) |
252 | char *msg; | 264 | const u_char *msg; |
265 | int len; | ||
253 | FILE *file; | 266 | FILE *file; |
254 | { | 267 | { |
255 | register char *cp; | 268 | register const u_char *cp, *endMark; |
256 | register HEADER *hp; | 269 | register const HEADER *hp; |
257 | register int n; | 270 | register int n; |
258 | 271 | ||
272 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | ||
273 | return; | ||
274 | |||
275 | #define TruncTest(x) if (x > endMark) goto trunc | ||
276 | #define ErrorTest(x) if (x == NULL) goto error | ||
277 | |||
259 | /* | 278 | /* |
260 | * Print header fields. | 279 | * Print header fields. |
261 | */ | 280 | */ |
262 | hp = (HEADER *)msg; | 281 | hp = (HEADER *)msg; |
263 | cp = msg + sizeof(HEADER); | 282 | cp = msg + HFIXEDSZ; |
283 | endMark = msg + len; | ||
264 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) { | 284 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) { |
265 | fprintf(file,";; ->>HEADER<<- opcode: %s, status: %s, id: %d", | 285 | fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d", |
266 | _res_opcodes[hp->opcode], | 286 | _res_opcodes[hp->opcode], |
267 | _res_resultcodes[hp->rcode], | 287 | _res_resultcodes[hp->rcode], |
268 | ntohs(hp->id)); | 288 | ntohs(hp->id)); |
269 | putc('\n', file); | 289 | putc('\n', file); |
270 | } | 290 | } |
271 | putc(';', file); | 291 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) |
292 | putc(';', file); | ||
272 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { | 293 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { |
273 | fprintf(file,"; flags:"); | 294 | fprintf(file, "; flags:"); |
274 | if (hp->qr) | 295 | if (hp->qr) |
275 | fprintf(file," qr"); | 296 | fprintf(file, " qr"); |
276 | if (hp->aa) | 297 | if (hp->aa) |
277 | fprintf(file," aa"); | 298 | fprintf(file, " aa"); |
278 | if (hp->tc) | 299 | if (hp->tc) |
279 | fprintf(file," tc"); | 300 | fprintf(file, " tc"); |
280 | if (hp->rd) | 301 | if (hp->rd) |
281 | fprintf(file," rd"); | 302 | fprintf(file, " rd"); |
282 | if (hp->ra) | 303 | if (hp->ra) |
283 | fprintf(file," ra"); | 304 | fprintf(file, " ra"); |
284 | if (hp->pr) | 305 | if (hp->unused) |
285 | fprintf(file," pr"); | 306 | fprintf(file, " UNUSED-BIT-ON"); |
307 | if (hp->ad) | ||
308 | fprintf(file, " ad"); | ||
309 | if (hp->cd) | ||
310 | fprintf(file, " cd"); | ||
286 | } | 311 | } |
287 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { | 312 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { |
288 | fprintf(file,"; Ques: %d", ntohs(hp->qdcount)); | 313 | fprintf(file, "; Ques: %d", ntohs(hp->qdcount)); |
289 | fprintf(file,", Ans: %d", ntohs(hp->ancount)); | 314 | fprintf(file, ", Ans: %d", ntohs(hp->ancount)); |
290 | fprintf(file,", Auth: %d", ntohs(hp->nscount)); | 315 | fprintf(file, ", Auth: %d", ntohs(hp->nscount)); |
291 | fprintf(file,", Addit: %d\n", ntohs(hp->arcount)); | 316 | fprintf(file, ", Addit: %d", ntohs(hp->arcount)); |
292 | } | 317 | } |
293 | #if 0 | 318 | if ((!_res.pfcode) || (_res.pfcode & |
294 | if (_res.pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1)) { | 319 | (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { |
295 | putc('\n',file); | 320 | putc('\n',file); |
296 | } | 321 | } |
297 | #endif | ||
298 | /* | 322 | /* |
299 | * Print question records. | 323 | * Print question records. |
300 | */ | 324 | */ |
301 | if (n = ntohs(hp->qdcount)) { | 325 | if ((n = ntohs(hp->qdcount))) { |
302 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 326 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
303 | fprintf(file,";; QUESTIONS:\n"); | 327 | fprintf(file, ";; QUESTIONS:\n"); |
304 | while (--n >= 0) { | 328 | while (--n >= 0) { |
305 | fprintf(file,";;\t"); | 329 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
306 | cp = p_cdname(cp, msg, file); | 330 | fprintf(file, ";;\t"); |
307 | if (cp == NULL) | 331 | TruncTest(cp); |
308 | return; | 332 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
333 | cp = p_cdnname(cp, msg, len, file); | ||
334 | else { | ||
335 | int n; | ||
336 | char name[MAXDNAME]; | ||
337 | |||
338 | if ((n = dn_expand(msg, msg+len, cp, name, | ||
339 | sizeof name)) < 0) | ||
340 | cp = NULL; | ||
341 | else | ||
342 | cp += n; | ||
343 | } | ||
344 | ErrorTest(cp); | ||
345 | TruncTest(cp); | ||
309 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 346 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
310 | fprintf(file, ", type = %s", | 347 | fprintf(file, ", type = %s", |
311 | __p_type(_getshort(cp))); | 348 | __p_type(_getshort((u_char*)cp))); |
312 | cp += sizeof(u_int16_t); | 349 | cp += INT16SZ; |
350 | TruncTest(cp); | ||
313 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | 351 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) |
314 | fprintf(file, ", class = %s\n\n", | 352 | fprintf(file, ", class = %s\n", |
315 | __p_class(_getshort(cp))); | 353 | __p_class(_getshort((u_char*)cp))); |
316 | cp += sizeof(u_int16_t); | 354 | cp += INT16SZ; |
355 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) | ||
356 | putc('\n', file); | ||
317 | } | 357 | } |
318 | } | 358 | } |
319 | /* | 359 | /* |
320 | * Print authoritative answer records | 360 | * Print authoritative answer records |
321 | */ | 361 | */ |
322 | cp = do_rrset(msg, cp, hp->ancount, RES_PRF_ANS, file, | 362 | TruncTest(cp); |
363 | cp = do_rrset(msg, len, cp, hp->ancount, RES_PRF_ANS, file, | ||
323 | ";; ANSWERS:\n"); | 364 | ";; ANSWERS:\n"); |
324 | if (cp == NULL) | 365 | ErrorTest(cp); |
325 | return; | ||
326 | 366 | ||
327 | /* | 367 | /* |
328 | * print name server records | 368 | * print name server records |
329 | */ | 369 | */ |
330 | cp = do_rrset(msg, cp, hp->nscount, RES_PRF_AUTH, file, | 370 | TruncTest(cp); |
371 | cp = do_rrset(msg, len, cp, hp->nscount, RES_PRF_AUTH, file, | ||
331 | ";; AUTHORITY RECORDS:\n"); | 372 | ";; AUTHORITY RECORDS:\n"); |
332 | if (!cp) | 373 | ErrorTest(cp); |
333 | return; | ||
334 | 374 | ||
375 | TruncTest(cp); | ||
335 | /* | 376 | /* |
336 | * print additional records | 377 | * print additional records |
337 | */ | 378 | */ |
338 | cp = do_rrset(msg, cp, hp->arcount, RES_PRF_ADD, file, | 379 | cp = do_rrset(msg, len, cp, hp->arcount, RES_PRF_ADD, file, |
339 | ";; ADDITIONAL RECORDS:\n"); | 380 | ";; ADDITIONAL RECORDS:\n"); |
340 | if (!cp) | 381 | ErrorTest(cp); |
341 | return; | 382 | return; |
383 | trunc: | ||
384 | fprintf(file, "\n;; ...truncated\n"); | ||
385 | return; | ||
386 | error: | ||
387 | fprintf(file, "\n;; ...malformed\n"); | ||
342 | } | 388 | } |
343 | 389 | ||
344 | char * | 390 | void |
345 | p_cdname(cp, msg, file) | 391 | __fp_query(msg, file) |
346 | char *cp, *msg; | 392 | const u_char *msg; |
393 | FILE *file; | ||
394 | { | ||
395 | fp_nquery(msg, PACKETSZ, file); | ||
396 | } | ||
397 | |||
398 | const u_char * | ||
399 | __p_cdnname(cp, msg, len, file) | ||
400 | const u_char *cp, *msg; | ||
401 | int len; | ||
347 | FILE *file; | 402 | FILE *file; |
348 | { | 403 | { |
349 | char name[MAXDNAME]; | 404 | char name[MAXDNAME]; |
350 | int n; | 405 | int n; |
351 | 406 | ||
352 | if ((n = dn_expand((u_char *)msg, (u_char *)cp + MAXCDNAME, | 407 | if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0) |
353 | (u_char *)cp, (u_char *)name, sizeof(name))) < 0) | ||
354 | return (NULL); | 408 | return (NULL); |
355 | if (name[0] == '\0') | 409 | if (name[0] == '\0') |
356 | putc('.', file); | 410 | putc('.', file); |
@@ -359,54 +413,94 @@ p_cdname(cp, msg, file) | |||
359 | return (cp + n); | 413 | return (cp + n); |
360 | } | 414 | } |
361 | 415 | ||
362 | char * | 416 | const u_char * |
363 | p_fqname(cp, msg, file) | 417 | __p_cdname(cp, msg, file) |
364 | char *cp, *msg; | 418 | const u_char *cp, *msg; |
365 | FILE *file; | 419 | FILE *file; |
366 | { | 420 | { |
367 | char name[MAXDNAME]; | 421 | return (p_cdnname(cp, msg, PACKETSZ, file)); |
368 | int n, len; | 422 | } |
369 | 423 | ||
370 | if ((n = dn_expand((u_char *)msg, (u_char *)cp + MAXCDNAME, | 424 | |
371 | (u_char *)cp, (u_char *)name, sizeof(name))) < 0) | 425 | /* Return a fully-qualified domain name from a compressed name (with |
426 | length supplied). */ | ||
427 | |||
428 | const u_char * | ||
429 | __p_fqnname(cp, msg, msglen, name, namelen) | ||
430 | const u_char *cp, *msg; | ||
431 | int msglen; | ||
432 | char *name; | ||
433 | int namelen; | ||
434 | { | ||
435 | int n, newlen; | ||
436 | |||
437 | if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) | ||
372 | return (NULL); | 438 | return (NULL); |
373 | if (name[0] == '\0') { | 439 | newlen = strlen (name); |
374 | putc('.', file); | 440 | if (newlen == 0 || name[newlen - 1] != '.') { |
375 | } else { | 441 | if (newlen+1 >= namelen) /* Lack space for final dot */ |
376 | fputs(name, file); | 442 | return (NULL); |
377 | if (name[strlen(name) - 1] != '.') | 443 | else |
378 | putc('.', file); | 444 | strcpy(name + newlen, "."); |
379 | } | 445 | } |
380 | return (cp + n); | 446 | return (cp + n); |
381 | } | 447 | } |
382 | 448 | ||
449 | /* XXX: the rest of these functions need to become length-limited, too. (vix) | ||
450 | */ | ||
451 | |||
452 | const u_char * | ||
453 | __p_fqname(cp, msg, file) | ||
454 | const u_char *cp, *msg; | ||
455 | FILE *file; | ||
456 | { | ||
457 | char name[MAXDNAME]; | ||
458 | const u_char *n; | ||
459 | |||
460 | n = __p_fqnname(cp, msg, MAXCDNAME, name, sizeof name); | ||
461 | if (n == NULL) | ||
462 | return (NULL); | ||
463 | fputs(name, file); | ||
464 | return (n); | ||
465 | } | ||
466 | |||
383 | /* | 467 | /* |
384 | * Print resource record fields in human readable form. | 468 | * Print resource record fields in human readable form. |
385 | */ | 469 | */ |
386 | char * | 470 | const u_char * |
387 | p_rr(cp, msg, file) | 471 | __p_rr(cp, msg, file) |
388 | char *cp, *msg; | 472 | const u_char *cp, *msg; |
389 | FILE *file; | 473 | FILE *file; |
390 | { | 474 | { |
391 | int type, class, dlen, n, c; | 475 | int type, class, dlen, n, c; |
392 | struct in_addr inaddr; | 476 | struct in_addr inaddr; |
393 | char *cp1, *cp2; | 477 | const u_char *cp1, *cp2; |
394 | u_int32_t tmpttl, t; | 478 | u_int32_t tmpttl, t; |
395 | int lcnt; | 479 | int lcnt; |
480 | u_int16_t keyflags; | ||
481 | char rrname[MAXDNAME]; /* The fqdn of this RR */ | ||
482 | char base64_key[MAX_KEY_BASE64]; | ||
396 | 483 | ||
397 | if ((cp = p_fqname(cp, msg, file)) == NULL) | 484 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { |
485 | h_errno = NETDB_INTERNAL; | ||
486 | return (NULL); | ||
487 | } | ||
488 | cp = __p_fqnname(cp, msg, MAXCDNAME, rrname, sizeof rrname); | ||
489 | if (!cp) | ||
398 | return (NULL); /* compression error */ | 490 | return (NULL); /* compression error */ |
399 | type = _getshort(cp); | 491 | fputs(rrname, file); |
400 | cp += sizeof(u_int16_t); | 492 | |
401 | class = _getshort(cp); | 493 | type = _getshort((u_char*)cp); |
402 | cp += sizeof(u_int16_t); | 494 | cp += INT16SZ; |
403 | tmpttl = _getlong(cp); | 495 | class = _getshort((u_char*)cp); |
404 | cp += sizeof(u_int32_t); | 496 | cp += INT16SZ; |
405 | dlen = _getshort(cp); | 497 | tmpttl = _getlong((u_char*)cp); |
406 | cp += sizeof(u_int16_t); | 498 | cp += INT32SZ; |
499 | dlen = _getshort((u_char*)cp); | ||
500 | cp += INT16SZ; | ||
407 | cp1 = cp; | 501 | cp1 = cp; |
408 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID)) | 502 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID)) |
409 | fprintf(file, "\t%lu", tmpttl); | 503 | fprintf(file, "\t%lu", (u_long)tmpttl); |
410 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS)) | 504 | if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS)) |
411 | fprintf(file, "\t%s", __p_class(class)); | 505 | fprintf(file, "\t%s", __p_class(class)); |
412 | fprintf(file, "\t%s", __p_type(type)); | 506 | fprintf(file, "\t%s", __p_type(type)); |
@@ -418,21 +512,21 @@ p_rr(cp, msg, file) | |||
418 | switch (class) { | 512 | switch (class) { |
419 | case C_IN: | 513 | case C_IN: |
420 | case C_HS: | 514 | case C_HS: |
421 | bcopy(cp, (char *)&inaddr, sizeof(inaddr)); | 515 | bcopy(cp, (char *)&inaddr, INADDRSZ); |
422 | if (dlen == 4) { | 516 | if (dlen == 4) { |
423 | fprintf(file,"\t%s", inet_ntoa(inaddr)); | 517 | fprintf(file, "\t%s", inet_ntoa(inaddr)); |
424 | cp += dlen; | 518 | cp += dlen; |
425 | } else if (dlen == 7) { | 519 | } else if (dlen == 7) { |
426 | char *address; | 520 | char *address; |
427 | u_char protocol; | 521 | u_char protocol; |
428 | u_short port; | 522 | in_port_t port; |
429 | 523 | ||
430 | address = inet_ntoa(inaddr); | 524 | address = inet_ntoa(inaddr); |
431 | cp += sizeof(inaddr); | 525 | cp += INADDRSZ; |
432 | protocol = *(u_char*)cp; | 526 | protocol = *(u_char*)cp; |
433 | cp += sizeof(u_char); | 527 | cp += sizeof (u_char); |
434 | port = _getshort(cp); | 528 | port = _getshort((u_char*)cp); |
435 | cp += sizeof(u_int16_t); | 529 | cp += INT16SZ; |
436 | fprintf(file, "\t%s\t; proto %d, port %d", | 530 | fprintf(file, "\t%s\t; proto %d, port %d", |
437 | address, protocol, port); | 531 | address, protocol, port); |
438 | } | 532 | } |
@@ -448,98 +542,205 @@ p_rr(cp, msg, file) | |||
448 | case T_NS: | 542 | case T_NS: |
449 | case T_PTR: | 543 | case T_PTR: |
450 | putc('\t', file); | 544 | putc('\t', file); |
451 | cp = p_fqname(cp, msg, file); | 545 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
546 | return (NULL); | ||
452 | break; | 547 | break; |
453 | 548 | ||
454 | case T_HINFO: | 549 | case T_HINFO: |
455 | if (n = *cp++) { | 550 | case T_ISDN: |
456 | fprintf(file,"\t%.*s", n, cp); | 551 | cp2 = cp + dlen; |
457 | cp += n; | 552 | (void) fputs("\t\"", file); |
553 | if ((n = (unsigned char) *cp++) != 0) { | ||
554 | for (c = n; c > 0 && cp < cp2; c--) { | ||
555 | if (strchr("\n\"\\", *cp)) | ||
556 | (void) putc('\\', file); | ||
557 | (void) putc(*cp++, file); | ||
558 | } | ||
458 | } | 559 | } |
459 | if (n = *cp++) { | 560 | putc('"', file); |
460 | fprintf(file,"\t%.*s", n, cp); | 561 | if (cp < cp2 && (n = (unsigned char) *cp++) != 0) { |
461 | cp += n; | 562 | (void) fputs ("\t\"", file); |
563 | for (c = n; c > 0 && cp < cp2; c--) { | ||
564 | if (strchr("\n\"\\", *cp)) | ||
565 | (void) putc('\\', file); | ||
566 | (void) putc(*cp++, file); | ||
567 | } | ||
568 | putc('"', file); | ||
569 | } else if (type == T_HINFO) { | ||
570 | (void) fputs("\"?\"", file); | ||
571 | fprintf(file, "\n;; *** Warning *** OS-type missing"); | ||
462 | } | 572 | } |
463 | break; | 573 | break; |
464 | 574 | ||
465 | case T_SOA: | 575 | case T_SOA: |
466 | putc('\t', file); | 576 | putc('\t', file); |
467 | cp = p_fqname(cp, msg, file); /* origin */ | 577 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
578 | return (NULL); | ||
468 | putc(' ', file); | 579 | putc(' ', file); |
469 | cp = p_fqname(cp, msg, file); /* mail addr */ | 580 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
581 | return (NULL); | ||
470 | fputs(" (\n", file); | 582 | fputs(" (\n", file); |
471 | t = _getlong(cp); cp += sizeof(u_int32_t); | 583 | t = _getlong((u_char*)cp); cp += INT32SZ; |
472 | fprintf(file,"\t\t\t%lu\t; serial\n", t); | 584 | fprintf(file, "\t\t\t%lu\t; serial\n", (u_long)t); |
473 | t = _getlong(cp); cp += sizeof(u_int32_t); | 585 | t = _getlong((u_char*)cp); cp += INT32SZ; |
474 | fprintf(file,"\t\t\t%lu\t; refresh (%s)\n", t, __p_time(t)); | 586 | fprintf(file, "\t\t\t%lu\t; refresh (%s)\n", |
475 | t = _getlong(cp); cp += sizeof(u_int32_t); | 587 | (u_long)t, __p_time(t)); |
476 | fprintf(file,"\t\t\t%lu\t; retry (%s)\n", t, __p_time(t)); | 588 | t = _getlong((u_char*)cp); cp += INT32SZ; |
477 | t = _getlong(cp); cp += sizeof(u_int32_t); | 589 | fprintf(file, "\t\t\t%lu\t; retry (%s)\n", |
478 | fprintf(file,"\t\t\t%lu\t; expire (%s)\n", t, __p_time(t)); | 590 | (u_long)t, __p_time(t)); |
479 | t = _getlong(cp); cp += sizeof(u_int32_t); | 591 | t = _getlong((u_char*)cp); cp += INT32SZ; |
480 | fprintf(file,"\t\t\t%lu )\t; minimum (%s)", t, __p_time(t)); | 592 | fprintf(file, "\t\t\t%lu\t; expire (%s)\n", |
593 | (u_long)t, __p_time(t)); | ||
594 | t = _getlong((u_char*)cp); cp += INT32SZ; | ||
595 | fprintf(file, "\t\t\t%lu )\t; minimum (%s)", | ||
596 | (u_long)t, __p_time(t)); | ||
481 | break; | 597 | break; |
482 | 598 | ||
483 | case T_MX: | 599 | case T_MX: |
484 | case T_AFSDB: | 600 | case T_AFSDB: |
485 | fprintf(file,"\t%d ", _getshort(cp)); | 601 | case T_RT: |
486 | cp += sizeof(u_int16_t); | 602 | fprintf(file, "\t%d ", _getshort((u_char*)cp)); |
487 | cp = p_fqname(cp, msg, file); | 603 | cp += INT16SZ; |
604 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
605 | return (NULL); | ||
606 | break; | ||
607 | |||
608 | case T_PX: | ||
609 | fprintf(file, "\t%d ", _getshort((u_char*)cp)); | ||
610 | cp += INT16SZ; | ||
611 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
612 | return (NULL); | ||
613 | putc(' ', file); | ||
614 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
615 | return (NULL); | ||
488 | break; | 616 | break; |
489 | 617 | ||
490 | case T_TXT: | 618 | case T_X25: |
619 | cp2 = cp + dlen; | ||
491 | (void) fputs("\t\"", file); | 620 | (void) fputs("\t\"", file); |
621 | if ((n = (unsigned char) *cp++) != 0) { | ||
622 | for (c = n; c > 0 && cp < cp2; c--) { | ||
623 | if (strchr("\n\"\\", *cp)) | ||
624 | (void) putc('\\', file); | ||
625 | (void) putc(*cp++, file); | ||
626 | } | ||
627 | } | ||
628 | putc('"', file); | ||
629 | break; | ||
630 | |||
631 | case T_TXT: | ||
632 | (void) putc('\t', file); | ||
492 | cp2 = cp1 + dlen; | 633 | cp2 = cp1 + dlen; |
493 | while (cp < cp2) { | 634 | while (cp < cp2) { |
494 | if (n = (unsigned char) *cp++) { | 635 | putc('"', file); |
495 | for (c = n; c > 0 && cp < cp2; c--) | 636 | if ((n = (unsigned char) *cp++)) { |
496 | if (*cp == '\n') { | 637 | for (c = n; c > 0 && cp < cp2; c--) { |
497 | (void) putc('\\', file); | 638 | if (strchr("\n\"\\", *cp)) |
498 | (void) putc(*cp++, file); | 639 | (void) putc('\\', file); |
499 | } else | 640 | (void) putc(*cp++, file); |
500 | (void) putc(*cp++, file); | 641 | } |
501 | } | 642 | } |
643 | putc('"', file); | ||
644 | if (cp < cp2) | ||
645 | putc(' ', file); | ||
502 | } | 646 | } |
503 | putc('"', file); | 647 | break; |
504 | break; | 648 | |
649 | case T_NSAP: | ||
650 | (void) fprintf(file, "\t%s", inet_nsap_ntoa(dlen, cp, NULL)); | ||
651 | cp += dlen; | ||
652 | break; | ||
653 | |||
654 | case T_AAAA: { | ||
655 | char t[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; | ||
656 | |||
657 | fprintf(file, "\t%s", inet_ntop(AF_INET6, cp, t, sizeof t)); | ||
658 | cp += dlen; | ||
659 | break; | ||
660 | } | ||
661 | |||
662 | case T_LOC: { | ||
663 | char t[255]; | ||
664 | |||
665 | fprintf(file, "\t%s", loc_ntoa(cp, t)); | ||
666 | cp += dlen; | ||
667 | break; | ||
668 | } | ||
669 | |||
670 | case T_NAPTR: { | ||
671 | u_int order, preference; | ||
672 | |||
673 | order = _getshort(cp); cp += INT16SZ; | ||
674 | preference = _getshort(cp); cp += INT16SZ; | ||
675 | fprintf(file, "\t%u %u ",order, preference); | ||
676 | /* Flags */ | ||
677 | n = *cp++; | ||
678 | fprintf(file,"\"%.*s\" ", (int)n, cp); | ||
679 | cp += n; | ||
680 | /* Service */ | ||
681 | n = *cp++; | ||
682 | fprintf(file,"\"%.*s\" ", (int)n, cp); | ||
683 | cp += n; | ||
684 | /* Regexp */ | ||
685 | n = *cp++; | ||
686 | fprintf(file,"\"%.*s\" ", (int)n, cp); | ||
687 | cp += n; | ||
688 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
689 | return (NULL); | ||
690 | break; | ||
691 | } | ||
692 | |||
693 | case T_SRV: { | ||
694 | u_int priority, weight, port; | ||
695 | |||
696 | priority = _getshort(cp); cp += INT16SZ; | ||
697 | weight = _getshort(cp); cp += INT16SZ; | ||
698 | port = _getshort(cp); cp += INT16SZ; | ||
699 | fprintf(file, "\t%u %u %u ", priority, weight, port); | ||
700 | if ((cp = p_fqname(cp, msg, file)) == NULL) | ||
701 | return (NULL); | ||
702 | break; | ||
703 | } | ||
505 | 704 | ||
506 | case T_MINFO: | 705 | case T_MINFO: |
507 | case T_RP: | 706 | case T_RP: |
508 | putc('\t', file); | 707 | putc('\t', file); |
509 | cp = p_fqname(cp, msg, file); | 708 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
709 | return (NULL); | ||
510 | putc(' ', file); | 710 | putc(' ', file); |
511 | cp = p_fqname(cp, msg, file); | 711 | if ((cp = p_fqname(cp, msg, file)) == NULL) |
712 | return (NULL); | ||
512 | break; | 713 | break; |
513 | 714 | ||
514 | case T_UINFO: | 715 | case T_UINFO: |
515 | putc('\t', file); | 716 | putc('\t', file); |
516 | fputs(cp, file); | 717 | fputs((char *)cp, file); |
517 | cp += dlen; | 718 | cp += dlen; |
518 | break; | 719 | break; |
519 | 720 | ||
520 | case T_UID: | 721 | case T_UID: |
521 | case T_GID: | 722 | case T_GID: |
522 | if (dlen == 4) { | 723 | if (dlen == 4) { |
523 | fprintf(file,"\t%u", _getlong(cp)); | 724 | fprintf(file, "\t%u", _getlong((u_char*)cp)); |
524 | cp += sizeof(int32_t); | 725 | cp += INT32SZ; |
525 | } | 726 | } |
526 | break; | 727 | break; |
527 | 728 | ||
528 | case T_WKS: | 729 | case T_WKS: |
529 | if (dlen < sizeof(u_int32_t) + 1) | 730 | if (dlen < INT32SZ + 1) |
530 | break; | 731 | break; |
531 | bcopy(cp, (char *)&inaddr, sizeof(inaddr)); | 732 | bcopy(cp, (char *)&inaddr, INADDRSZ); |
532 | cp += sizeof(u_int32_t); | 733 | cp += INT32SZ; |
533 | fprintf(file, "\t%s %s ( ", | 734 | fprintf(file, "\t%s %s ( ", |
534 | inet_ntoa(inaddr), | 735 | inet_ntoa(inaddr), |
535 | deproto((int) *cp)); | 736 | deproto((int) *cp)); |
536 | cp += sizeof(u_char); | 737 | cp += sizeof (u_char); |
537 | n = 0; | 738 | n = 0; |
538 | lcnt = 0; | 739 | lcnt = 0; |
539 | while (cp < cp1 + dlen) { | 740 | while (cp < cp1 + dlen) { |
540 | c = *cp++; | 741 | c = *cp++; |
541 | do { | 742 | do { |
542 | if (c & 0200) { | 743 | if (c & 0200) { |
543 | if (lcnt == 0) { | 744 | if (lcnt == 0) { |
544 | fputs("\n\t\t\t", file); | 745 | fputs("\n\t\t\t", file); |
545 | lcnt = 5; | 746 | lcnt = 5; |
@@ -548,17 +749,83 @@ p_rr(cp, msg, file) | |||
548 | putc(' ', file); | 749 | putc(' ', file); |
549 | lcnt--; | 750 | lcnt--; |
550 | } | 751 | } |
551 | c <<= 1; | 752 | c <<= 1; |
552 | } while (++n & 07); | 753 | } while (++n & 07); |
553 | } | 754 | } |
554 | putc(')', file); | 755 | putc(')', file); |
555 | break; | 756 | break; |
556 | 757 | ||
758 | case T_KEY: | ||
759 | putc('\t', file); | ||
760 | keyflags = _getshort(cp); | ||
761 | cp += 2; | ||
762 | fprintf(file,"0x%04x", keyflags ); /* flags */ | ||
763 | fprintf(file," %u", *cp++); /* protocol */ | ||
764 | fprintf(file," %u (", *cp++); /* algorithm */ | ||
765 | |||
766 | n = b64_ntop(cp, (cp1 + dlen) - cp, | ||
767 | base64_key, sizeof base64_key); | ||
768 | for (c = 0; c < n; ++c) { | ||
769 | if (0 == (c & 0x3F)) | ||
770 | fprintf(file, "\n\t"); | ||
771 | putc(base64_key[c], file); /* public key data */ | ||
772 | } | ||
773 | |||
774 | fprintf(file, " )"); | ||
775 | if (n < 0) | ||
776 | fprintf(file, "\t; BAD BASE64"); | ||
777 | fflush(file); | ||
778 | cp = cp1 + dlen; | ||
779 | break; | ||
780 | |||
781 | case T_SIG: | ||
782 | type = _getshort((u_char*)cp); | ||
783 | cp += INT16SZ; | ||
784 | fprintf(file, " %s", p_type(type)); | ||
785 | fprintf(file, "\t%d", *cp++); /* algorithm */ | ||
786 | /* Check label value and print error if wrong. */ | ||
787 | n = *cp++; | ||
788 | c = dn_count_labels (rrname); | ||
789 | if (n != c) | ||
790 | fprintf(file, "\t; LABELS WRONG (%d should be %d)\n\t", | ||
791 | n, c); | ||
792 | /* orig ttl */ | ||
793 | n = _getlong((u_char*)cp); | ||
794 | if (n != tmpttl) | ||
795 | fprintf(file, " %u", n); | ||
796 | cp += INT32SZ; | ||
797 | /* sig expire */ | ||
798 | fprintf(file, " (\n\t%s", | ||
799 | __p_secstodate(_getlong((u_char*)cp))); | ||
800 | cp += INT32SZ; | ||
801 | /* time signed */ | ||
802 | fprintf(file, " %s", __p_secstodate(_getlong((u_char*)cp))); | ||
803 | cp += INT32SZ; | ||
804 | /* sig footprint */ | ||
805 | fprintf(file," %u ", _getshort((u_char*)cp)); | ||
806 | cp += INT16SZ; | ||
807 | /* signer's name */ | ||
808 | cp = p_fqname(cp, msg, file); | ||
809 | n = b64_ntop(cp, (cp1 + dlen) - cp, | ||
810 | base64_key, sizeof base64_key); | ||
811 | for (c = 0; c < n; c++) { | ||
812 | if (0 == (c & 0x3F)) | ||
813 | fprintf (file, "\n\t"); | ||
814 | putc(base64_key[c], file); /* signature */ | ||
815 | } | ||
816 | /* Clean up... */ | ||
817 | fprintf(file, " )"); | ||
818 | if (n < 0) | ||
819 | fprintf(file, "\t; BAD BASE64"); | ||
820 | fflush(file); | ||
821 | cp = cp1+dlen; | ||
822 | break; | ||
823 | |||
557 | #ifdef ALLOW_T_UNSPEC | 824 | #ifdef ALLOW_T_UNSPEC |
558 | case T_UNSPEC: | 825 | case T_UNSPEC: |
559 | { | 826 | { |
560 | int NumBytes = 8; | 827 | int NumBytes = 8; |
561 | char *DataPtr; | 828 | u_char *DataPtr; |
562 | int i; | 829 | int i; |
563 | 830 | ||
564 | if (dlen < NumBytes) NumBytes = dlen; | 831 | if (dlen < NumBytes) NumBytes = dlen; |
@@ -572,7 +839,7 @@ p_rr(cp, msg, file) | |||
572 | #endif /* ALLOW_T_UNSPEC */ | 839 | #endif /* ALLOW_T_UNSPEC */ |
573 | 840 | ||
574 | default: | 841 | default: |
575 | fprintf(file,"\t?%d?", type); | 842 | fprintf(file, "\t?%d?", type); |
576 | cp += dlen; | 843 | cp += dlen; |
577 | } | 844 | } |
578 | #if 0 | 845 | #if 0 |
@@ -581,136 +848,205 @@ p_rr(cp, msg, file) | |||
581 | putc('\n', file); | 848 | putc('\n', file); |
582 | #endif | 849 | #endif |
583 | if (cp - cp1 != dlen) { | 850 | if (cp - cp1 != dlen) { |
584 | fprintf(file,";; packet size error (found %d, dlen was %d)\n", | 851 | fprintf(file, ";; packet size error (found %ld, dlen was %d)\n", |
585 | cp - cp1, dlen); | 852 | (long)(cp - cp1), dlen); |
586 | cp = NULL; | 853 | cp = NULL; |
587 | } | 854 | } |
588 | return (cp); | 855 | return (cp); |
589 | } | 856 | } |
590 | 857 | ||
591 | static char nbuf[40]; | 858 | /* |
859 | * Names of RR classes and qclasses. Classes and qclasses are the same, except | ||
860 | * that C_ANY is a qclass but not a class. (You can ask for records of class | ||
861 | * C_ANY, but you can't have any records of that class in the database.) | ||
862 | */ | ||
863 | const struct res_sym __p_class_syms[] = { | ||
864 | {C_IN, "IN"}, | ||
865 | {C_CHAOS, "CHAOS"}, | ||
866 | {C_HS, "HS"}, | ||
867 | {C_HS, "HESIOD"}, | ||
868 | {C_ANY, "ANY"}, | ||
869 | {C_IN, (char *)0} | ||
870 | }; | ||
592 | 871 | ||
593 | /* | 872 | /* |
594 | * Return a string for the type | 873 | * Names of RR types and qtypes. Types and qtypes are the same, except |
874 | * that T_ANY is a qtype but not a type. (You can ask for records of type | ||
875 | * T_ANY, but you can't have any records of that type in the database.) | ||
595 | */ | 876 | */ |
596 | char * | 877 | const struct res_sym __p_type_syms[] = { |
597 | __p_type(type) | 878 | {T_A, "A", "address"}, |
598 | int type; | 879 | {T_NS, "NS", "name server"}, |
599 | { | 880 | {T_MD, "MD", "mail destination (deprecated)"}, |
600 | switch (type) { | 881 | {T_MF, "MF", "mail forwarder (deprecated)"}, |
601 | case T_A: | 882 | {T_CNAME, "CNAME", "canonical name"}, |
602 | return("A"); | 883 | {T_SOA, "SOA", "start of authority"}, |
603 | case T_NS: /* authoritative server */ | 884 | {T_MB, "MB", "mailbox"}, |
604 | return("NS"); | 885 | {T_MG, "MG", "mail group member"}, |
605 | case T_CNAME: /* canonical name */ | 886 | {T_MR, "MR", "mail rename"}, |
606 | return("CNAME"); | 887 | {T_NULL, "NULL", "null"}, |
607 | case T_SOA: /* start of authority zone */ | 888 | {T_WKS, "WKS", "well-known service (deprecated)"}, |
608 | return("SOA"); | 889 | {T_PTR, "PTR", "domain name pointer"}, |
609 | case T_MB: /* mailbox domain name */ | 890 | {T_HINFO, "HINFO", "host information"}, |
610 | return("MB"); | 891 | {T_MINFO, "MINFO", "mailbox information"}, |
611 | case T_MG: /* mail group member */ | 892 | {T_MX, "MX", "mail exchanger"}, |
612 | return("MG"); | 893 | {T_TXT, "TXT", "text"}, |
613 | case T_MR: /* mail rename name */ | 894 | {T_RP, "RP", "responsible person"}, |
614 | return("MR"); | 895 | {T_AFSDB, "AFSDB", "DCE or AFS server"}, |
615 | case T_NULL: /* null resource record */ | 896 | {T_X25, "X25", "X25 address"}, |
616 | return("NULL"); | 897 | {T_ISDN, "ISDN", "ISDN address"}, |
617 | case T_WKS: /* well known service */ | 898 | {T_RT, "RT", "router"}, |
618 | return("WKS"); | 899 | {T_NSAP, "NSAP", "nsap address"}, |
619 | case T_PTR: /* domain name pointer */ | 900 | {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"}, |
620 | return("PTR"); | 901 | {T_SIG, "SIG", "signature"}, |
621 | case T_HINFO: /* host information */ | 902 | {T_KEY, "KEY", "key"}, |
622 | return("HINFO"); | 903 | {T_PX, "PX", "mapping information"}, |
623 | case T_MINFO: /* mailbox information */ | 904 | {T_GPOS, "GPOS", "geographical position (withdrawn)"}, |
624 | return("MINFO"); | 905 | {T_AAAA, "AAAA", "IPv6 address"}, |
625 | case T_MX: /* mail routing info */ | 906 | {T_LOC, "LOC", "location"}, |
626 | return("MX"); | 907 | {T_NXT, "NXT", "next valid name (unimplemented)"}, |
627 | case T_TXT: /* text */ | 908 | {T_EID, "EID", "endpoint identifier (unimplemented)"}, |
628 | return("TXT"); | 909 | {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"}, |
629 | case T_RP: /* responsible person */ | 910 | {T_SRV, "SRV", "server selection"}, |
630 | return("RP"); | 911 | {T_ATMA, "ATMA", "ATM address (unimplemented)"}, |
631 | case T_AFSDB: /* AFS cell database */ | 912 | {T_IXFR, "IXFR", "incremental zone transfer"}, |
632 | return("AFSDB"); | 913 | {T_AXFR, "AXFR", "zone transfer"}, |
633 | case T_AXFR: /* zone transfer */ | 914 | {T_MAILB, "MAILB", "mailbox-related data (deprecated)"}, |
634 | return("AXFR"); | 915 | {T_MAILA, "MAILA", "mail agent (deprecated)"}, |
635 | case T_MAILB: /* mail box */ | 916 | {T_UINFO, "UINFO", "user information (nonstandard)"}, |
636 | return("MAILB"); | 917 | {T_UID, "UID", "user ID (nonstandard)"}, |
637 | case T_MAILA: /* mail address */ | 918 | {T_GID, "GID", "group ID (nonstandard)"}, |
638 | return("MAILA"); | 919 | {T_NAPTR, "NAPTR", "URN Naming Authority"}, |
639 | case T_ANY: /* matches any type */ | ||
640 | return("ANY"); | ||
641 | case T_UINFO: | ||
642 | return("UINFO"); | ||
643 | case T_UID: | ||
644 | return("UID"); | ||
645 | case T_GID: | ||
646 | return("GID"); | ||
647 | #ifdef ALLOW_T_UNSPEC | 920 | #ifdef ALLOW_T_UNSPEC |
648 | case T_UNSPEC: | 921 | {T_UNSPEC, "UNSPEC", "unspecified data (nonstandard)"}, |
649 | return("UNSPEC"); | ||
650 | #endif /* ALLOW_T_UNSPEC */ | 922 | #endif /* ALLOW_T_UNSPEC */ |
923 | {T_ANY, "ANY", "\"any\""}, | ||
924 | {0, NULL, NULL} | ||
925 | }; | ||
651 | 926 | ||
652 | default: | 927 | int |
653 | (void)sprintf(nbuf, "%d", type); | 928 | __sym_ston(syms, name, success) |
654 | return(nbuf); | 929 | const struct res_sym *syms; |
930 | char *name; | ||
931 | int *success; | ||
932 | { | ||
933 | for (; syms->name != 0; syms++) { | ||
934 | if (strcasecmp (name, syms->name) == 0) { | ||
935 | if (success) | ||
936 | *success = 1; | ||
937 | return (syms->number); | ||
938 | } | ||
939 | } | ||
940 | if (success) | ||
941 | *success = 0; | ||
942 | return (syms->number); /* The default value. */ | ||
943 | } | ||
944 | |||
945 | const char * | ||
946 | __sym_ntos(syms, number, success) | ||
947 | const struct res_sym *syms; | ||
948 | int number; | ||
949 | int *success; | ||
950 | { | ||
951 | static char unname[20]; | ||
952 | |||
953 | for (; syms->name != 0; syms++) { | ||
954 | if (number == syms->number) { | ||
955 | if (success) | ||
956 | *success = 1; | ||
957 | return (syms->name); | ||
958 | } | ||
959 | } | ||
960 | |||
961 | sprintf (unname, "%d", number); | ||
962 | if (success) | ||
963 | *success = 0; | ||
964 | return (unname); | ||
965 | } | ||
966 | |||
967 | |||
968 | const char * | ||
969 | __sym_ntop(syms, number, success) | ||
970 | const struct res_sym *syms; | ||
971 | int number; | ||
972 | int *success; | ||
973 | { | ||
974 | static char unname[20]; | ||
975 | |||
976 | for (; syms->name != 0; syms++) { | ||
977 | if (number == syms->number) { | ||
978 | if (success) | ||
979 | *success = 1; | ||
980 | return (syms->humanname); | ||
981 | } | ||
655 | } | 982 | } |
983 | sprintf(unname, "%d", number); | ||
984 | if (success) | ||
985 | *success = 0; | ||
986 | return (unname); | ||
987 | } | ||
988 | |||
989 | /* | ||
990 | * Return a string for the type | ||
991 | */ | ||
992 | const char * | ||
993 | __p_type(type) | ||
994 | int type; | ||
995 | { | ||
996 | return (__sym_ntos (__p_type_syms, type, (int *)0)); | ||
656 | } | 997 | } |
657 | 998 | ||
658 | /* | 999 | /* |
659 | * Return a mnemonic for class | 1000 | * Return a mnemonic for class |
660 | */ | 1001 | */ |
661 | char * | 1002 | const char * |
662 | __p_class(class) | 1003 | __p_class(class) |
663 | int class; | 1004 | int class; |
664 | { | 1005 | { |
665 | 1006 | return (__sym_ntos (__p_class_syms, class, (int *)0)); | |
666 | switch (class) { | ||
667 | case C_IN: /* internet class */ | ||
668 | return("IN"); | ||
669 | case C_HS: /* hesiod class */ | ||
670 | return("HS"); | ||
671 | case C_ANY: /* matches any class */ | ||
672 | return("ANY"); | ||
673 | default: | ||
674 | (void)sprintf(nbuf, "%d", class); | ||
675 | return(nbuf); | ||
676 | } | ||
677 | } | 1007 | } |
678 | 1008 | ||
679 | /* | 1009 | /* |
680 | * Return a mnemonic for an option | 1010 | * Return a mnemonic for an option |
681 | */ | 1011 | */ |
682 | static char * | 1012 | const char * |
683 | p_option(option) | 1013 | __p_option(option) |
684 | u_int32_t option; | 1014 | u_long option; |
685 | { | 1015 | { |
1016 | static char nbuf[40]; | ||
1017 | |||
686 | switch (option) { | 1018 | switch (option) { |
687 | case RES_INIT: return "init"; | 1019 | case RES_INIT: return "init"; |
688 | case RES_DEBUG: return "debug"; | 1020 | case RES_DEBUG: return "debug"; |
689 | case RES_AAONLY: return "aaonly"; | 1021 | case RES_AAONLY: return "aaonly(unimpl)"; |
690 | case RES_USEVC: return "usevc"; | 1022 | case RES_USEVC: return "usevc"; |
691 | case RES_PRIMARY: return "primry"; | 1023 | case RES_PRIMARY: return "primry(unimpl)"; |
692 | case RES_IGNTC: return "igntc"; | 1024 | case RES_IGNTC: return "igntc"; |
693 | case RES_RECURSE: return "recurs"; | 1025 | case RES_RECURSE: return "recurs"; |
694 | case RES_DEFNAMES: return "defnam"; | 1026 | case RES_DEFNAMES: return "defnam"; |
695 | case RES_STAYOPEN: return "styopn"; | 1027 | case RES_STAYOPEN: return "styopn"; |
696 | case RES_DNSRCH: return "dnsrch"; | 1028 | case RES_DNSRCH: return "dnsrch"; |
697 | default: sprintf(nbuf, "?0x%x?", option); return nbuf; | 1029 | case RES_INSECURE1: return "insecure1"; |
1030 | case RES_INSECURE2: return "insecure2"; | ||
1031 | default: sprintf(nbuf, "?0x%lx?", (u_long)option); | ||
1032 | return (nbuf); | ||
698 | } | 1033 | } |
699 | } | 1034 | } |
700 | 1035 | ||
701 | /* | 1036 | /* |
702 | * Return a mnemonic for a time to live | 1037 | * Return a mnemonic for a time to live |
703 | */ | 1038 | */ |
704 | char * | 1039 | const char * |
705 | __p_time(value) | 1040 | p_time(value) |
706 | u_int32_t value; | 1041 | u_int32_t value; |
707 | { | 1042 | { |
1043 | static char nbuf[40]; | ||
708 | int secs, mins, hours, days; | 1044 | int secs, mins, hours, days; |
709 | register char *p; | 1045 | register char *p; |
710 | 1046 | ||
711 | if (value == 0) { | 1047 | if (value == 0) { |
712 | strcpy(nbuf, "0 secs"); | 1048 | strcpy(nbuf, "0 secs"); |
713 | return(nbuf); | 1049 | return (nbuf); |
714 | } | 1050 | } |
715 | 1051 | ||
716 | secs = value % 60; | 1052 | secs = value % 60; |
@@ -745,5 +1081,438 @@ __p_time(value) | |||
745 | *p++ = ' '; | 1081 | *p++ = ' '; |
746 | (void)sprintf(p, "%d sec%s", PLURALIZE(secs)); | 1082 | (void)sprintf(p, "%d sec%s", PLURALIZE(secs)); |
747 | } | 1083 | } |
748 | return(nbuf); | 1084 | return (nbuf); |
1085 | } | ||
1086 | |||
1087 | /* | ||
1088 | * routines to convert between on-the-wire RR format and zone file format. | ||
1089 | * Does not contain conversion to/from decimal degrees; divide or multiply | ||
1090 | * by 60*60*1000 for that. | ||
1091 | */ | ||
1092 | |||
1093 | static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000, | ||
1094 | 1000000,10000000,100000000,1000000000}; | ||
1095 | |||
1096 | /* takes an XeY precision/size value, returns a string representation. */ | ||
1097 | static const char * | ||
1098 | precsize_ntoa(prec) | ||
1099 | u_int8_t prec; | ||
1100 | { | ||
1101 | static char retbuf[sizeof "90000000.00"]; | ||
1102 | unsigned long val; | ||
1103 | int mantissa, exponent; | ||
1104 | |||
1105 | mantissa = (int)((prec >> 4) & 0x0f) % 10; | ||
1106 | exponent = (int)((prec >> 0) & 0x0f) % 10; | ||
1107 | |||
1108 | val = mantissa * poweroften[exponent]; | ||
1109 | |||
1110 | (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100); | ||
1111 | return (retbuf); | ||
1112 | } | ||
1113 | |||
1114 | /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */ | ||
1115 | static u_int8_t | ||
1116 | precsize_aton(strptr) | ||
1117 | char **strptr; | ||
1118 | { | ||
1119 | unsigned int mval = 0, cmval = 0; | ||
1120 | u_int8_t retval = 0; | ||
1121 | register char *cp; | ||
1122 | register int exponent; | ||
1123 | register int mantissa; | ||
1124 | |||
1125 | cp = *strptr; | ||
1126 | |||
1127 | while (isdigit(*cp)) | ||
1128 | mval = mval * 10 + (*cp++ - '0'); | ||
1129 | |||
1130 | if (*cp == '.') { /* centimeters */ | ||
1131 | cp++; | ||
1132 | if (isdigit(*cp)) { | ||
1133 | cmval = (*cp++ - '0') * 10; | ||
1134 | if (isdigit(*cp)) { | ||
1135 | cmval += (*cp++ - '0'); | ||
1136 | } | ||
1137 | } | ||
1138 | } | ||
1139 | cmval = (mval * 100) + cmval; | ||
1140 | |||
1141 | for (exponent = 0; exponent < 9; exponent++) | ||
1142 | if (cmval < poweroften[exponent+1]) | ||
1143 | break; | ||
1144 | |||
1145 | mantissa = cmval / poweroften[exponent]; | ||
1146 | if (mantissa > 9) | ||
1147 | mantissa = 9; | ||
1148 | |||
1149 | retval = (mantissa << 4) | exponent; | ||
1150 | |||
1151 | *strptr = cp; | ||
1152 | |||
1153 | return (retval); | ||
1154 | } | ||
1155 | |||
1156 | /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */ | ||
1157 | static u_int32_t | ||
1158 | latlon2ul(latlonstrptr,which) | ||
1159 | char **latlonstrptr; | ||
1160 | int *which; | ||
1161 | { | ||
1162 | register char *cp; | ||
1163 | u_int32_t retval; | ||
1164 | int deg = 0, min = 0, secs = 0, secsfrac = 0; | ||
1165 | |||
1166 | cp = *latlonstrptr; | ||
1167 | |||
1168 | while (isdigit(*cp)) | ||
1169 | deg = deg * 10 + (*cp++ - '0'); | ||
1170 | |||
1171 | while (isspace(*cp)) | ||
1172 | cp++; | ||
1173 | |||
1174 | if (!(isdigit(*cp))) | ||
1175 | goto fndhemi; | ||
1176 | |||
1177 | while (isdigit(*cp)) | ||
1178 | min = min * 10 + (*cp++ - '0'); | ||
1179 | |||
1180 | while (isspace(*cp)) | ||
1181 | cp++; | ||
1182 | |||
1183 | if (!(isdigit(*cp))) | ||
1184 | goto fndhemi; | ||
1185 | |||
1186 | while (isdigit(*cp)) | ||
1187 | secs = secs * 10 + (*cp++ - '0'); | ||
1188 | |||
1189 | if (*cp == '.') { /* decimal seconds */ | ||
1190 | cp++; | ||
1191 | if (isdigit(*cp)) { | ||
1192 | secsfrac = (*cp++ - '0') * 100; | ||
1193 | if (isdigit(*cp)) { | ||
1194 | secsfrac += (*cp++ - '0') * 10; | ||
1195 | if (isdigit(*cp)) { | ||
1196 | secsfrac += (*cp++ - '0'); | ||
1197 | } | ||
1198 | } | ||
1199 | } | ||
1200 | } | ||
1201 | |||
1202 | while (!isspace(*cp)) /* if any trailing garbage */ | ||
1203 | cp++; | ||
1204 | |||
1205 | while (isspace(*cp)) | ||
1206 | cp++; | ||
1207 | |||
1208 | fndhemi: | ||
1209 | switch (*cp) { | ||
1210 | case 'N': case 'n': | ||
1211 | case 'E': case 'e': | ||
1212 | retval = ((unsigned)1<<31) | ||
1213 | + (((((deg * 60) + min) * 60) + secs) * 1000) | ||
1214 | + secsfrac; | ||
1215 | break; | ||
1216 | case 'S': case 's': | ||
1217 | case 'W': case 'w': | ||
1218 | retval = ((unsigned)1<<31) | ||
1219 | - (((((deg * 60) + min) * 60) + secs) * 1000) | ||
1220 | - secsfrac; | ||
1221 | break; | ||
1222 | default: | ||
1223 | retval = 0; /* invalid value -- indicates error */ | ||
1224 | break; | ||
1225 | } | ||
1226 | |||
1227 | switch (*cp) { | ||
1228 | case 'N': case 'n': | ||
1229 | case 'S': case 's': | ||
1230 | *which = 1; /* latitude */ | ||
1231 | break; | ||
1232 | case 'E': case 'e': | ||
1233 | case 'W': case 'w': | ||
1234 | *which = 2; /* longitude */ | ||
1235 | break; | ||
1236 | default: | ||
1237 | *which = 0; /* error */ | ||
1238 | break; | ||
1239 | } | ||
1240 | |||
1241 | cp++; /* skip the hemisphere */ | ||
1242 | |||
1243 | while (!isspace(*cp)) /* if any trailing garbage */ | ||
1244 | cp++; | ||
1245 | |||
1246 | while (isspace(*cp)) /* move to next field */ | ||
1247 | cp++; | ||
1248 | |||
1249 | *latlonstrptr = cp; | ||
1250 | |||
1251 | return (retval); | ||
1252 | } | ||
1253 | |||
1254 | /* converts a zone file representation in a string to an RDATA on-the-wire | ||
1255 | * representation. */ | ||
1256 | int | ||
1257 | loc_aton(ascii, binary) | ||
1258 | const char *ascii; | ||
1259 | u_char *binary; | ||
1260 | { | ||
1261 | const char *maxcp; | ||
1262 | u_char *bcp; | ||
1263 | char *cp; | ||
1264 | |||
1265 | u_int32_t latit = 0, longit = 0, alt = 0; | ||
1266 | u_int32_t lltemp1 = 0, lltemp2 = 0; | ||
1267 | int altmeters = 0, altfrac = 0, altsign = 1; | ||
1268 | u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */ | ||
1269 | u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */ | ||
1270 | u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */ | ||
1271 | int which1 = 0, which2 = 0; | ||
1272 | |||
1273 | cp = (char *)ascii; | ||
1274 | maxcp = cp + strlen(ascii); | ||
1275 | |||
1276 | lltemp1 = latlon2ul(&cp, &which1); | ||
1277 | |||
1278 | lltemp2 = latlon2ul(&cp, &which2); | ||
1279 | |||
1280 | switch (which1 + which2) { | ||
1281 | case 3: /* 1 + 2, the only valid combination */ | ||
1282 | if ((which1 == 1) && (which2 == 2)) { /* normal case */ | ||
1283 | latit = lltemp1; | ||
1284 | longit = lltemp2; | ||
1285 | } else if ((which1 == 2) && (which2 == 1)) { /* reversed */ | ||
1286 | longit = lltemp1; | ||
1287 | latit = lltemp2; | ||
1288 | } else { /* some kind of brokenness */ | ||
1289 | return (0); | ||
1290 | } | ||
1291 | break; | ||
1292 | default: /* we didn't get one of each */ | ||
1293 | return (0); | ||
1294 | } | ||
1295 | |||
1296 | /* altitude */ | ||
1297 | if (*cp == '-') { | ||
1298 | altsign = -1; | ||
1299 | cp++; | ||
1300 | } | ||
1301 | |||
1302 | if (*cp == '+') | ||
1303 | cp++; | ||
1304 | |||
1305 | while (isdigit(*cp)) | ||
1306 | altmeters = altmeters * 10 + (*cp++ - '0'); | ||
1307 | |||
1308 | if (*cp == '.') { /* decimal meters */ | ||
1309 | cp++; | ||
1310 | if (isdigit(*cp)) { | ||
1311 | altfrac = (*cp++ - '0') * 10; | ||
1312 | if (isdigit(*cp)) { | ||
1313 | altfrac += (*cp++ - '0'); | ||
1314 | } | ||
1315 | } | ||
1316 | } | ||
1317 | |||
1318 | alt = (10000000 + (altsign * (altmeters * 100 + altfrac))); | ||
1319 | |||
1320 | while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ | ||
1321 | cp++; | ||
1322 | |||
1323 | while (isspace(*cp) && (cp < maxcp)) | ||
1324 | cp++; | ||
1325 | |||
1326 | if (cp >= maxcp) | ||
1327 | goto defaults; | ||
1328 | |||
1329 | siz = precsize_aton(&cp); | ||
1330 | |||
1331 | while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ | ||
1332 | cp++; | ||
1333 | |||
1334 | while (isspace(*cp) && (cp < maxcp)) | ||
1335 | cp++; | ||
1336 | |||
1337 | if (cp >= maxcp) | ||
1338 | goto defaults; | ||
1339 | |||
1340 | hp = precsize_aton(&cp); | ||
1341 | |||
1342 | while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ | ||
1343 | cp++; | ||
1344 | |||
1345 | while (isspace(*cp) && (cp < maxcp)) | ||
1346 | cp++; | ||
1347 | |||
1348 | if (cp >= maxcp) | ||
1349 | goto defaults; | ||
1350 | |||
1351 | vp = precsize_aton(&cp); | ||
1352 | |||
1353 | defaults: | ||
1354 | |||
1355 | bcp = binary; | ||
1356 | *bcp++ = (u_int8_t) 0; /* version byte */ | ||
1357 | *bcp++ = siz; | ||
1358 | *bcp++ = hp; | ||
1359 | *bcp++ = vp; | ||
1360 | PUTLONG(latit,bcp); | ||
1361 | PUTLONG(longit,bcp); | ||
1362 | PUTLONG(alt,bcp); | ||
1363 | |||
1364 | return (16); /* size of RR in octets */ | ||
1365 | } | ||
1366 | |||
1367 | /* takes an on-the-wire LOC RR and formats it in a human readable format. */ | ||
1368 | const char * | ||
1369 | loc_ntoa(binary, ascii) | ||
1370 | const u_char *binary; | ||
1371 | char *ascii; | ||
1372 | { | ||
1373 | static char *error = "?"; | ||
1374 | register const u_char *cp = binary; | ||
1375 | |||
1376 | int latdeg, latmin, latsec, latsecfrac; | ||
1377 | int longdeg, longmin, longsec, longsecfrac; | ||
1378 | char northsouth, eastwest; | ||
1379 | int altmeters, altfrac, altsign; | ||
1380 | |||
1381 | const int referencealt = 100000 * 100; | ||
1382 | |||
1383 | int32_t latval, longval, altval; | ||
1384 | u_int32_t templ; | ||
1385 | u_int8_t sizeval, hpval, vpval, versionval; | ||
1386 | |||
1387 | char *sizestr, *hpstr, *vpstr; | ||
1388 | |||
1389 | versionval = *cp++; | ||
1390 | |||
1391 | if (versionval) { | ||
1392 | sprintf(ascii, "; error: unknown LOC RR version"); | ||
1393 | return (ascii); | ||
1394 | } | ||
1395 | |||
1396 | sizeval = *cp++; | ||
1397 | |||
1398 | hpval = *cp++; | ||
1399 | vpval = *cp++; | ||
1400 | |||
1401 | GETLONG(templ, cp); | ||
1402 | latval = (templ - ((unsigned)1<<31)); | ||
1403 | |||
1404 | GETLONG(templ, cp); | ||
1405 | longval = (templ - ((unsigned)1<<31)); | ||
1406 | |||
1407 | GETLONG(templ, cp); | ||
1408 | if (templ < referencealt) { /* below WGS 84 spheroid */ | ||
1409 | altval = referencealt - templ; | ||
1410 | altsign = -1; | ||
1411 | } else { | ||
1412 | altval = templ - referencealt; | ||
1413 | altsign = 1; | ||
1414 | } | ||
1415 | |||
1416 | if (latval < 0) { | ||
1417 | northsouth = 'S'; | ||
1418 | latval = -latval; | ||
1419 | } else | ||
1420 | northsouth = 'N'; | ||
1421 | |||
1422 | latsecfrac = latval % 1000; | ||
1423 | latval = latval / 1000; | ||
1424 | latsec = latval % 60; | ||
1425 | latval = latval / 60; | ||
1426 | latmin = latval % 60; | ||
1427 | latval = latval / 60; | ||
1428 | latdeg = latval; | ||
1429 | |||
1430 | if (longval < 0) { | ||
1431 | eastwest = 'W'; | ||
1432 | longval = -longval; | ||
1433 | } else | ||
1434 | eastwest = 'E'; | ||
1435 | |||
1436 | longsecfrac = longval % 1000; | ||
1437 | longval = longval / 1000; | ||
1438 | longsec = longval % 60; | ||
1439 | longval = longval / 60; | ||
1440 | longmin = longval % 60; | ||
1441 | longval = longval / 60; | ||
1442 | longdeg = longval; | ||
1443 | |||
1444 | altfrac = altval % 100; | ||
1445 | altmeters = (altval / 100) * altsign; | ||
1446 | |||
1447 | if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL) | ||
1448 | sizestr = error; | ||
1449 | if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL) | ||
1450 | hpstr = error; | ||
1451 | if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL) | ||
1452 | vpstr = error; | ||
1453 | |||
1454 | sprintf(ascii, | ||
1455 | "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm", | ||
1456 | latdeg, latmin, latsec, latsecfrac, northsouth, | ||
1457 | longdeg, longmin, longsec, longsecfrac, eastwest, | ||
1458 | altmeters, altfrac, sizestr, hpstr, vpstr); | ||
1459 | |||
1460 | if (sizestr != error) | ||
1461 | free(sizestr); | ||
1462 | if (hpstr != error) | ||
1463 | free(hpstr); | ||
1464 | if (vpstr != error) | ||
1465 | free(vpstr); | ||
1466 | |||
1467 | return (ascii); | ||
1468 | } | ||
1469 | |||
1470 | |||
1471 | /* Return the number of DNS hierarchy levels in the name. */ | ||
1472 | int | ||
1473 | __dn_count_labels(name) | ||
1474 | char *name; | ||
1475 | { | ||
1476 | int i, len, count; | ||
1477 | |||
1478 | len = strlen(name); | ||
1479 | |||
1480 | for(i = 0, count = 0; i < len; i++) { | ||
1481 | if (name[i] == '.') | ||
1482 | count++; | ||
1483 | } | ||
1484 | |||
1485 | /* don't count initial wildcard */ | ||
1486 | if (name[0] == '*') | ||
1487 | if (count) | ||
1488 | count--; | ||
1489 | |||
1490 | /* don't count the null label for root. */ | ||
1491 | /* if terminating '.' not found, must adjust */ | ||
1492 | /* count to include last label */ | ||
1493 | if (len > 0 && name[len-1] != '.') | ||
1494 | count++; | ||
1495 | return (count); | ||
1496 | } | ||
1497 | |||
1498 | |||
1499 | /* | ||
1500 | * Make dates expressed in seconds-since-Jan-1-1970 easy to read. | ||
1501 | * SIG records are required to be printed like this, by the Secure DNS RFC. | ||
1502 | */ | ||
1503 | char * | ||
1504 | __p_secstodate (secs) | ||
1505 | unsigned long secs; | ||
1506 | { | ||
1507 | static char output[15]; /* YYYYMMDDHHMMSS and null */ | ||
1508 | time_t clock = secs; | ||
1509 | struct tm *time; | ||
1510 | |||
1511 | time = gmtime(&clock); | ||
1512 | time->tm_year += 1900; | ||
1513 | time->tm_mon += 1; | ||
1514 | sprintf(output, "%04d%02d%02d%02d%02d%02d", | ||
1515 | time->tm_year, time->tm_mon, time->tm_mday, | ||
1516 | time->tm_hour, time->tm_min, time->tm_sec); | ||
1517 | return (output); | ||
749 | } | 1518 | } |