Print this page
1926 libresolv evades compiler warnings
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libresolv/res_debug.c
+++ new/usr/src/lib/libresolv/res_debug.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 + * Copyright 2015 Gary Mills
23 24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 25 * Use is subject to license terms.
25 26 */
26 27
27 28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 29 /* All Rights Reserved */
29 30
30 31 /*
31 32 * University Copyright- Copyright (c) 1982, 1986, 1988
32 33 * The Regents of the University of California
33 34 * All Rights Reserved
34 35 *
35 36 * University Acknowledgment- Portions of this document are derived from
36 37 * software developed by the University of California, Berkeley, and its
37 38 * contributors.
38 39 */
39 40
40 -#pragma ident "%Z%%M% %I% %E% SMI"
41 -
42 41 #include <sys/types.h>
42 +#include <sys/socket.h>
43 43 #include <netinet/in.h>
44 +#include <arpa/inet.h>
44 45 #include <stdio.h>
46 +#include <string.h>
45 47 #include <arpa/nameser.h>
48 +#include <resolv.h>
49 +#include "crossl.h"
46 50
47 -extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time();
48 -extern char *inet_ntoa();
49 51 void fp_query(char *msg, FILE *file);
50 52
51 53 char *_res_opcodes[] = {
52 54 "QUERY",
53 55 "IQUERY",
54 56 "CQUERYM",
55 57 "CQUERYU",
56 58 "4",
57 59 "5",
58 60 "6",
59 61 "7",
60 62 "8",
61 63 "UPDATEA",
62 64 "UPDATED",
63 65 "UPDATEDA",
64 66 "UPDATEM",
65 67 "UPDATEMA",
66 68 "ZONEINIT",
67 69 "ZONEREF",
68 70 };
69 71
70 72 char *_res_resultcodes[] = {
71 73 "NOERROR",
72 74 "FORMERR",
73 75 "SERVFAIL",
74 76 "NXDOMAIN",
75 77 "NOTIMP",
76 78 "REFUSED",
77 79 "6",
78 80 "7",
79 81 "8",
80 82 "9",
81 83 "10",
82 84 "11",
83 85 "12",
84 86 "13",
85 87 "14",
86 88 "NOCHANGE",
87 89 };
88 90
89 91 void
90 92 p_query(msg)
91 93 char *msg;
92 94 {
93 95 fp_query(msg, stdout);
94 96 }
95 97
96 98 /*
97 99 * Print the contents of a query.
98 100 * This is intended to be primarily a debugging routine.
99 101 */
100 102 void
101 103 fp_query(msg, file)
102 104 char *msg;
103 105 FILE *file;
104 106 {
105 107 register char *cp;
106 108 register HEADER *hp;
107 109 register int n;
108 110
109 111 /*
110 112 * Print header fields.
111 113 */
112 114 hp = (HEADER *)msg;
113 115 cp = msg + sizeof (HEADER);
114 116 fprintf(file, "HEADER:\n");
115 117 fprintf(file, "\topcode = %s", _res_opcodes[hp->opcode]);
116 118 fprintf(file, ", id = %d", ntohs(hp->id));
117 119 fprintf(file, ", rcode = %s\n", _res_resultcodes[hp->rcode]);
118 120 fprintf(file, "\theader flags: ");
119 121 if (hp->qr)
120 122 fprintf(file, " qr");
121 123 if (hp->aa)
122 124 fprintf(file, " aa");
123 125 if (hp->tc)
124 126 fprintf(file, " tc");
125 127 if (hp->rd)
126 128 fprintf(file, " rd");
127 129 if (hp->ra)
128 130 fprintf(file, " ra");
129 131 if (hp->pr)
130 132 fprintf(file, " pr");
131 133 fprintf(file, "\n\tqdcount = %d", ntohs(hp->qdcount));
132 134 fprintf(file, ", ancount = %d", ntohs(hp->ancount));
133 135 fprintf(file, ", nscount = %d", ntohs(hp->nscount));
134 136 fprintf(file, ", arcount = %d\n\n", ntohs(hp->arcount));
135 137 /*
136 138 * Print question records.
137 139 */
138 140 if (n = ntohs(hp->qdcount)) {
139 141 fprintf(file, "QUESTIONS:\n");
140 142 while (--n >= 0) {
141 143 fprintf(file, "\t");
142 144 cp = p_cdname(cp, msg, file);
143 145 if (cp == NULL)
144 146 return;
145 147 fprintf(file, ", type = %s", p_type(_getshort(cp)));
146 148 cp += sizeof (u_short);
147 149 fprintf(file, ", class = %s\n\n",
148 150 p_class(_getshort(cp)));
149 151 cp += sizeof (u_short);
150 152 }
151 153 }
152 154 /*
153 155 * Print authoritative answer records
154 156 */
155 157 if (n = ntohs(hp->ancount)) {
156 158 fprintf(file, "ANSWERS:\n");
157 159 while (--n >= 0) {
158 160 fprintf(file, "\t");
159 161 cp = p_rr(cp, msg, file);
160 162 if (cp == NULL)
161 163 return;
162 164 }
163 165 }
164 166 /*
165 167 * print name server records
166 168 */
167 169 if (n = ntohs(hp->nscount)) {
168 170 fprintf(file, "NAME SERVERS:\n");
169 171 while (--n >= 0) {
170 172 fprintf(file, "\t");
171 173 cp = p_rr(cp, msg, file);
172 174 if (cp == NULL)
173 175 return;
174 176 }
175 177 }
176 178 /*
177 179 * print additional records
178 180 */
179 181 if (n = ntohs(hp->arcount)) {
180 182 fprintf(file, "ADDITIONAL RECORDS:\n");
181 183 while (--n >= 0) {
182 184 fprintf(file, "\t");
183 185 cp = p_rr(cp, msg, file);
184 186 if (cp == NULL)
185 187 return;
186 188 }
187 189 }
↓ open down ↓ |
129 lines elided |
↑ open up ↑ |
188 190 }
189 191
190 192 char *
191 193 p_cdname(cp, msg, file)
192 194 char *cp, *msg;
193 195 FILE *file;
194 196 {
195 197 char name[MAXDNAME];
196 198 int n;
197 199
198 - if ((n = dn_expand(msg, msg + 512, cp, name, sizeof (name))) < 0)
200 + if ((n = dn_expand((u_char *)msg, (u_char *)(msg + 512), (u_char *)cp,
201 + (u_char *)name, sizeof (name))) < 0)
199 202 return (NULL);
200 203 if (name[0] == '\0') {
201 204 name[0] = '.';
202 205 name[1] = '\0';
203 206 }
204 207 fputs(name, file);
205 208 return (cp + n);
206 209 }
207 210
208 211 /*
209 212 * Print resource record fields in human readable form.
210 213 */
211 214 char *
212 215 p_rr(cp, msg, file)
213 216 char *cp, *msg;
214 217 FILE *file;
215 218 {
216 219 int type, class, dlen, n, c;
217 220 struct in_addr inaddr;
218 221 char *cp1, *cp2;
219 222
220 223 if ((cp = p_cdname(cp, msg, file)) == NULL)
221 224 return (NULL); /* compression error */
222 225 fprintf(file, "\n\ttype = %s", p_type(type = _getshort(cp)));
223 226 cp += sizeof (u_short);
224 227 fprintf(file, ", class = %s", p_class(class = _getshort(cp)));
225 228 cp += sizeof (u_short);
226 229 fprintf(file, ", ttl = %s", p_time(_getlong(cp)));
227 230 cp += sizeof (u_long);
228 231 fprintf(file, ", dlen = %d\n", dlen = _getshort(cp));
229 232 cp += sizeof (u_short);
230 233 cp1 = cp;
231 234 /*
232 235 * Print type specific data, if appropriate
233 236 */
234 237 switch (type) {
235 238 case T_A:
236 239 switch (class) {
237 240 case C_IN:
238 241 case C_HS:
239 242 #ifdef SYSV
240 243 memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr));
241 244 #else
242 245 bcopy(cp, (char *)&inaddr, sizeof (inaddr));
243 246 #endif
244 247 if (dlen == 4) {
245 248 fprintf(file, "\tinternet address = %s\n",
246 249 inet_ntoa(inaddr));
247 250 cp += dlen;
248 251 } else if (dlen == 7) {
249 252 fprintf(file, "\tinternet address = %s",
250 253 inet_ntoa(inaddr));
251 254 fprintf(file, ", protocol = %d", cp[4]);
252 255 fprintf(file, ", port = %d\n",
253 256 (cp[5] << 8) + cp[6]);
254 257 cp += dlen;
255 258 }
256 259 break;
257 260 default:
258 261 cp += dlen;
259 262 }
260 263 break;
261 264 case T_CNAME:
262 265 case T_MB:
263 266 case T_MG:
264 267 case T_MR:
265 268 case T_NS:
266 269 case T_PTR:
267 270 fprintf(file, "\tdomain name = ");
268 271 cp = p_cdname(cp, msg, file);
269 272 fprintf(file, "\n");
270 273 break;
271 274
272 275 case T_HINFO:
273 276 if (n = *cp++) {
274 277 fprintf(file, "\tCPU=%.*s\n", n, cp);
275 278 cp += n;
276 279 }
277 280 if (n = *cp++) {
278 281 fprintf(file, "\tOS=%.*s\n", n, cp);
279 282 cp += n;
280 283 }
281 284 break;
282 285
283 286 case T_SOA:
284 287 fprintf(file, "\torigin = ");
285 288 cp = p_cdname(cp, msg, file);
286 289 fprintf(file, "\n\tmail addr = ");
287 290 cp = p_cdname(cp, msg, file);
288 291 fprintf(file, "\n\tserial = %ld", _getlong(cp));
289 292 cp += sizeof (u_long);
290 293 fprintf(file, "\n\trefresh = %s", p_time(_getlong(cp)));
291 294 cp += sizeof (u_long);
292 295 fprintf(file, "\n\tretry = %s", p_time(_getlong(cp)));
293 296 cp += sizeof (u_long);
294 297 fprintf(file, "\n\texpire = %s", p_time(_getlong(cp)));
295 298 cp += sizeof (u_long);
296 299 fprintf(file, "\n\tmin = %s\n", p_time(_getlong(cp)));
297 300 cp += sizeof (u_long);
298 301 break;
299 302
300 303 case T_MX:
301 304 fprintf(file, "\tpreference = %ld,", _getshort(cp));
302 305 cp += sizeof (u_short);
303 306 fprintf(file, " name = ");
304 307 cp = p_cdname(cp, msg, file);
305 308 break;
306 309
307 310 case T_TXT:
308 311 (void) fputs("\t\"", file);
309 312 cp2 = cp1 + dlen;
310 313 while (cp < cp2) {
311 314 if (n = (unsigned char) *cp++) {
312 315 for (c = n; c > 0 && cp < cp2; c--)
313 316 if (*cp == '\n') {
314 317 (void) putc('\\', file);
315 318 (void) putc(*cp++, file);
316 319 } else
317 320 (void) putc(*cp++, file);
318 321 }
319 322 }
320 323 (void) fputs("\"\n", file);
321 324 break;
322 325
323 326 case T_MINFO:
324 327 fprintf(file, "\trequests = ");
325 328 cp = p_cdname(cp, msg, file);
326 329 fprintf(file, "\n\terrors = ");
327 330 cp = p_cdname(cp, msg, file);
328 331 break;
329 332
330 333 case T_UINFO:
331 334 fprintf(file, "\t%s\n", cp);
332 335 cp += dlen;
333 336 break;
334 337
335 338 case T_UID:
336 339 case T_GID:
337 340 if (dlen == 4) {
338 341 fprintf(file, "\t%ld\n", _getlong(cp));
339 342 cp += sizeof (int);
340 343 }
341 344 break;
342 345
343 346 case T_WKS:
344 347 if (dlen < sizeof (u_long) + 1)
345 348 break;
346 349 #ifdef SYSV
347 350 memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr));
348 351 #else
349 352 bcopy(cp, (char *)&inaddr, sizeof (inaddr));
350 353 #endif
351 354 cp += sizeof (u_long);
352 355 fprintf(file, "\tinternet address = %s, protocol = %d\n\t",
353 356 inet_ntoa(inaddr), *cp++);
354 357 n = 0;
355 358 while (cp < cp1 + dlen) {
356 359 c = *cp++;
357 360 do {
358 361 if (c & 0200)
359 362 fprintf(file, " %d", n);
360 363 c <<= 1;
361 364 } while (++n & 07);
362 365 }
363 366 putc('\n', file);
364 367 break;
365 368
366 369 #ifdef ALLOW_T_UNSPEC
367 370 case T_UNSPEC:
368 371 {
369 372 int NumBytes = 8;
370 373 char *DataPtr;
371 374 int i;
372 375
373 376 if (dlen < NumBytes) NumBytes = dlen;
374 377 fprintf(file, "\tFirst %d bytes of hex data:",
375 378 NumBytes);
376 379 for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++)
377 380 fprintf(file, " %x", *DataPtr);
378 381 fputs("\n", file);
379 382 cp += dlen;
380 383 }
381 384 break;
382 385 #endif /* ALLOW_T_UNSPEC */
383 386
384 387 default:
385 388 fprintf(file, "\t???\n");
386 389 cp += dlen;
387 390 }
388 391 if (cp != cp1 + dlen) {
389 392 fprintf(file, "packet size error (%#x != %#x)\n", cp, cp1+dlen);
390 393 cp = NULL;
391 394 }
392 395 fprintf(file, "\n");
393 396 return (cp);
394 397 }
395 398
396 399 static char nbuf[40];
397 400
398 401 /*
399 402 * Return a string for the type
400 403 */
401 404 char *
402 405 p_type(type)
403 406 int type;
404 407 {
405 408 switch (type) {
406 409 case T_A:
407 410 return ("A");
408 411 case T_NS: /* authoritative server */
409 412 return ("NS");
410 413 case T_CNAME: /* canonical name */
411 414 return ("CNAME");
412 415 case T_SOA: /* start of authority zone */
413 416 return ("SOA");
414 417 case T_MB: /* mailbox domain name */
415 418 return ("MB");
416 419 case T_MG: /* mail group member */
417 420 return ("MG");
418 421 case T_MR: /* mail rename name */
419 422 return ("MR");
420 423 case T_NULL: /* null resource record */
421 424 return ("NULL");
422 425 case T_WKS: /* well known service */
423 426 return ("WKS");
424 427 case T_PTR: /* domain name pointer */
425 428 return ("PTR");
426 429 case T_HINFO: /* host information */
427 430 return ("HINFO");
428 431 case T_MINFO: /* mailbox information */
429 432 return ("MINFO");
430 433 case T_MX: /* mail routing info */
431 434 return ("MX");
432 435 case T_TXT: /* text */
433 436 return ("TXT");
434 437 case T_AXFR: /* zone transfer */
435 438 return ("AXFR");
436 439 case T_MAILB: /* mail box */
437 440 return ("MAILB");
438 441 case T_MAILA: /* mail address */
439 442 return ("MAILA");
440 443 case T_ANY: /* matches any type */
441 444 return ("ANY");
442 445 case T_UINFO:
443 446 return ("UINFO");
444 447 case T_UID:
445 448 return ("UID");
446 449 case T_GID:
447 450 return ("GID");
448 451 #ifdef ALLOW_T_UNSPEC
449 452 case T_UNSPEC:
450 453 return ("UNSPEC");
451 454 #endif /* ALLOW_T_UNSPEC */
452 455 default:
453 456 (void) sprintf(nbuf, "%d", type);
454 457 return (nbuf);
455 458 }
456 459 }
457 460
458 461 /*
459 462 * Return a mnemonic for class
460 463 */
461 464 char *
462 465 p_class(class)
463 466 int class;
464 467 {
465 468
466 469 switch (class) {
467 470 case C_IN: /* internet class */
468 471 return ("IN");
469 472 case C_HS: /* hesiod class */
470 473 return ("HS");
471 474 case C_ANY: /* matches any class */
472 475 return ("ANY");
473 476 default:
474 477 (void) sprintf(nbuf, "%d", class);
475 478 return (nbuf);
476 479 }
477 480 }
478 481
479 482 /*
480 483 * Return a mnemonic for a time to live
481 484 */
482 485 char *
483 486 p_time(value)
484 487 u_long value;
485 488 {
486 489 int secs, mins, hours;
487 490 register char *p;
488 491
489 492 if (value == 0) {
490 493 strcpy(nbuf, "0 secs");
491 494 return (nbuf);
492 495 }
493 496
494 497 secs = value % 60;
495 498 value /= 60;
496 499 mins = value % 60;
497 500 value /= 60;
498 501 hours = value % 24;
499 502 value /= 24;
500 503
501 504 #define PLURALIZE(x) x, (x == 1) ? "" : "s"
502 505 p = nbuf;
503 506 if (value) {
504 507 (void) sprintf(p, "%d day%s", PLURALIZE(value));
505 508 while (*++p);
506 509 }
507 510 if (hours) {
508 511 if (value)
509 512 *p++ = ' ';
510 513 (void) sprintf(p, "%d hour%s", PLURALIZE(hours));
511 514 while (*++p);
512 515 }
513 516 if (mins) {
514 517 if (value || hours)
515 518 *p++ = ' ';
516 519 (void) sprintf(p, "%d min%s", PLURALIZE(mins));
517 520 while (*++p);
518 521 }
519 522 if (secs || ! (value || hours || mins)) {
520 523 if (value || hours || mins)
521 524 *p++ = ' ';
522 525 (void) sprintf(p, "%d sec%s", PLURALIZE(secs));
523 526 }
524 527 return (nbuf);
525 528 }
↓ open down ↓ |
317 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX