]> The Tcpdump Group git mirrors - tcpdump/blob - print-domain.c
Add more nd_print_trunc() calls
[tcpdump] / print-domain.c
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
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
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
22 /* \summary: Domain Name System (DNS) printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "netdissect-stdinc.h"
29
30 #include <string.h>
31
32 #include "netdissect.h"
33 #include "addrtoname.h"
34 #include "addrtostr.h"
35 #include "extract.h"
36
37 #include "nameser.h"
38
39 static const char *ns_ops[] = {
40 "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7",
41 " op8", " updateA", " updateD", " updateDA",
42 " updateM", " updateMA", " zoneInit", " zoneRef",
43 };
44
45 static const char *ns_resp[] = {
46 "", " FormErr", " ServFail", " NXDomain",
47 " NotImp", " Refused", " YXDomain", " YXRRSet",
48 " NXRRSet", " NotAuth", " NotZone", " Resp11",
49 " Resp12", " Resp13", " Resp14", " NoChange",
50 };
51
52 /* skip over a domain name */
53 static const u_char *
54 ns_nskip(netdissect_options *ndo,
55 const u_char *cp)
56 {
57 u_char i;
58
59 if (!ND_TTEST_1(cp))
60 return (NULL);
61 i = EXTRACT_U_1(cp);
62 cp++;
63 while (i) {
64 if ((i & INDIR_MASK) == INDIR_MASK)
65 return (cp + 1);
66 if ((i & INDIR_MASK) == EDNS0_MASK) {
67 int bitlen, bytelen;
68
69 if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL)
70 return(NULL); /* unknown ELT */
71 if (!ND_TTEST_1(cp))
72 return (NULL);
73 if ((bitlen = EXTRACT_U_1(cp)) == 0)
74 bitlen = 256;
75 cp++;
76 bytelen = (bitlen + 7) / 8;
77 cp += bytelen;
78 } else
79 cp += i;
80 if (!ND_TTEST_1(cp))
81 return (NULL);
82 i = EXTRACT_U_1(cp);
83 cp++;
84 }
85 return (cp);
86 }
87
88 /* print a <domain-name> */
89 static const u_char *
90 blabel_print(netdissect_options *ndo,
91 const u_char *cp)
92 {
93 u_int bitlen, slen, b;
94 const u_char *bitp, *lim;
95 uint8_t tc;
96
97 if (!ND_TTEST_1(cp))
98 return(NULL);
99 if ((bitlen = EXTRACT_U_1(cp)) == 0)
100 bitlen = 256;
101 slen = (bitlen + 3) / 4;
102 lim = cp + 1 + slen;
103
104 /* print the bit string as a hex string */
105 ND_PRINT("\\[x");
106 for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) {
107 ND_TCHECK_1(bitp);
108 ND_PRINT("%02x", EXTRACT_U_1(bitp));
109 }
110 if (b > 4) {
111 ND_TCHECK_1(bitp);
112 tc = EXTRACT_U_1(bitp);
113 bitp++;
114 ND_PRINT("%02x", tc & (0xff << (8 - b)));
115 } else if (b > 0) {
116 ND_TCHECK_1(bitp);
117 tc = EXTRACT_U_1(bitp);
118 bitp++;
119 ND_PRINT("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
120 }
121 ND_PRINT("/%u]", bitlen);
122 return lim;
123 trunc:
124 ND_PRINT(".../%u]", bitlen);
125 return NULL;
126 }
127
128 static int
129 labellen(netdissect_options *ndo,
130 const u_char *cp)
131 {
132 u_int i;
133
134 if (!ND_TTEST_1(cp))
135 return(-1);
136 i = EXTRACT_U_1(cp);
137 if ((i & INDIR_MASK) == EDNS0_MASK) {
138 u_int bitlen, elt;
139 if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) {
140 ND_PRINT("<ELT %d>", elt);
141 return(-1);
142 }
143 if (!ND_TTEST_1(cp + 1))
144 return(-1);
145 if ((bitlen = EXTRACT_U_1(cp + 1)) == 0)
146 bitlen = 256;
147 return(((bitlen + 7) / 8) + 1);
148 } else
149 return(i);
150 }
151
152 const u_char *
153 ns_nprint(netdissect_options *ndo,
154 const u_char *cp, const u_char *bp)
155 {
156 u_int i, l;
157 const u_char *rp = NULL;
158 int compress = 0;
159 u_int elt;
160 u_int offset, max_offset;
161
162 if ((l = labellen(ndo, cp)) == (u_int)-1)
163 return(NULL);
164 if (!ND_TTEST_1(cp))
165 return(NULL);
166 max_offset = (u_int)(cp - bp);
167 i = EXTRACT_U_1(cp);
168 cp++;
169 if ((i & INDIR_MASK) != INDIR_MASK) {
170 compress = 0;
171 rp = cp + l;
172 }
173
174 if (i != 0)
175 while (i && cp < ndo->ndo_snapend) {
176 if ((i & INDIR_MASK) == INDIR_MASK) {
177 if (!compress) {
178 rp = cp + 1;
179 compress = 1;
180 }
181 if (!ND_TTEST_1(cp))
182 return(NULL);
183 offset = (((i << 8) | EXTRACT_U_1(cp)) & 0x3fff);
184 /*
185 * This must move backwards in the packet.
186 * No RFC explicitly says that, but BIND's
187 * name decompression code requires it,
188 * as a way of preventing infinite loops
189 * and other bad behavior, and it's probably
190 * what was intended (compress by pointing
191 * to domain name suffixes already seen in
192 * the packet).
193 */
194 if (offset >= max_offset) {
195 ND_PRINT("<BAD PTR>");
196 return(NULL);
197 }
198 max_offset = offset;
199 cp = bp + offset;
200 if ((l = labellen(ndo, cp)) == (u_int)-1)
201 return(NULL);
202 if (!ND_TTEST_1(cp))
203 return(NULL);
204 i = EXTRACT_U_1(cp);
205 cp++;
206 continue;
207 }
208 if ((i & INDIR_MASK) == EDNS0_MASK) {
209 elt = (i & ~INDIR_MASK);
210 switch(elt) {
211 case EDNS0_ELT_BITLABEL:
212 if (blabel_print(ndo, cp) == NULL)
213 return (NULL);
214 break;
215 default:
216 /* unknown ELT */
217 ND_PRINT("<ELT %u>", elt);
218 return(NULL);
219 }
220 } else {
221 if (nd_printn(ndo, cp, l, ndo->ndo_snapend))
222 return(NULL);
223 }
224
225 cp += l;
226 ND_PRINT(".");
227 if ((l = labellen(ndo, cp)) == (u_int)-1)
228 return(NULL);
229 if (!ND_TTEST_1(cp))
230 return(NULL);
231 i = EXTRACT_U_1(cp);
232 cp++;
233 if (!compress)
234 rp += l + 1;
235 }
236 else
237 ND_PRINT(".");
238 return (rp);
239 }
240
241 /* print a <character-string> */
242 static const u_char *
243 ns_cprint(netdissect_options *ndo,
244 const u_char *cp)
245 {
246 u_int i;
247
248 if (!ND_TTEST_1(cp))
249 return (NULL);
250 i = EXTRACT_U_1(cp);
251 cp++;
252 if (nd_printn(ndo, cp, i, ndo->ndo_snapend))
253 return (NULL);
254 return (cp + i);
255 }
256
257 extern const struct tok ns_type2str[];
258
259 /* http://www.iana.org/assignments/dns-parameters */
260 const struct tok ns_type2str[] = {
261 { T_A, "A" }, /* RFC 1035 */
262 { T_NS, "NS" }, /* RFC 1035 */
263 { T_MD, "MD" }, /* RFC 1035 */
264 { T_MF, "MF" }, /* RFC 1035 */
265 { T_CNAME, "CNAME" }, /* RFC 1035 */
266 { T_SOA, "SOA" }, /* RFC 1035 */
267 { T_MB, "MB" }, /* RFC 1035 */
268 { T_MG, "MG" }, /* RFC 1035 */
269 { T_MR, "MR" }, /* RFC 1035 */
270 { T_NULL, "NULL" }, /* RFC 1035 */
271 { T_WKS, "WKS" }, /* RFC 1035 */
272 { T_PTR, "PTR" }, /* RFC 1035 */
273 { T_HINFO, "HINFO" }, /* RFC 1035 */
274 { T_MINFO, "MINFO" }, /* RFC 1035 */
275 { T_MX, "MX" }, /* RFC 1035 */
276 { T_TXT, "TXT" }, /* RFC 1035 */
277 { T_RP, "RP" }, /* RFC 1183 */
278 { T_AFSDB, "AFSDB" }, /* RFC 1183 */
279 { T_X25, "X25" }, /* RFC 1183 */
280 { T_ISDN, "ISDN" }, /* RFC 1183 */
281 { T_RT, "RT" }, /* RFC 1183 */
282 { T_NSAP, "NSAP" }, /* RFC 1706 */
283 { T_NSAP_PTR, "NSAP_PTR" },
284 { T_SIG, "SIG" }, /* RFC 2535 */
285 { T_KEY, "KEY" }, /* RFC 2535 */
286 { T_PX, "PX" }, /* RFC 2163 */
287 { T_GPOS, "GPOS" }, /* RFC 1712 */
288 { T_AAAA, "AAAA" }, /* RFC 1886 */
289 { T_LOC, "LOC" }, /* RFC 1876 */
290 { T_NXT, "NXT" }, /* RFC 2535 */
291 { T_EID, "EID" }, /* Nimrod */
292 { T_NIMLOC, "NIMLOC" }, /* Nimrod */
293 { T_SRV, "SRV" }, /* RFC 2782 */
294 { T_ATMA, "ATMA" }, /* ATM Forum */
295 { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */
296 { T_KX, "KX" }, /* RFC 2230 */
297 { T_CERT, "CERT" }, /* RFC 2538 */
298 { T_A6, "A6" }, /* RFC 2874 */
299 { T_DNAME, "DNAME" }, /* RFC 2672 */
300 { T_SINK, "SINK" },
301 { T_OPT, "OPT" }, /* RFC 2671 */
302 { T_APL, "APL" }, /* RFC 3123 */
303 { T_DS, "DS" }, /* RFC 4034 */
304 { T_SSHFP, "SSHFP" }, /* RFC 4255 */
305 { T_IPSECKEY, "IPSECKEY" }, /* RFC 4025 */
306 { T_RRSIG, "RRSIG" }, /* RFC 4034 */
307 { T_NSEC, "NSEC" }, /* RFC 4034 */
308 { T_DNSKEY, "DNSKEY" }, /* RFC 4034 */
309 { T_SPF, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */
310 { T_UINFO, "UINFO" },
311 { T_UID, "UID" },
312 { T_GID, "GID" },
313 { T_UNSPEC, "UNSPEC" },
314 { T_UNSPECA, "UNSPECA" },
315 { T_TKEY, "TKEY" }, /* RFC 2930 */
316 { T_TSIG, "TSIG" }, /* RFC 2845 */
317 { T_IXFR, "IXFR" }, /* RFC 1995 */
318 { T_AXFR, "AXFR" }, /* RFC 1035 */
319 { T_MAILB, "MAILB" }, /* RFC 1035 */
320 { T_MAILA, "MAILA" }, /* RFC 1035 */
321 { T_ANY, "ANY" },
322 { 0, NULL }
323 };
324
325 extern const struct tok ns_class2str[];
326
327 const struct tok ns_class2str[] = {
328 { C_IN, "IN" }, /* Not used */
329 { C_CHAOS, "CHAOS" },
330 { C_HS, "HS" },
331 { C_ANY, "ANY" },
332 { 0, NULL }
333 };
334
335 /* print a query */
336 static const u_char *
337 ns_qprint(netdissect_options *ndo,
338 const u_char *cp, const u_char *bp, int is_mdns)
339 {
340 const u_char *np = cp;
341 u_int i, class;
342
343 cp = ns_nskip(ndo, cp);
344
345 if (cp == NULL || !ND_TTEST_4(cp))
346 return(NULL);
347
348 /* print the qtype */
349 i = EXTRACT_BE_U_2(cp);
350 cp += 2;
351 ND_PRINT(" %s", tok2str(ns_type2str, "Type%u", i));
352 /* print the qclass (if it's not IN) */
353 i = EXTRACT_BE_U_2(cp);
354 cp += 2;
355 if (is_mdns)
356 class = (i & ~C_QU);
357 else
358 class = i;
359 if (class != C_IN)
360 ND_PRINT(" %s", tok2str(ns_class2str, "(Class %u)", class));
361 if (is_mdns) {
362 ND_PRINT(i & C_QU ? " (QU)" : " (QM)");
363 }
364
365 ND_PRINT("? ");
366 cp = ns_nprint(ndo, np, bp);
367 return(cp ? cp + 4 : NULL);
368 }
369
370 /* print a reply */
371 static const u_char *
372 ns_rprint(netdissect_options *ndo,
373 const u_char *cp, const u_char *bp, int is_mdns)
374 {
375 u_int i, class, opt_flags = 0;
376 u_short typ, len;
377 const u_char *rp;
378
379 if (ndo->ndo_vflag) {
380 ND_PRINT(" ");
381 if ((cp = ns_nprint(ndo, cp, bp)) == NULL)
382 return NULL;
383 } else
384 cp = ns_nskip(ndo, cp);
385
386 if (cp == NULL || !ND_TTEST_LEN(cp, 10))
387 return (ndo->ndo_snapend);
388
389 /* print the type/qtype */
390 typ = EXTRACT_BE_U_2(cp);
391 cp += 2;
392 /* print the class (if it's not IN and the type isn't OPT) */
393 i = EXTRACT_BE_U_2(cp);
394 cp += 2;
395 if (is_mdns)
396 class = (i & ~C_CACHE_FLUSH);
397 else
398 class = i;
399 if (class != C_IN && typ != T_OPT)
400 ND_PRINT(" %s", tok2str(ns_class2str, "(Class %u)", class));
401 if (is_mdns) {
402 if (i & C_CACHE_FLUSH)
403 ND_PRINT(" (Cache flush)");
404 }
405
406 if (typ == T_OPT) {
407 /* get opt flags */
408 cp += 2;
409 opt_flags = EXTRACT_BE_U_2(cp);
410 /* ignore rest of ttl field */
411 cp += 2;
412 } else if (ndo->ndo_vflag > 2) {
413 /* print ttl */
414 ND_PRINT(" [");
415 unsigned_relts_print(ndo, EXTRACT_BE_U_4(cp));
416 ND_PRINT("]");
417 cp += 4;
418 } else {
419 /* ignore ttl */
420 cp += 4;
421 }
422
423 len = EXTRACT_BE_U_2(cp);
424 cp += 2;
425
426 rp = cp + len;
427
428 ND_PRINT(" %s", tok2str(ns_type2str, "Type%u", typ));
429 if (rp > ndo->ndo_snapend)
430 return(NULL);
431
432 switch (typ) {
433 case T_A:
434 if (!ND_TTEST_LEN(cp, sizeof(nd_ipv4)))
435 return(NULL);
436 ND_PRINT(" %s", intoa(EXTRACT_IPV4_TO_NETWORK_ORDER(cp)));
437 break;
438
439 case T_NS:
440 case T_CNAME:
441 case T_PTR:
442 #ifdef T_DNAME
443 case T_DNAME:
444 #endif
445 ND_PRINT(" ");
446 if (ns_nprint(ndo, cp, bp) == NULL)
447 return(NULL);
448 break;
449
450 case T_SOA:
451 if (!ndo->ndo_vflag)
452 break;
453 ND_PRINT(" ");
454 if ((cp = ns_nprint(ndo, cp, bp)) == NULL)
455 return(NULL);
456 ND_PRINT(" ");
457 if ((cp = ns_nprint(ndo, cp, bp)) == NULL)
458 return(NULL);
459 if (!ND_TTEST_LEN(cp, 5 * 4))
460 return(NULL);
461 ND_PRINT(" %u", EXTRACT_BE_U_4(cp));
462 cp += 4;
463 ND_PRINT(" %u", EXTRACT_BE_U_4(cp));
464 cp += 4;
465 ND_PRINT(" %u", EXTRACT_BE_U_4(cp));
466 cp += 4;
467 ND_PRINT(" %u", EXTRACT_BE_U_4(cp));
468 cp += 4;
469 ND_PRINT(" %u", EXTRACT_BE_U_4(cp));
470 cp += 4;
471 break;
472 case T_MX:
473 ND_PRINT(" ");
474 if (!ND_TTEST_2(cp))
475 return(NULL);
476 if (ns_nprint(ndo, cp + 2, bp) == NULL)
477 return(NULL);
478 ND_PRINT(" %u", EXTRACT_BE_U_2(cp));
479 break;
480
481 case T_TXT:
482 while (cp < rp) {
483 ND_PRINT(" \"");
484 cp = ns_cprint(ndo, cp);
485 if (cp == NULL)
486 return(NULL);
487 ND_PRINT("\"");
488 }
489 break;
490
491 case T_SRV:
492 ND_PRINT(" ");
493 if (!ND_TTEST_6(cp))
494 return(NULL);
495 if (ns_nprint(ndo, cp + 6, bp) == NULL)
496 return(NULL);
497 ND_PRINT(":%u %u %u", EXTRACT_BE_U_2(cp + 4),
498 EXTRACT_BE_U_2(cp), EXTRACT_BE_U_2(cp + 2));
499 break;
500
501 case T_AAAA:
502 {
503 char ntop_buf[INET6_ADDRSTRLEN];
504
505 if (!ND_TTEST_LEN(cp, sizeof(nd_ipv6)))
506 return(NULL);
507 ND_PRINT(" %s",
508 addrtostr6(cp, ntop_buf, sizeof(ntop_buf)));
509
510 break;
511 }
512
513 case T_A6:
514 {
515 struct in6_addr a;
516 int pbit, pbyte;
517 char ntop_buf[INET6_ADDRSTRLEN];
518
519 if (!ND_TTEST_1(cp))
520 return(NULL);
521 pbit = EXTRACT_U_1(cp);
522 pbyte = (pbit & ~7) / 8;
523 if (pbit > 128) {
524 ND_PRINT(" %u(bad plen)", pbit);
525 break;
526 } else if (pbit < 128) {
527 if (!ND_TTEST_LEN(cp + 1, sizeof(a) - pbyte))
528 return(NULL);
529 memset(&a, 0, sizeof(a));
530 memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte);
531 ND_PRINT(" %u %s", pbit,
532 addrtostr6(&a, ntop_buf, sizeof(ntop_buf)));
533 }
534 if (pbit > 0) {
535 ND_PRINT(" ");
536 if (ns_nprint(ndo, cp + 1 + sizeof(a) - pbyte, bp) == NULL)
537 return(NULL);
538 }
539 break;
540 }
541
542 case T_OPT:
543 ND_PRINT(" UDPsize=%u", class);
544 if (opt_flags & 0x8000)
545 ND_PRINT(" DO");
546 break;
547
548 case T_UNSPECA: /* One long string */
549 if (!ND_TTEST_LEN(cp, len))
550 return(NULL);
551 if (nd_printn(ndo, cp, len, ndo->ndo_snapend))
552 return(NULL);
553 break;
554
555 case T_TSIG:
556 {
557 if (cp + len > ndo->ndo_snapend)
558 return(NULL);
559 if (!ndo->ndo_vflag)
560 break;
561 ND_PRINT(" ");
562 if ((cp = ns_nprint(ndo, cp, bp)) == NULL)
563 return(NULL);
564 cp += 6;
565 if (!ND_TTEST_2(cp))
566 return(NULL);
567 ND_PRINT(" fudge=%u", EXTRACT_BE_U_2(cp));
568 cp += 2;
569 if (!ND_TTEST_2(cp))
570 return(NULL);
571 ND_PRINT(" maclen=%u", EXTRACT_BE_U_2(cp));
572 cp += 2 + EXTRACT_BE_U_2(cp);
573 if (!ND_TTEST_2(cp))
574 return(NULL);
575 ND_PRINT(" origid=%u", EXTRACT_BE_U_2(cp));
576 cp += 2;
577 if (!ND_TTEST_2(cp))
578 return(NULL);
579 ND_PRINT(" error=%u", EXTRACT_BE_U_2(cp));
580 cp += 2;
581 if (!ND_TTEST_2(cp))
582 return(NULL);
583 ND_PRINT(" otherlen=%u", EXTRACT_BE_U_2(cp));
584 cp += 2;
585 }
586 }
587 return (rp); /* XXX This isn't always right */
588 }
589
590 void
591 domain_print(netdissect_options *ndo,
592 const u_char *bp, u_int length, int is_mdns)
593 {
594 const dns_header_t *np;
595 uint16_t flags;
596 u_int qdcount, ancount, nscount, arcount;
597 u_int i;
598 const u_char *cp;
599 uint16_t b2;
600
601 ndo->ndo_protocol = "domain";
602 np = (const dns_header_t *)bp;
603 ND_TCHECK_SIZE(np);
604 flags = EXTRACT_BE_U_2(np->flags);
605 /* get the byte-order right */
606 qdcount = EXTRACT_BE_U_2(np->qdcount);
607 ancount = EXTRACT_BE_U_2(np->ancount);
608 nscount = EXTRACT_BE_U_2(np->nscount);
609 arcount = EXTRACT_BE_U_2(np->arcount);
610
611 if (DNS_QR(flags)) {
612 /* this is a response */
613 ND_PRINT("%u%s%s%s%s%s%s",
614 EXTRACT_BE_U_2(np->id),
615 ns_ops[DNS_OPCODE(flags)],
616 ns_resp[DNS_RCODE(flags)],
617 DNS_AA(flags)? "*" : "",
618 DNS_RA(flags)? "" : "-",
619 DNS_TC(flags)? "|" : "",
620 DNS_AD(flags)? "$" : "");
621
622 if (qdcount != 1)
623 ND_PRINT(" [%uq]", qdcount);
624 /* Print QUESTION section on -vv */
625 cp = (const u_char *)(np + 1);
626 for (i = 0; i < qdcount; i++) {
627 if (i != 0)
628 ND_PRINT(",");
629 if (ndo->ndo_vflag > 1) {
630 ND_PRINT(" q:");
631 if ((cp = ns_qprint(ndo, cp, bp, is_mdns)) == NULL)
632 goto trunc;
633 } else {
634 if ((cp = ns_nskip(ndo, cp)) == NULL)
635 goto trunc;
636 cp += 4; /* skip QTYPE and QCLASS */
637 }
638 }
639 ND_PRINT(" %u/%u/%u", ancount, nscount, arcount);
640 if (ancount) {
641 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
642 goto trunc;
643 ancount--;
644 while (cp < ndo->ndo_snapend && ancount) {
645 ND_PRINT(",");
646 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
647 goto trunc;
648 ancount--;
649 }
650 }
651 if (ancount)
652 goto trunc;
653 /* Print NS and AR sections on -vv */
654 if (ndo->ndo_vflag > 1) {
655 if (cp < ndo->ndo_snapend && nscount) {
656 ND_PRINT(" ns:");
657 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
658 goto trunc;
659 nscount--;
660 while (cp < ndo->ndo_snapend && nscount) {
661 ND_PRINT(",");
662 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
663 goto trunc;
664 nscount--;
665 }
666 }
667 if (nscount)
668 goto trunc;
669 if (cp < ndo->ndo_snapend && arcount) {
670 ND_PRINT(" ar:");
671 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
672 goto trunc;
673 arcount--;
674 while (cp < ndo->ndo_snapend && arcount) {
675 ND_PRINT(",");
676 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
677 goto trunc;
678 arcount--;
679 }
680 }
681 if (arcount)
682 goto trunc;
683 }
684 }
685 else {
686 /* this is a request */
687 ND_PRINT("%u%s%s%s", EXTRACT_BE_U_2(np->id), ns_ops[DNS_OPCODE(flags)],
688 DNS_RD(flags) ? "+" : "",
689 DNS_CD(flags) ? "%" : "");
690
691 /* any weirdness? */
692 b2 = EXTRACT_BE_U_2(((const u_short *)np) + 1);
693 if (b2 & 0x6cf)
694 ND_PRINT(" [b2&3=0x%x]", b2);
695
696 if (DNS_OPCODE(flags) == IQUERY) {
697 if (qdcount)
698 ND_PRINT(" [%uq]", qdcount);
699 if (ancount != 1)
700 ND_PRINT(" [%ua]", ancount);
701 }
702 else {
703 if (ancount)
704 ND_PRINT(" [%ua]", ancount);
705 if (qdcount != 1)
706 ND_PRINT(" [%uq]", qdcount);
707 }
708 if (nscount)
709 ND_PRINT(" [%un]", nscount);
710 if (arcount)
711 ND_PRINT(" [%uau]", arcount);
712
713 cp = (const u_char *)(np + 1);
714 if (qdcount) {
715 cp = ns_qprint(ndo, cp, (const u_char *)np, is_mdns);
716 if (!cp)
717 goto trunc;
718 qdcount--;
719 while (cp < ndo->ndo_snapend && qdcount) {
720 cp = ns_qprint(ndo, (const u_char *)cp,
721 (const u_char *)np,
722 is_mdns);
723 if (!cp)
724 goto trunc;
725 qdcount--;
726 }
727 }
728 if (qdcount)
729 goto trunc;
730
731 /* Print remaining sections on -vv */
732 if (ndo->ndo_vflag > 1) {
733 if (ancount) {
734 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
735 goto trunc;
736 ancount--;
737 while (cp < ndo->ndo_snapend && ancount) {
738 ND_PRINT(",");
739 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
740 goto trunc;
741 ancount--;
742 }
743 }
744 if (ancount)
745 goto trunc;
746 if (cp < ndo->ndo_snapend && nscount) {
747 ND_PRINT(" ns:");
748 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
749 goto trunc;
750 nscount--;
751 while (cp < ndo->ndo_snapend && nscount) {
752 ND_PRINT(",");
753 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
754 goto trunc;
755 nscount--;
756 }
757 }
758 if (nscount > 0)
759 goto trunc;
760 if (cp < ndo->ndo_snapend && arcount) {
761 ND_PRINT(" ar:");
762 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
763 goto trunc;
764 arcount--;
765 while (cp < ndo->ndo_snapend && arcount) {
766 ND_PRINT(",");
767 if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
768 goto trunc;
769 arcount--;
770 }
771 }
772 if (arcount)
773 goto trunc;
774 }
775 }
776 ND_PRINT(" (%u)", length);
777 return;
778
779 trunc:
780 nd_print_trunc(ndo);
781 }