print-domain.c (56896) | print-domain.c (75118) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * |
21 * $FreeBSD: head/contrib/tcpdump/print-domain.c 56896 2000-01-30 01:05:24Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-domain.c 75118 2001-04-03 07:50:46Z fenner $ |
22 */ 23 24#ifndef lint 25static const char rcsid[] = | 22 */ 23 24#ifndef lint 25static const char rcsid[] = |
26 "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.42 1999/11/21 09:36:50 fenner Exp $ (LBL)"; | 26 "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.64 2001/01/02 23:24:51 guy Exp $ (LBL)"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <sys/param.h> 34#include <sys/time.h> | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <sys/param.h> 34#include <sys/time.h> |
35#include <sys/socket.h> | |
36 | 35 |
37#if __STDC__ 38struct mbuf; 39struct rtentry; 40#endif 41#include <net/if.h> 42 | |
43#include <netinet/in.h> | 36#include <netinet/in.h> |
44#include <net/ethernet.h> 45#include <netinet/in_systm.h> 46#include <netinet/ip.h> 47#include <netinet/ip_var.h> 48#include <netinet/udp.h> 49#include <netinet/udp_var.h> 50#include <netinet/tcp.h> | |
51 52#ifdef NOERROR 53#undef NOERROR /* Solaris sucks */ 54#endif 55#ifdef NOERROR 56#undef T_UNSPEC /* SINIX does too */ 57#endif | 37 38#ifdef NOERROR 39#undef NOERROR /* Solaris sucks */ 40#endif 41#ifdef NOERROR 42#undef T_UNSPEC /* SINIX does too */ 43#endif |
58#include <arpa/nameser.h> | 44#include "nameser.h" |
59 60#include <stdio.h> 61#include <string.h> 62 63#include "interface.h" 64#include "addrtoname.h" 65#include "extract.h" /* must come after interface.h */ 66 --- 54 unchanged lines hidden (view full) --- 121#endif 122#ifndef T_ATMA 123#define T_ATMA 34 /* ATM Address */ 124#endif 125#ifndef T_NAPTR 126#define T_NAPTR 35 /* Naming Authority PoinTeR */ 127#endif 128#ifndef T_A6 | 45 46#include <stdio.h> 47#include <string.h> 48 49#include "interface.h" 50#include "addrtoname.h" 51#include "extract.h" /* must come after interface.h */ 52 --- 54 unchanged lines hidden (view full) --- 107#endif 108#ifndef T_ATMA 109#define T_ATMA 34 /* ATM Address */ 110#endif 111#ifndef T_NAPTR 112#define T_NAPTR 35 /* Naming Authority PoinTeR */ 113#endif 114#ifndef T_A6 |
129#define T_A6 38 /* IP6 address (ipngwg-dns-lookups) */ | 115#define T_A6 38 /* IP6 address */ |
130#endif | 116#endif |
117#ifndef T_DNAME 118#define T_DNAME 39 /* non-terminal redirection */ 119#endif |
|
131 | 120 |
121#ifndef T_OPT 122#define T_OPT 41 /* EDNS0 option (meta-RR) */ 123#endif 124 |
|
132#ifndef T_UNSPEC 133#define T_UNSPEC 103 /* Unspecified format (binary data) */ 134#endif 135#ifndef T_UNSPECA 136#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */ 137#endif 138 139#ifndef C_CHAOS --- 19 unchanged lines hidden (view full) --- 159/* skip over a domain name */ 160static const u_char * 161ns_nskip(register const u_char *cp, register const u_char *bp) 162{ 163 register u_char i; 164 165 if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) 166 return (cp + 1); | 125#ifndef T_UNSPEC 126#define T_UNSPEC 103 /* Unspecified format (binary data) */ 127#endif 128#ifndef T_UNSPECA 129#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */ 130#endif 131 132#ifndef C_CHAOS --- 19 unchanged lines hidden (view full) --- 152/* skip over a domain name */ 153static const u_char * 154ns_nskip(register const u_char *cp, register const u_char *bp) 155{ 156 register u_char i; 157 158 if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) 159 return (cp + 1); |
160 if (cp >= snapend) 161 return(NULL); |
|
167 while (i && cp < snapend) { | 162 while (i && cp < snapend) { |
168 cp += i; | 163 if ((i & INDIR_MASK) == EDNS0_MASK) { 164 int bitlen, bytelen; 165 166 if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) 167 return(NULL); /* unknown ELT */ 168 if ((bitlen = *cp++) == 0) 169 bitlen = 256; 170 bytelen = (bitlen + 7) / 8; 171 cp += bytelen; 172 } else 173 cp += i; 174 if (cp >= snapend) 175 return(NULL); |
169 i = *cp++; 170 } 171 return (cp); 172} 173 174/* print a <domain-name> */ 175static const u_char * | 176 i = *cp++; 177 } 178 return (cp); 179} 180 181/* print a <domain-name> */ 182static const u_char * |
176ns_nprint(register const u_char *cp, register const u_char *bp) | 183blabel_print(const u_char *cp) |
177{ | 184{ |
185 int bitlen, slen, b; 186 int truncated = 0; 187 const u_char *bitp, *lim; 188 char tc; 189 190 if (cp >= snapend) 191 return(NULL); 192 if ((bitlen = *cp) == 0) 193 bitlen = 256; 194 slen = (bitlen + 3) / 4; 195 if ((lim = cp + 1 + slen) > snapend) { 196 truncated = 1; 197 lim = snapend; 198 } 199 200 /* print the bit string as a hex string */ 201 printf("\\[x"); 202 for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) 203 printf("%02x", *bitp); 204 if (bitp == lim) 205 printf("..."); 206 else if (b > 4) { 207 tc = *bitp++; 208 printf("%02x", tc & (0xff << (8 - b))); 209 } else if (b > 0) { 210 tc = *bitp++; 211 printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b))); 212 } 213 printf("/%d]", bitlen); 214 215 return(truncated ? NULL : lim); 216} 217 218static int 219labellen(const u_char *cp) 220{ |
|
178 register u_int i; | 221 register u_int i; |
179 register const u_char *rp; 180 register int compress; | |
181 | 222 |
182 i = *cp++; 183 rp = cp + i; 184 if ((i & INDIR_MASK) == INDIR_MASK) { 185 rp = cp + 1; 186 compress = 1; | 223 if (cp >= snapend) 224 return(-1); 225 i = *cp; 226 if ((i & INDIR_MASK) == EDNS0_MASK) { 227 int bitlen, elt; 228 229 if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) 230 return(-1); 231 if (cp + 1 >= snapend) 232 return(-1); 233 if ((bitlen = *(cp + 1)) == 0) 234 bitlen = 256; 235 return(((bitlen + 7) / 8) + 1); |
187 } else | 236 } else |
237 return(i); 238} 239 240static const u_char * 241ns_nprint(register const u_char *cp, register const u_char *bp) 242{ 243 register u_int i, l; 244 register const u_char *rp = NULL; 245 register int compress = 0; 246 int chars_processed; 247 int elt; 248 int data_size = snapend - bp; 249 250 if ((l = labellen(cp)) < 0) 251 return(NULL); 252 if (cp >= snapend) 253 return(NULL); 254 chars_processed = 1; 255 if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { |
|
188 compress = 0; | 256 compress = 0; |
257 rp = cp + l; 258 } 259 |
|
189 if (i != 0) 190 while (i && cp < snapend) { 191 if ((i & INDIR_MASK) == INDIR_MASK) { | 260 if (i != 0) 261 while (i && cp < snapend) { 262 if ((i & INDIR_MASK) == INDIR_MASK) { |
263 if (!compress) { 264 rp = cp + 1; 265 compress = 1; 266 } |
|
192 cp = bp + (((i << 8) | *cp) & 0x3fff); | 267 cp = bp + (((i << 8) | *cp) & 0x3fff); |
268 if (cp >= snapend) 269 return(NULL); 270 if ((l = labellen(cp)) < 0) 271 return(NULL); |
|
193 i = *cp++; | 272 i = *cp++; |
273 chars_processed++; 274 275 /* 276 * If we've looked at every character in 277 * the message, this pointer will make 278 * us look at some character again, 279 * which means we're looping. 280 */ 281 if (chars_processed >= data_size) { 282 printf("<LOOP>"); 283 return (NULL); 284 } |
|
194 continue; 195 } | 285 continue; 286 } |
196 if (fn_printn(cp, i, snapend)) 197 break; 198 cp += i; | 287 if ((i & INDIR_MASK) == EDNS0_MASK) { 288 elt = (i & ~INDIR_MASK); 289 switch(elt) { 290 case EDNS0_ELT_BITLABEL: 291 blabel_print(cp); 292 break; 293 default: 294 /* unknown ELT */ 295 printf("<ELT %d>", elt); 296 return(NULL); 297 } 298 } else { 299 if (fn_printn(cp, l, snapend)) 300 break; 301 } 302 303 cp += l; 304 chars_processed += l; |
199 putchar('.'); | 305 putchar('.'); |
306 if (cp >= snapend || (l = labellen(cp)) < 0) 307 return(NULL); |
|
200 i = *cp++; | 308 i = *cp++; |
309 chars_processed++; |
|
201 if (!compress) | 310 if (!compress) |
202 rp += i + 1; | 311 rp += l + 1; |
203 } 204 else 205 putchar('.'); 206 return (rp); 207} 208 209/* print a <character-string> */ 210static const u_char * 211ns_cprint(register const u_char *cp, register const u_char *bp) 212{ 213 register u_int i; 214 | 312 } 313 else 314 putchar('.'); 315 return (rp); 316} 317 318/* print a <character-string> */ 319static const u_char * 320ns_cprint(register const u_char *cp, register const u_char *bp) 321{ 322 register u_int i; 323 |
324 if (cp >= snapend) 325 return NULL; |
|
215 i = *cp++; 216 (void)fn_printn(cp, i, snapend); 217 return (cp + i); 218} 219 220static struct tok type2str[] = { 221 { T_A, "A" }, 222 { T_NS, "NS" }, --- 26 unchanged lines hidden (view full) --- 249 { T_LOC, "LOC " }, 250 { T_NXT, "NXT " }, 251 { T_EID, "EID " }, 252 { T_NIMLOC, "NIMLOC " }, 253 { T_SRV, "SRV " }, 254 { T_ATMA, "ATMA " }, 255 { T_NAPTR, "NAPTR " }, 256 { T_A6, "A6 " }, | 326 i = *cp++; 327 (void)fn_printn(cp, i, snapend); 328 return (cp + i); 329} 330 331static struct tok type2str[] = { 332 { T_A, "A" }, 333 { T_NS, "NS" }, --- 26 unchanged lines hidden (view full) --- 360 { T_LOC, "LOC " }, 361 { T_NXT, "NXT " }, 362 { T_EID, "EID " }, 363 { T_NIMLOC, "NIMLOC " }, 364 { T_SRV, "SRV " }, 365 { T_ATMA, "ATMA " }, 366 { T_NAPTR, "NAPTR " }, 367 { T_A6, "A6 " }, |
257#ifndef T_UINFO 258#define T_UINFO 100 259#endif | 368 { T_DNAME, "DNAME " }, 369 { T_OPT, "OPT " }, |
260 { T_UINFO, "UINFO" }, | 370 { T_UINFO, "UINFO" }, |
261#ifndef T_UID 262#define T_UID 101 263#endif | |
264 { T_UID, "UID" }, | 371 { T_UID, "UID" }, |
265#ifndef T_GID 266#define T_GID 102 267#endif | |
268 { T_GID, "GID" }, 269 { T_UNSPEC, "UNSPEC" }, 270 { T_UNSPECA, "UNSPECA" }, 271 { T_AXFR, "AXFR" }, 272 { T_MAILB, "MAILB" }, 273 { T_MAILA, "MAILA" }, 274 { T_ANY, "ANY" }, 275 { 0, NULL } 276}; 277 278static struct tok class2str[] = { 279 { C_IN, "IN" }, /* Not used */ 280 { C_CHAOS, "CHAOS)" }, 281 { C_HS, "HS" }, 282 { C_ANY, "ANY" }, 283 { 0, NULL } 284}; 285 286/* print a query */ | 372 { T_GID, "GID" }, 373 { T_UNSPEC, "UNSPEC" }, 374 { T_UNSPECA, "UNSPECA" }, 375 { T_AXFR, "AXFR" }, 376 { T_MAILB, "MAILB" }, 377 { T_MAILA, "MAILA" }, 378 { T_ANY, "ANY" }, 379 { 0, NULL } 380}; 381 382static struct tok class2str[] = { 383 { C_IN, "IN" }, /* Not used */ 384 { C_CHAOS, "CHAOS)" }, 385 { C_HS, "HS" }, 386 { C_ANY, "ANY" }, 387 { 0, NULL } 388}; 389 390/* print a query */ |
287static void | 391static const u_char * |
288ns_qprint(register const u_char *cp, register const u_char *bp) 289{ 290 register const u_char *np = cp; 291 register u_int i; 292 293 cp = ns_nskip(cp, bp); 294 | 392ns_qprint(register const u_char *cp, register const u_char *bp) 393{ 394 register const u_char *np = cp; 395 register u_int i; 396 397 cp = ns_nskip(cp, bp); 398 |
295 if (cp + 4 > snapend) 296 return; | 399 if (cp + 4 > snapend || cp == NULL) 400 return(NULL); |
297 298 /* print the qtype and qclass (if it's not IN) */ 299 i = *cp++ << 8; 300 i |= *cp++; 301 printf(" %s", tok2str(type2str, "Type%d", i)); 302 i = *cp++ << 8; 303 i |= *cp++; 304 if (i != C_IN) 305 printf(" %s", tok2str(class2str, "(Class %d)", i)); 306 307 fputs("? ", stdout); | 401 402 /* print the qtype and qclass (if it's not IN) */ 403 i = *cp++ << 8; 404 i |= *cp++; 405 printf(" %s", tok2str(type2str, "Type%d", i)); 406 i = *cp++ << 8; 407 i |= *cp++; 408 if (i != C_IN) 409 printf(" %s", tok2str(class2str, "(Class %d)", i)); 410 411 fputs("? ", stdout); |
308 ns_nprint(np, bp); | 412 cp = ns_nprint(np, bp); 413 return(cp ? cp + 4 : NULL); |
309} 310 311/* print a reply */ 312static const u_char * 313ns_rprint(register const u_char *cp, register const u_char *bp) 314{ | 414} 415 416/* print a reply */ 417static const u_char * 418ns_rprint(register const u_char *cp, register const u_char *bp) 419{ |
315 register u_int i; | 420 register u_int class; |
316 register u_short typ, len; 317 register const u_char *rp; 318 319 if (vflag) { 320 putchar(' '); | 421 register u_short typ, len; 422 register const u_char *rp; 423 424 if (vflag) { 425 putchar(' '); |
321 cp = ns_nprint(cp, bp); | 426 if ((cp = ns_nprint(cp, bp)) == NULL) 427 return NULL; |
322 } else 323 cp = ns_nskip(cp, bp); 324 | 428 } else 429 cp = ns_nskip(cp, bp); 430 |
325 if (cp + 10 > snapend) | 431 if (cp + 10 > snapend || cp == NULL) |
326 return (snapend); 327 328 /* print the type/qtype and class (if it's not IN) */ 329 typ = *cp++ << 8; 330 typ |= *cp++; | 432 return (snapend); 433 434 /* print the type/qtype and class (if it's not IN) */ 435 typ = *cp++ << 8; 436 typ |= *cp++; |
331 i = *cp++ << 8; 332 i |= *cp++; 333 if (i != C_IN) 334 printf(" %s", tok2str(class2str, "(Class %d)", i)); | 437 class = *cp++ << 8; 438 class |= *cp++; 439 if (class != C_IN && typ != T_OPT) 440 printf(" %s", tok2str(class2str, "(Class %d)", class)); |
335 336 /* ignore ttl */ 337 cp += 4; 338 339 len = *cp++ << 8; 340 len |= *cp++; 341 342 rp = cp + len; 343 344 printf(" %s", tok2str(type2str, "Type%d", typ)); | 441 442 /* ignore ttl */ 443 cp += 4; 444 445 len = *cp++ << 8; 446 len |= *cp++; 447 448 rp = cp + len; 449 450 printf(" %s", tok2str(type2str, "Type%d", typ)); |
345 switch (typ) { | 451 if (rp > snapend) 452 return(NULL); |
346 | 453 |
454 switch (typ) { |
|
347 case T_A: | 455 case T_A: |
456 if (cp + sizeof(struct in_addr) > snapend) 457 return(NULL); |
|
348 printf(" %s", ipaddr_string(cp)); 349 break; 350 351 case T_NS: 352 case T_CNAME: 353 case T_PTR: 354#ifdef T_DNAME | 458 printf(" %s", ipaddr_string(cp)); 459 break; 460 461 case T_NS: 462 case T_CNAME: 463 case T_PTR: 464#ifdef T_DNAME |
355 case T_DNAME: /*XXX not checked as there's no server support yet*/ | 465 case T_DNAME: |
356#endif 357 putchar(' '); | 466#endif 467 putchar(' '); |
358 (void)ns_nprint(cp, bp); | 468 if (ns_nprint(cp, bp) == NULL) 469 return(NULL); |
359 break; 360 | 470 break; 471 |
472 case T_SOA: 473 if (!vflag) 474 break; 475 putchar(' '); 476 if ((cp = ns_nprint(cp, bp)) == NULL) 477 return(NULL); 478 putchar(' '); 479 if ((cp = ns_nprint(cp, bp)) == NULL) 480 return(NULL); 481 if (cp + 5 * 4 > snapend) 482 return(NULL); 483 printf(" %u", EXTRACT_32BITS(cp)); 484 cp += 4; 485 printf(" %u", EXTRACT_32BITS(cp)); 486 cp += 4; 487 printf(" %u", EXTRACT_32BITS(cp)); 488 cp += 4; 489 printf(" %u", EXTRACT_32BITS(cp)); 490 cp += 4; 491 printf(" %u", EXTRACT_32BITS(cp)); 492 cp += 4; 493 break; |
|
361 case T_MX: 362 putchar(' '); | 494 case T_MX: 495 putchar(' '); |
363 (void)ns_nprint(cp + 2, bp); | 496 if (cp + 2 > snapend) 497 return(NULL); 498 if (ns_nprint(cp + 2, bp) == NULL) 499 return(NULL); |
364 printf(" %d", EXTRACT_16BITS(cp)); 365 break; 366 367 case T_TXT: 368 putchar(' '); 369 (void)ns_cprint(cp, bp); 370 break; 371 372#ifdef INET6 373 case T_AAAA: | 500 printf(" %d", EXTRACT_16BITS(cp)); 501 break; 502 503 case T_TXT: 504 putchar(' '); 505 (void)ns_cprint(cp, bp); 506 break; 507 508#ifdef INET6 509 case T_AAAA: |
510 if (cp + sizeof(struct in6_addr) > snapend) 511 return(NULL); |
|
374 printf(" %s", ip6addr_string(cp)); 375 break; 376 | 512 printf(" %s", ip6addr_string(cp)); 513 break; 514 |
377 case T_A6: /*XXX not checked as there's no server support yet*/ | 515 case T_A6: |
378 { 379 struct in6_addr a; | 516 { 517 struct in6_addr a; |
380 int pbyte; | 518 int pbit, pbyte; |
381 | 519 |
382 pbyte = (*cp + 7) / 8; 383 memset(&a, 0, sizeof(a)); 384 memcpy(&a, cp + 1, pbyte); 385 printf(" %u %s ", *cp, ip6addr_string(&a)); 386 (void)ns_nprint(cp + 1 + pbyte, bp); | 520 pbit = *cp; 521 pbyte = (pbit & ~7) / 8; 522 if (pbit > 128) { 523 printf(" %u(bad plen)", pbit); 524 break; 525 } else if (pbit < 128) { 526 memset(&a, 0, sizeof(a)); 527 memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); 528 printf(" %u %s", pbit, ip6addr_string(&a)); 529 } 530 if (pbit > 0) { 531 putchar(' '); 532 if (ns_nprint(cp + 1 + sizeof(a) - pbyte, bp) == NULL) 533 return(NULL); 534 } |
387 break; 388 } 389#endif /*INET6*/ 390 | 535 break; 536 } 537#endif /*INET6*/ 538 |
539 case T_OPT: 540 printf(" UDPsize=%u", class); 541 break; 542 |
|
391 case T_UNSPECA: /* One long string */ | 543 case T_UNSPECA: /* One long string */ |
392 printf(" %.*s", len, cp); | 544 if (cp + len > snapend) 545 return(NULL); 546 fn_printn(cp, len, snapend); |
393 break; 394 } 395 return (rp); /* XXX This isn't always right */ 396} 397 398void 399ns_print(register const u_char *bp, u_int length) 400{ 401 register const HEADER *np; 402 register int qdcount, ancount, nscount, arcount; | 547 break; 548 } 549 return (rp); /* XXX This isn't always right */ 550} 551 552void 553ns_print(register const u_char *bp, u_int length) 554{ 555 register const HEADER *np; 556 register int qdcount, ancount, nscount, arcount; |
403 register const u_char *cp; | 557 register const u_char *cp = NULL; |
404 405 np = (const HEADER *)bp; 406 /* get the byte-order right */ 407 qdcount = ntohs(np->qdcount); 408 ancount = ntohs(np->ancount); 409 nscount = ntohs(np->nscount); 410 arcount = ntohs(np->arcount); 411 | 558 559 np = (const HEADER *)bp; 560 /* get the byte-order right */ 561 qdcount = ntohs(np->qdcount); 562 ancount = ntohs(np->ancount); 563 nscount = ntohs(np->nscount); 564 arcount = ntohs(np->arcount); 565 |
412 if (np->qr) { | 566 if (DNS_QR(np)) { |
413 /* this is a response */ | 567 /* this is a response */ |
414 printf(" %d%s%s%s%s%s", | 568 printf(" %d%s%s%s%s%s%s", |
415 ntohs(np->id), | 569 ntohs(np->id), |
416 ns_ops[np->opcode], 417 ns_resp[np->rcode], 418 np->aa? "*" : "", 419 np->ra? "" : "-", 420 np->tc? "|" : ""); | 570 ns_ops[DNS_OPCODE(np)], 571 ns_resp[DNS_RCODE(np)], 572 DNS_AA(np)? "*" : "", 573 DNS_RA(np)? "" : "-", 574 DNS_TC(np)? "|" : "", 575 DNS_CD(np)? "%" : ""); 576 |
421 if (qdcount != 1) 422 printf(" [%dq]", qdcount); 423 /* Print QUESTION section on -vv */ 424 if (vflag > 1) { | 577 if (qdcount != 1) 578 printf(" [%dq]", qdcount); 579 /* Print QUESTION section on -vv */ 580 if (vflag > 1) { |
425 fputs(" q: ", stdout); 426 cp = ns_nprint((const u_char *)(np + 1), bp); 427 } else 428 cp = ns_nskip((const u_char *)(np + 1), bp); | 581 fputs(" q:", stdout); 582 if ((cp = ns_qprint((const u_char *)(np + 1), bp)) 583 == NULL) 584 goto trunc; 585 } else { 586 if ((cp = ns_nskip((const u_char *)(np + 1), bp)) 587 == NULL) 588 goto trunc; 589 cp += 4; 590 } |
429 printf(" %d/%d/%d", ancount, nscount, arcount); 430 if (ancount--) { | 591 printf(" %d/%d/%d", ancount, nscount, arcount); 592 if (ancount--) { |
431 cp = ns_rprint(cp + 4, bp); | 593 if ((cp = ns_rprint(cp, bp)) == NULL) 594 goto trunc; |
432 while (ancount-- && cp < snapend) { 433 putchar(','); | 595 while (ancount-- && cp < snapend) { 596 putchar(','); |
434 cp = ns_rprint(cp, bp); | 597 if ((cp = ns_rprint(cp, bp)) == NULL) 598 goto trunc; |
435 } 436 } | 599 } 600 } |
601 /* Print NS and AR sections on -vv */ 602 if (vflag > 1) { 603 if (nscount-- && cp < snapend) { 604 fputs(" ns:", stdout); 605 if ((cp = ns_rprint(cp, bp)) == NULL) 606 goto trunc; 607 while (nscount-- && cp < snapend) { 608 putchar(','); 609 if ((cp = ns_rprint(cp, bp)) == NULL) 610 goto trunc; 611 } 612 } 613 if (arcount-- && cp < snapend) { 614 fputs(" ar:", stdout); 615 if ((cp = ns_rprint(cp, bp)) == NULL) 616 goto trunc; 617 while (arcount-- && cp < snapend) { 618 putchar(','); 619 if ((cp = ns_rprint(cp, bp)) == NULL) 620 goto trunc; 621 } 622 } 623 } |
|
437 } 438 else { 439 /* this is a request */ | 624 } 625 else { 626 /* this is a request */ |
440 printf(" %d%s%s", 441 ntohs(np->id), 442 ns_ops[np->opcode], 443 np->rd? "+" : ""); | 627 printf(" %d%s%s%s", ntohs(np->id), ns_ops[DNS_OPCODE(np)], 628 DNS_RD(np) ? "+" : "", 629 DNS_AD(np) ? "$" : ""); |
444 445 /* any weirdness? */ | 630 631 /* any weirdness? */ |
446 if (*(((u_short *)np)+1) & htons(0x6ff)) | 632 if (*(((u_short *)np)+1) & htons(0x6cf)) |
447 printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1))); 448 | 633 printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1))); 634 |
449 if (np->opcode == IQUERY) { | 635 if (DNS_OPCODE(np) == IQUERY) { |
450 if (qdcount) 451 printf(" [%dq]", qdcount); 452 if (ancount != 1) 453 printf(" [%da]", ancount); 454 } 455 else { 456 if (ancount) 457 printf(" [%da]", ancount); 458 if (qdcount != 1) 459 printf(" [%dq]", qdcount); 460 } 461 if (nscount) 462 printf(" [%dn]", nscount); 463 if (arcount) 464 printf(" [%dau]", arcount); 465 | 636 if (qdcount) 637 printf(" [%dq]", qdcount); 638 if (ancount != 1) 639 printf(" [%da]", ancount); 640 } 641 else { 642 if (ancount) 643 printf(" [%da]", ancount); 644 if (qdcount != 1) 645 printf(" [%dq]", qdcount); 646 } 647 if (nscount) 648 printf(" [%dn]", nscount); 649 if (arcount) 650 printf(" [%dau]", arcount); 651 |
466 ns_qprint((const u_char *)(np + 1), (const u_char *)np); | 652 if (qdcount--) { 653 cp = ns_qprint((const u_char *)(np + 1), 654 (const u_char *)np); 655 if (!cp) 656 goto trunc; 657 if ((cp = ns_rprint(cp, bp)) == NULL) 658 goto trunc; 659 while (qdcount-- && cp < snapend) { 660 cp = ns_qprint((const u_char *)cp, 661 (const u_char *)np); 662 if (!cp) 663 goto trunc; 664 if ((cp = ns_rprint(cp, bp)) == NULL) 665 goto trunc; 666 } 667 } 668 669 /* Print remaining sections on -vv */ 670 if (vflag > 1) { 671 if (ancount--) { 672 if ((cp = ns_rprint(cp, bp)) == NULL) 673 goto trunc; 674 while (ancount-- && cp < snapend) { 675 putchar(','); 676 if ((cp = ns_rprint(cp, bp)) == NULL) 677 goto trunc; 678 } 679 } 680 if (nscount-- && cp < snapend) { 681 fputs(" ns:", stdout); 682 if ((cp = ns_rprint(cp, bp)) == NULL) 683 goto trunc; 684 while (nscount-- && cp < snapend) { 685 putchar(','); 686 if ((cp = ns_rprint(cp, bp)) == NULL) 687 goto trunc; 688 } 689 } 690 if (arcount-- && cp < snapend) { 691 fputs(" ar:", stdout); 692 if ((cp = ns_rprint(cp, bp)) == NULL) 693 goto trunc; 694 while (arcount-- && cp < snapend) { 695 putchar(','); 696 if ((cp = ns_rprint(cp, bp)) == NULL) 697 goto trunc; 698 } 699 } 700 } |
467 } 468 printf(" (%d)", length); | 701 } 702 printf(" (%d)", length); |
703 return; 704 705 trunc: 706 printf("[|domain]"); 707 return; |
|
469} | 708} |