]>
The Tcpdump Group git mirrors - tcpdump/blob - print-domain.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
22 /* \summary: Domain Name System (DNS) printer */
28 #include "netdissect-stdinc.h"
32 #include "netdissect.h"
33 #include "addrtoname.h"
34 #include "addrtostr.h"
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",
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 " BadVers", "Resp17", " Resp18", " Resp19",
51 " Resp20", "Resp21", " Resp22", " BadCookie",
55 ns_rcode(u_int rcode
) {
56 static char buf
[sizeof(" Resp4095")];
58 if (rcode
< sizeof(ns_resp
)/sizeof(ns_resp
[0])) {
59 return (ns_resp
[rcode
]);
61 snprintf(buf
, sizeof(buf
), " Resp%u", rcode
& 0xfff);
65 /* skip over a domain name */
67 ns_nskip(netdissect_options
*ndo
,
77 if ((i
& INDIR_MASK
) == INDIR_MASK
)
79 if ((i
& INDIR_MASK
) == EDNS0_MASK
) {
82 if ((i
& ~INDIR_MASK
) != EDNS0_ELT_BITLABEL
)
83 return(NULL
); /* unknown ELT */
86 if ((bitlen
= GET_U_1(cp
)) == 0)
89 bytelen
= (bitlen
+ 7) / 8;
101 static const u_char
*
102 blabel_print(netdissect_options
*ndo
,
105 u_int bitlen
, slen
, b
;
106 const u_char
*bitp
, *lim
;
111 if ((bitlen
= GET_U_1(cp
)) == 0)
113 slen
= (bitlen
+ 3) / 4;
116 /* print the bit string as a hex string */
118 for (bitp
= cp
+ 1, b
= bitlen
; bitp
< lim
&& b
> 7; b
-= 8, bitp
++) {
119 ND_PRINT("%02x", GET_U_1(bitp
));
124 ND_PRINT("%02x", tc
& (0xff << (8 - b
)));
128 ND_PRINT("%1x", ((tc
>> 4) & 0x0f) & (0x0f << (4 - b
)));
130 ND_PRINT("/%u]", bitlen
);
135 labellen(netdissect_options
*ndo
,
143 if ((i
& INDIR_MASK
) == EDNS0_MASK
) {
145 if ((elt
= (i
& ~INDIR_MASK
)) != EDNS0_ELT_BITLABEL
) {
146 ND_PRINT("<ELT %d>", elt
);
149 if (!ND_TTEST_1(cp
+ 1))
151 if ((bitlen
= GET_U_1(cp
+ 1)) == 0)
153 return(((bitlen
+ 7) / 8) + 1);
158 /* print a <domain-name> */
160 fqdn_print(netdissect_options
*ndo
,
161 const u_char
*cp
, const u_char
*bp
)
164 const u_char
*rp
= NULL
;
167 u_int offset
, max_offset
;
169 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
173 max_offset
= (u_int
)(cp
- bp
);
176 if ((i
& INDIR_MASK
) != INDIR_MASK
) {
182 while (i
&& cp
< ndo
->ndo_snapend
) {
183 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
190 offset
= (((i
<< 8) | GET_U_1(cp
)) & 0x3fff);
192 * This must move backwards in the packet.
193 * No RFC explicitly says that, but BIND's
194 * name decompression code requires it,
195 * as a way of preventing infinite loops
196 * and other bad behavior, and it's probably
197 * what was intended (compress by pointing
198 * to domain name suffixes already seen in
201 if (offset
>= max_offset
) {
202 ND_PRINT("<BAD PTR>");
207 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
215 if ((i
& INDIR_MASK
) == EDNS0_MASK
) {
216 elt
= (i
& ~INDIR_MASK
);
218 case EDNS0_ELT_BITLABEL
:
219 if (blabel_print(ndo
, cp
) == NULL
)
224 ND_PRINT("<ELT %u>", elt
);
228 if (nd_printn(ndo
, cp
, l
, ndo
->ndo_snapend
))
234 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
248 /* print a <character-string> */
249 static const u_char
*
250 ns_cprint(netdissect_options
*ndo
,
259 if (nd_printn(ndo
, cp
, i
, ndo
->ndo_snapend
))
265 print_eopt_ecs(netdissect_options
*ndo
, const u_char
*cp
,
268 u_int family
, addr_bits
, src_len
, scope_len
;
271 char addr
[INET6_ADDRSTRLEN
];
273 /* ecs option must at least contain family, src len, and scope len */
275 nd_print_invalid(ndo
);
279 family
= GET_BE_U_2(cp
);
281 src_len
= GET_U_1(cp
);
283 scope_len
= GET_U_1(cp
);
288 else if (family
== 2)
291 nd_print_invalid(ndo
);
295 if (data_len
- 4 > (addr_bits
/ 8)) {
296 nd_print_invalid(ndo
);
299 /* checks for invalid ecs scope or source length */
300 if (src_len
> addr_bits
|| scope_len
> addr_bits
|| ((src_len
+ 7) / 8) != (data_len
- 4)) {
301 nd_print_invalid(ndo
);
305 /* pad the truncated address from ecs with zeros */
306 memset(padded
, 0, sizeof(padded
));
307 memcpy(padded
, cp
, data_len
- 4);
311 ND_PRINT("%s/%d/%d", addrtostr(padded
, addr
, INET_ADDRSTRLEN
),
314 ND_PRINT("%s/%d/%d", addrtostr6(padded
, addr
, INET6_ADDRSTRLEN
),
319 extern const struct tok edns_opt2str
[];
320 extern const struct tok dau_alg2str
[];
321 extern const struct tok dhu_alg2str
[];
322 extern const struct tok n3u_alg2str
[];
325 /* print an <EDNS-option> */
326 static const u_char
*
327 eopt_print(netdissect_options
*ndo
,
330 u_int opt
, data_len
, i
;
334 opt
= GET_BE_U_2(cp
);
336 ND_PRINT("%s", tok2str(edns_opt2str
, "Opt%u", opt
));
339 data_len
= GET_BE_U_2(cp
);
342 ND_TCHECK_LEN(cp
, data_len
);
349 print_eopt_ecs(ndo
, cp
, data_len
);
352 if (data_len
< 8 || (data_len
> 8 && data_len
< 16) || data_len
> 40)
353 nd_print_invalid(ndo
);
355 for (i
= 0; i
< data_len
; ++i
) {
356 /* split client and server cookie */
359 ND_PRINT("%02x", GET_U_1(cp
+ i
));
365 nd_print_invalid(ndo
);
367 /* keepalive is in increments of 100ms. Convert to seconds */
368 ND_PRINT("%0.1f sec", (GET_BE_U_2(cp
) / 10.0));
372 nd_print_invalid(ndo
);
374 ND_PRINT("%u sec", GET_BE_U_4(cp
));
377 /* ignore contents and just print length */
378 ND_PRINT("(%u)", data_len
);
381 if (data_len
% 2 != 0)
382 nd_print_invalid(ndo
);
384 for (i
= 0; i
< data_len
; i
+= 2) {
387 ND_PRINT("%u", GET_BE_U_2(cp
+ i
));
391 for (i
= 0; i
< data_len
; ++i
) {
394 ND_PRINT("%s", tok2str(dau_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
398 for (i
= 0; i
< data_len
; ++i
) {
401 ND_PRINT("%s", tok2str(dhu_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
405 for (i
= 0; i
< data_len
; ++i
) {
408 ND_PRINT("%s", tok2str(n3u_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
412 fqdn_print(ndo
, cp
, cp
+ data_len
);
415 /* intentional fall-through. NSID is an undefined byte string */
417 for (i
= 0; i
< data_len
; ++i
)
418 ND_PRINT("%02x", GET_U_1(cp
+ i
));
422 return (cp
+ data_len
);
431 extern const struct tok ns_type2str
[];
433 /* https://www.iana.org/assignments/dns-parameters */
434 const struct tok ns_type2str
[] = {
435 { T_A
, "A" }, /* RFC 1035 */
436 { T_NS
, "NS" }, /* RFC 1035 */
437 { T_MD
, "MD" }, /* RFC 1035 */
438 { T_MF
, "MF" }, /* RFC 1035 */
439 { T_CNAME
, "CNAME" }, /* RFC 1035 */
440 { T_SOA
, "SOA" }, /* RFC 1035 */
441 { T_MB
, "MB" }, /* RFC 1035 */
442 { T_MG
, "MG" }, /* RFC 1035 */
443 { T_MR
, "MR" }, /* RFC 1035 */
444 { T_NULL
, "NULL" }, /* RFC 1035 */
445 { T_WKS
, "WKS" }, /* RFC 1035 */
446 { T_PTR
, "PTR" }, /* RFC 1035 */
447 { T_HINFO
, "HINFO" }, /* RFC 1035 */
448 { T_MINFO
, "MINFO" }, /* RFC 1035 */
449 { T_MX
, "MX" }, /* RFC 1035 */
450 { T_TXT
, "TXT" }, /* RFC 1035 */
451 { T_RP
, "RP" }, /* RFC 1183 */
452 { T_AFSDB
, "AFSDB" }, /* RFC 1183 */
453 { T_X25
, "X25" }, /* RFC 1183 */
454 { T_ISDN
, "ISDN" }, /* RFC 1183 */
455 { T_RT
, "RT" }, /* RFC 1183 */
456 { T_NSAP
, "NSAP" }, /* RFC 1706 */
457 { T_NSAP_PTR
, "NSAP_PTR" },
458 { T_SIG
, "SIG" }, /* RFC 2535 */
459 { T_KEY
, "KEY" }, /* RFC 2535 */
460 { T_PX
, "PX" }, /* RFC 2163 */
461 { T_GPOS
, "GPOS" }, /* RFC 1712 */
462 { T_AAAA
, "AAAA" }, /* RFC 1886 */
463 { T_LOC
, "LOC" }, /* RFC 1876 */
464 { T_NXT
, "NXT" }, /* RFC 2535 */
465 { T_EID
, "EID" }, /* Nimrod */
466 { T_NIMLOC
, "NIMLOC" }, /* Nimrod */
467 { T_SRV
, "SRV" }, /* RFC 2782 */
468 { T_ATMA
, "ATMA" }, /* ATM Forum */
469 { T_NAPTR
, "NAPTR" }, /* RFC 2168, RFC 2915 */
470 { T_KX
, "KX" }, /* RFC 2230 */
471 { T_CERT
, "CERT" }, /* RFC 2538 */
472 { T_A6
, "A6" }, /* RFC 2874 */
473 { T_DNAME
, "DNAME" }, /* RFC 2672 */
475 { T_OPT
, "OPT" }, /* RFC 2671 */
476 { T_APL
, "APL" }, /* RFC 3123 */
477 { T_DS
, "DS" }, /* RFC 4034 */
478 { T_SSHFP
, "SSHFP" }, /* RFC 4255 */
479 { T_IPSECKEY
, "IPSECKEY" }, /* RFC 4025 */
480 { T_RRSIG
, "RRSIG" }, /* RFC 4034 */
481 { T_NSEC
, "NSEC" }, /* RFC 4034 */
482 { T_DNSKEY
, "DNSKEY" }, /* RFC 4034 */
483 { T_SPF
, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */
484 { T_UINFO
, "UINFO" },
487 { T_UNSPEC
, "UNSPEC" },
488 { T_UNSPECA
, "UNSPECA" },
489 { T_TKEY
, "TKEY" }, /* RFC 2930 */
490 { T_TSIG
, "TSIG" }, /* RFC 2845 */
491 { T_IXFR
, "IXFR" }, /* RFC 1995 */
492 { T_AXFR
, "AXFR" }, /* RFC 1035 */
493 { T_MAILB
, "MAILB" }, /* RFC 1035 */
494 { T_MAILA
, "MAILA" }, /* RFC 1035 */
496 { T_URI
, "URI" }, /* RFC 7553 */
500 extern const struct tok ns_class2str
[];
502 const struct tok ns_class2str
[] = {
503 { C_IN
, "IN" }, /* Not used */
504 { C_CHAOS
, "CHAOS" },
510 const struct tok edns_opt2str
[] = {
518 { E_EXPIRE
, "EXPIRE" },
519 { E_COOKIE
, "COOKIE" },
520 { E_KEEPALIVE
, "KEEPALIVE" },
521 { E_PADDING
, "PADDING" },
522 { E_CHAIN
, "CHAIN" },
523 { E_KEYTAG
, "KEY-TAG" },
524 { E_CLIENTTAG
, "CLIENT-TAG" },
525 { E_SERVERTAG
, "SERVER-TAG" },
529 const struct tok dau_alg2str
[] = {
530 { A_DELETE
, "DELETE" },
531 { A_RSAMD5
, "RSAMD5" },
534 { A_RSASHA1
, "RSASHA1" },
535 { A_DSA_NSEC3_SHA1
, "DSA-NSEC3-SHA1" },
536 { A_RSASHA1_NSEC3_SHA1
, "RSASHA1-NSEC3-SHA1" },
537 { A_RSASHA256
, "RSASHA256" },
538 { A_RSASHA512
, "RSASHA512" },
539 { A_ECC_GOST
, "ECC-GOST" },
540 { A_ECDSAP256SHA256
, "ECDSAP256SHA256" },
541 { A_ECDSAP384SHA384
, "ECDSAP384SHA384" },
542 { A_ED25519
, "ED25519" },
543 { A_ED448
, "ED448" },
544 { A_INDIRECT
, "INDIRECT" },
545 { A_PRIVATEDNS
, "PRIVATEDNS" },
546 { A_PRIVATEOID
, "PRIVATEOID" },
550 const struct tok dhu_alg2str
[] = {
551 { DS_SHA1
, "SHA-1" },
552 { DS_SHA256
,"SHA-256" },
553 { DS_GOST
, "GOST_R_34.11-94" },
554 { DS_SHA384
,"SHA-384" },
558 const struct tok n3u_alg2str
[] = {
559 { NSEC_SHA1
,"SHA-1" },
564 static const u_char
*
565 ns_qprint(netdissect_options
*ndo
,
566 const u_char
*cp
, const u_char
*bp
, int is_mdns
)
568 const u_char
*np
= cp
;
571 cp
= ns_nskip(ndo
, cp
);
573 if (cp
== NULL
|| !ND_TTEST_4(cp
))
576 /* print the qtype */
579 ND_PRINT(" %s", tok2str(ns_type2str
, "Type%u", i
));
580 /* print the qclass (if it's not IN) */
588 ND_PRINT(" %s", tok2str(ns_class2str
, "(Class %u)", class));
590 ND_PRINT(i
& C_QU
? " (QU)" : " (QM)");
594 cp
= fqdn_print(ndo
, np
, bp
);
595 return(cp
? cp
+ 4 : NULL
);
599 static const u_char
*
600 ns_rprint(netdissect_options
*ndo
,
601 const u_char
*cp
, const u_char
*bp
, int is_mdns
)
603 u_int i
, class, opt_flags
= 0;
607 if (ndo
->ndo_vflag
) {
609 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
612 cp
= ns_nskip(ndo
, cp
);
614 if (cp
== NULL
|| !ND_TTEST_LEN(cp
, 10))
615 return (ndo
->ndo_snapend
);
617 /* print the type/qtype */
618 typ
= GET_BE_U_2(cp
);
620 /* print the class (if it's not IN and the type isn't OPT) */
624 class = (i
& ~C_CACHE_FLUSH
);
627 if (class != C_IN
&& typ
!= T_OPT
)
628 ND_PRINT(" %s", tok2str(ns_class2str
, "(Class %u)", class));
630 if (i
& C_CACHE_FLUSH
)
631 ND_PRINT(" (Cache flush)");
637 opt_flags
= GET_BE_U_2(cp
);
638 /* ignore rest of ttl field */
640 } else if (ndo
->ndo_vflag
> 2) {
643 unsigned_relts_print(ndo
, GET_BE_U_4(cp
));
651 len
= GET_BE_U_2(cp
);
656 ND_PRINT(" %s", tok2str(ns_type2str
, "Type%u", typ
));
657 if (rp
> ndo
->ndo_snapend
)
662 if (!ND_TTEST_LEN(cp
, sizeof(nd_ipv4
)))
664 ND_PRINT(" %s", intoa(GET_IPV4_TO_NETWORK_ORDER(cp
)));
674 if (fqdn_print(ndo
, cp
, bp
) == NULL
)
682 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
685 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
687 if (!ND_TTEST_LEN(cp
, 5 * 4))
689 ND_PRINT(" %u", GET_BE_U_4(cp
));
691 ND_PRINT(" %u", GET_BE_U_4(cp
));
693 ND_PRINT(" %u", GET_BE_U_4(cp
));
695 ND_PRINT(" %u", GET_BE_U_4(cp
));
697 ND_PRINT(" %u", GET_BE_U_4(cp
));
704 if (fqdn_print(ndo
, cp
+ 2, bp
) == NULL
)
706 ND_PRINT(" %u", GET_BE_U_2(cp
));
712 cp
= ns_cprint(ndo
, cp
);
723 if (fqdn_print(ndo
, cp
+ 6, bp
) == NULL
)
725 ND_PRINT(":%u %u %u", GET_BE_U_2(cp
+ 4),
726 GET_BE_U_2(cp
), GET_BE_U_2(cp
+ 2));
731 char ntop_buf
[INET6_ADDRSTRLEN
];
733 if (!ND_TTEST_LEN(cp
, sizeof(nd_ipv6
)))
736 addrtostr6(cp
, ntop_buf
, sizeof(ntop_buf
)));
745 char ntop_buf
[INET6_ADDRSTRLEN
];
750 pbyte
= (pbit
& ~7) / 8;
752 ND_PRINT(" %u(bad plen)", pbit
);
754 } else if (pbit
< 128) {
755 if (!ND_TTEST_LEN(cp
+ 1, sizeof(a
) - pbyte
))
757 memset(a
, 0, sizeof(a
));
758 memcpy(a
+ pbyte
, cp
+ 1, sizeof(a
) - pbyte
);
759 ND_PRINT(" %u %s", pbit
,
760 addrtostr6(&a
, ntop_buf
, sizeof(ntop_buf
)));
764 if (fqdn_print(ndo
, cp
+ 1 + sizeof(a
) - pbyte
, bp
) == NULL
)
771 if (!ND_TTEST_LEN(cp
, len
))
773 ND_PRINT(" %u %u ", GET_BE_U_2(cp
), GET_BE_U_2(cp
+ 2));
774 if (nd_printn(ndo
, cp
+ 4, len
- 4, ndo
->ndo_snapend
))
779 ND_PRINT(" UDPsize=%u", class);
780 if (opt_flags
& 0x8000)
785 cp
= eopt_print(ndo
, cp
);
795 case T_UNSPECA
: /* One long string */
796 if (!ND_TTEST_LEN(cp
, len
))
798 if (nd_printn(ndo
, cp
, len
, ndo
->ndo_snapend
))
804 if (cp
+ len
> ndo
->ndo_snapend
)
809 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
814 ND_PRINT(" fudge=%u", GET_BE_U_2(cp
));
818 ND_PRINT(" maclen=%u", GET_BE_U_2(cp
));
819 cp
+= 2 + GET_BE_U_2(cp
);
822 ND_PRINT(" origid=%u", GET_BE_U_2(cp
));
826 ND_PRINT(" error=%u", GET_BE_U_2(cp
));
830 ND_PRINT(" otherlen=%u", GET_BE_U_2(cp
));
834 return (rp
); /* XXX This isn't always right */
838 domain_print(netdissect_options
*ndo
,
839 const u_char
*bp
, u_int length
, int over_tcp
, int is_mdns
)
841 const dns_header_t
*np
;
842 uint16_t flags
, rcode
, rdlen
, type
;
843 u_int qdcount
, ancount
, nscount
, arcount
;
848 ndo
->ndo_protocol
= "domain";
852 * The message is prefixed with a two byte length field
853 * which gives the message length, excluding the two byte
854 * length field. (RFC 1035 - 4.2.2. TCP usage)
857 ND_PRINT(" [DNS over TCP: length %u < 2]", length
);
858 nd_print_invalid(ndo
);
861 length
-= 2; /* excluding the two byte length field */
862 if (GET_BE_U_2(bp
) != length
) {
863 ND_PRINT(" [prefix length(%u) != length(%u)]",
864 GET_BE_U_2(bp
), length
);
865 nd_print_invalid(ndo
);
869 /* in over TCP case, we need to prepend a space
870 * (not needed in over UDP case)
877 np
= (const dns_header_t
*)bp
;
879 if(length
< sizeof(*np
)) {
880 nd_print_protocol(ndo
);
881 ND_PRINT(" [length %u < %zu]", length
, sizeof(*np
));
882 nd_print_invalid(ndo
);
887 flags
= GET_BE_U_2(np
->flags
);
888 /* get the byte-order right */
889 qdcount
= GET_BE_U_2(np
->qdcount
);
890 ancount
= GET_BE_U_2(np
->ancount
);
891 nscount
= GET_BE_U_2(np
->nscount
);
892 arcount
= GET_BE_U_2(np
->arcount
);
894 /* find the opt record to extract extended rcode */
895 cp
= (const u_char
*)(np
+ 1);
896 rcode
= DNS_RCODE(flags
);
897 for (i
= 0; i
< qdcount
; i
++) {
898 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
900 cp
+= 4; /* skip QTYPE and QCLASS */
901 if (cp
>= ndo
->ndo_snapend
)
904 for (i
= 0; i
< ancount
+ nscount
; i
++) {
905 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
907 cp
+= 8; /* skip TYPE, CLASS and TTL */
908 if (cp
+ 2 > ndo
->ndo_snapend
)
910 rdlen
= GET_BE_U_2(cp
);
912 if (cp
>= ndo
->ndo_snapend
)
915 for (i
= 0; i
< arcount
; i
++) {
916 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
918 if (cp
+ 2 > ndo
->ndo_snapend
)
920 type
= GET_BE_U_2(cp
);
921 cp
+= 4; /* skip TYPE and CLASS */
922 if (cp
+ 1 > ndo
->ndo_snapend
)
925 rcode
|= (GET_U_1(cp
) << 4);
929 if (cp
+ 2 > ndo
->ndo_snapend
)
931 rdlen
= GET_BE_U_2(cp
);
933 if (cp
>= ndo
->ndo_snapend
)
939 /* this is a response */
940 ND_PRINT("%u%s%s%s%s%s%s",
942 ns_ops
[DNS_OPCODE(flags
)],
944 DNS_AA(flags
)? "*" : "",
945 DNS_RA(flags
)? "" : "-",
946 DNS_TC(flags
)? "|" : "",
947 DNS_AD(flags
)? "$" : "");
950 ND_PRINT(" [%uq]", qdcount
);
951 /* Print QUESTION section on -vv */
952 cp
= (const u_char
*)(np
+ 1);
953 for (i
= 0; i
< qdcount
; i
++) {
956 if (ndo
->ndo_vflag
> 1) {
958 if ((cp
= ns_qprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
961 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
963 cp
+= 4; /* skip QTYPE and QCLASS */
966 ND_PRINT(" %u/%u/%u", ancount
, nscount
, arcount
);
968 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
971 while (cp
< ndo
->ndo_snapend
&& ancount
) {
973 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
980 /* Print NS and AR sections on -vv */
981 if (ndo
->ndo_vflag
> 1) {
982 if (cp
< ndo
->ndo_snapend
&& nscount
) {
984 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
987 while (cp
< ndo
->ndo_snapend
&& nscount
) {
989 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
996 if (cp
< ndo
->ndo_snapend
&& arcount
) {
998 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1001 while (cp
< ndo
->ndo_snapend
&& arcount
) {
1003 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1013 /* this is a request */
1014 ND_PRINT("%u%s%s%s", GET_BE_U_2(np
->id
),
1015 ns_ops
[DNS_OPCODE(flags
)],
1016 DNS_RD(flags
) ? "+" : "",
1017 DNS_CD(flags
) ? "%" : "");
1019 /* any weirdness? */
1020 b2
= GET_BE_U_2(((const u_short
*)np
) + 1);
1022 ND_PRINT(" [b2&3=0x%x]", b2
);
1024 if (DNS_OPCODE(flags
) == IQUERY
) {
1026 ND_PRINT(" [%uq]", qdcount
);
1028 ND_PRINT(" [%ua]", ancount
);
1032 ND_PRINT(" [%ua]", ancount
);
1034 ND_PRINT(" [%uq]", qdcount
);
1037 ND_PRINT(" [%un]", nscount
);
1039 ND_PRINT(" [%uau]", arcount
);
1041 cp
= (const u_char
*)(np
+ 1);
1043 cp
= ns_qprint(ndo
, cp
, (const u_char
*)np
, is_mdns
);
1047 while (cp
< ndo
->ndo_snapend
&& qdcount
) {
1048 cp
= ns_qprint(ndo
, (const u_char
*)cp
,
1059 /* Print remaining sections on -vv */
1060 if (ndo
->ndo_vflag
> 1) {
1062 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1065 while (cp
< ndo
->ndo_snapend
&& ancount
) {
1067 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1074 if (cp
< ndo
->ndo_snapend
&& nscount
) {
1076 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1079 while (cp
< ndo
->ndo_snapend
&& nscount
) {
1081 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1088 if (cp
< ndo
->ndo_snapend
&& arcount
) {
1090 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1093 while (cp
< ndo
->ndo_snapend
&& arcount
) {
1095 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1104 ND_PRINT(" (%u)", length
);
1108 nd_print_trunc(ndo
);