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