]>
The Tcpdump Group git mirrors - tcpdump/blob - print-domain.c
74c71dba0ca8e41eac48b21575f99be5e0f91dfe
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 switch (i
& TYPE_MASK
) {
85 if ((i
& ~TYPE_MASK
) != EDNS0_ELT_BITLABEL
)
86 return(NULL
); /* unknown ELT */
89 if ((bitlen
= GET_U_1(cp
)) == 0)
92 bytelen
= (bitlen
+ 7) / 8;
112 static const u_char
*
113 blabel_print(netdissect_options
*ndo
,
116 u_int bitlen
, slen
, b
;
117 const u_char
*bitp
, *lim
;
122 if ((bitlen
= GET_U_1(cp
)) == 0)
124 slen
= (bitlen
+ 3) / 4;
127 /* print the bit string as a hex string */
129 for (bitp
= cp
+ 1, b
= bitlen
; bitp
< lim
&& b
> 7; b
-= 8, bitp
++) {
130 ND_PRINT("%02x", GET_U_1(bitp
));
135 ND_PRINT("%02x", tc
& (0xff << (8 - b
)));
139 ND_PRINT("%1x", ((tc
>> 4) & 0x0f) & (0x0f << (4 - b
)));
141 ND_PRINT("/%u]", bitlen
);
146 labellen(netdissect_options
*ndo
,
154 switch (i
& TYPE_MASK
) {
158 if ((elt
= (i
& ~TYPE_MASK
)) != EDNS0_ELT_BITLABEL
) {
159 ND_PRINT("<ELT %d>", elt
);
162 if (!ND_TTEST_1(cp
+ 1))
164 if ((bitlen
= GET_U_1(cp
+ 1)) == 0)
166 return(((bitlen
+ 7) / 8) + 1);
175 * TYPE_RESERVED, but we use default to suppress compiler
176 * warnings about falling out of the switch statement.
178 ND_PRINT("<BAD LABEL TYPE>");
183 /* print a <domain-name> */
185 fqdn_print(netdissect_options
*ndo
,
186 const u_char
*cp
, const u_char
*bp
)
189 const u_char
*rp
= NULL
;
192 u_int offset
, max_offset
;
193 u_int name_chars
= 0;
195 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
199 max_offset
= (u_int
)(cp
- bp
);
202 if ((i
& TYPE_MASK
) != TYPE_INDIR
) {
208 while (i
&& cp
< ndo
->ndo_snapend
) {
209 switch (i
& TYPE_MASK
) {
218 offset
= (((i
<< 8) | GET_U_1(cp
)) & 0x3fff);
220 * This must move backwards in the packet.
221 * No RFC explicitly says that, but BIND's
222 * name decompression code requires it,
223 * as a way of preventing infinite loops
224 * and other bad behavior, and it's probably
225 * what was intended (compress by pointing
226 * to domain name suffixes already seen in
229 if (offset
>= max_offset
) {
230 ND_PRINT("<BAD PTR>");
238 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
244 elt
= (i
& ~TYPE_MASK
);
246 case EDNS0_ELT_BITLABEL
:
247 if (blabel_print(ndo
, cp
) == NULL
)
252 ND_PRINT("<ELT %u>", elt
);
258 ND_PRINT("<BAD LABEL TYPE>");
262 if (name_chars
+ l
<= MAXCDNAME
) {
263 if (nd_printn(ndo
, cp
, l
, ndo
->ndo_snapend
))
265 } else if (name_chars
< MAXCDNAME
) {
266 if (nd_printn(ndo
, cp
,
267 MAXCDNAME
- name_chars
, ndo
->ndo_snapend
))
275 if (name_chars
<= MAXCDNAME
)
281 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
287 if (name_chars
> MAXCDNAME
)
288 ND_PRINT("<DOMAIN NAME TOO LONG>");
294 /* print a <character-string> */
295 static const u_char
*
296 ns_cprint(netdissect_options
*ndo
,
305 if (nd_printn(ndo
, cp
, i
, ndo
->ndo_snapend
))
311 print_eopt_ecs(netdissect_options
*ndo
, const u_char
*cp
,
314 u_int family
, addr_bits
, src_len
, scope_len
;
317 char addr
[INET6_ADDRSTRLEN
];
319 /* ecs option must at least contain family, src len, and scope len */
321 nd_print_invalid(ndo
);
325 family
= GET_BE_U_2(cp
);
327 src_len
= GET_U_1(cp
);
329 scope_len
= GET_U_1(cp
);
334 else if (family
== 2)
337 nd_print_invalid(ndo
);
341 if (data_len
- 4 > (addr_bits
/ 8)) {
342 nd_print_invalid(ndo
);
345 /* checks for invalid ecs scope or source length */
346 if (src_len
> addr_bits
|| scope_len
> addr_bits
|| ((src_len
+ 7) / 8) != (data_len
- 4)) {
347 nd_print_invalid(ndo
);
351 /* pad the truncated address from ecs with zeros */
352 memset(padded
, 0, sizeof(padded
));
353 memcpy(padded
, cp
, data_len
- 4);
357 ND_PRINT("%s/%d/%d", addrtostr(padded
, addr
, INET_ADDRSTRLEN
),
360 ND_PRINT("%s/%d/%d", addrtostr6(padded
, addr
, INET6_ADDRSTRLEN
),
365 extern const struct tok edns_opt2str
[];
366 extern const struct tok dau_alg2str
[];
367 extern const struct tok dhu_alg2str
[];
368 extern const struct tok n3u_alg2str
[];
371 /* print an <EDNS-option> */
372 static const u_char
*
373 eopt_print(netdissect_options
*ndo
,
376 u_int opt
, data_len
, i
;
380 opt
= GET_BE_U_2(cp
);
382 ND_PRINT("%s", tok2str(edns_opt2str
, "Opt%u", opt
));
385 data_len
= GET_BE_U_2(cp
);
388 ND_TCHECK_LEN(cp
, data_len
);
395 print_eopt_ecs(ndo
, cp
, data_len
);
398 if (data_len
< 8 || (data_len
> 8 && data_len
< 16) || data_len
> 40)
399 nd_print_invalid(ndo
);
401 for (i
= 0; i
< data_len
; ++i
) {
402 /* split client and server cookie */
405 ND_PRINT("%02x", GET_U_1(cp
+ i
));
411 nd_print_invalid(ndo
);
413 /* keepalive is in increments of 100ms. Convert to seconds */
414 ND_PRINT("%0.1f sec", (GET_BE_U_2(cp
) / 10.0));
418 nd_print_invalid(ndo
);
420 ND_PRINT("%u sec", GET_BE_U_4(cp
));
423 /* ignore contents and just print length */
424 ND_PRINT("(%u)", data_len
);
427 if (data_len
% 2 != 0)
428 nd_print_invalid(ndo
);
430 for (i
= 0; i
< data_len
; i
+= 2) {
433 ND_PRINT("%u", GET_BE_U_2(cp
+ i
));
437 for (i
= 0; i
< data_len
; ++i
) {
440 ND_PRINT("%s", tok2str(dau_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
444 for (i
= 0; i
< data_len
; ++i
) {
447 ND_PRINT("%s", tok2str(dhu_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
451 for (i
= 0; i
< data_len
; ++i
) {
454 ND_PRINT("%s", tok2str(n3u_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
458 fqdn_print(ndo
, cp
, cp
+ data_len
);
461 /* intentional fall-through. NSID is an undefined byte string */
463 for (i
= 0; i
< data_len
; ++i
)
464 ND_PRINT("%02x", GET_U_1(cp
+ i
));
468 return (cp
+ data_len
);
477 extern const struct tok ns_type2str
[];
479 /* https://www.iana.org/assignments/dns-parameters */
480 const struct tok ns_type2str
[] = {
481 { T_A
, "A" }, /* RFC 1035 */
482 { T_NS
, "NS" }, /* RFC 1035 */
483 { T_MD
, "MD" }, /* RFC 1035 */
484 { T_MF
, "MF" }, /* RFC 1035 */
485 { T_CNAME
, "CNAME" }, /* RFC 1035 */
486 { T_SOA
, "SOA" }, /* RFC 1035 */
487 { T_MB
, "MB" }, /* RFC 1035 */
488 { T_MG
, "MG" }, /* RFC 1035 */
489 { T_MR
, "MR" }, /* RFC 1035 */
490 { T_NULL
, "NULL" }, /* RFC 1035 */
491 { T_WKS
, "WKS" }, /* RFC 1035 */
492 { T_PTR
, "PTR" }, /* RFC 1035 */
493 { T_HINFO
, "HINFO" }, /* RFC 1035 */
494 { T_MINFO
, "MINFO" }, /* RFC 1035 */
495 { T_MX
, "MX" }, /* RFC 1035 */
496 { T_TXT
, "TXT" }, /* RFC 1035 */
497 { T_RP
, "RP" }, /* RFC 1183 */
498 { T_AFSDB
, "AFSDB" }, /* RFC 1183 */
499 { T_X25
, "X25" }, /* RFC 1183 */
500 { T_ISDN
, "ISDN" }, /* RFC 1183 */
501 { T_RT
, "RT" }, /* RFC 1183 */
502 { T_NSAP
, "NSAP" }, /* RFC 1706 */
503 { T_NSAP_PTR
, "NSAP_PTR" },
504 { T_SIG
, "SIG" }, /* RFC 2535 */
505 { T_KEY
, "KEY" }, /* RFC 2535 */
506 { T_PX
, "PX" }, /* RFC 2163 */
507 { T_GPOS
, "GPOS" }, /* RFC 1712 */
508 { T_AAAA
, "AAAA" }, /* RFC 1886 */
509 { T_LOC
, "LOC" }, /* RFC 1876 */
510 { T_NXT
, "NXT" }, /* RFC 2535 */
511 { T_EID
, "EID" }, /* Nimrod */
512 { T_NIMLOC
, "NIMLOC" }, /* Nimrod */
513 { T_SRV
, "SRV" }, /* RFC 2782 */
514 { T_ATMA
, "ATMA" }, /* ATM Forum */
515 { T_NAPTR
, "NAPTR" }, /* RFC 2168, RFC 2915 */
516 { T_KX
, "KX" }, /* RFC 2230 */
517 { T_CERT
, "CERT" }, /* RFC 2538 */
518 { T_A6
, "A6" }, /* RFC 2874 */
519 { T_DNAME
, "DNAME" }, /* RFC 2672 */
521 { T_OPT
, "OPT" }, /* RFC 2671 */
522 { T_APL
, "APL" }, /* RFC 3123 */
523 { T_DS
, "DS" }, /* RFC 4034 */
524 { T_SSHFP
, "SSHFP" }, /* RFC 4255 */
525 { T_IPSECKEY
, "IPSECKEY" }, /* RFC 4025 */
526 { T_RRSIG
, "RRSIG" }, /* RFC 4034 */
527 { T_NSEC
, "NSEC" }, /* RFC 4034 */
528 { T_DNSKEY
, "DNSKEY" }, /* RFC 4034 */
529 { T_SPF
, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */
530 { T_UINFO
, "UINFO" },
533 { T_UNSPEC
, "UNSPEC" },
534 { T_UNSPECA
, "UNSPECA" },
535 { T_TKEY
, "TKEY" }, /* RFC 2930 */
536 { T_TSIG
, "TSIG" }, /* RFC 2845 */
537 { T_IXFR
, "IXFR" }, /* RFC 1995 */
538 { T_AXFR
, "AXFR" }, /* RFC 1035 */
539 { T_MAILB
, "MAILB" }, /* RFC 1035 */
540 { T_MAILA
, "MAILA" }, /* RFC 1035 */
542 { T_URI
, "URI" }, /* RFC 7553 */
546 extern const struct tok ns_class2str
[];
548 const struct tok ns_class2str
[] = {
549 { C_IN
, "IN" }, /* Not used */
550 { C_CHAOS
, "CHAOS" },
556 const struct tok edns_opt2str
[] = {
564 { E_EXPIRE
, "EXPIRE" },
565 { E_COOKIE
, "COOKIE" },
566 { E_KEEPALIVE
, "KEEPALIVE" },
567 { E_PADDING
, "PADDING" },
568 { E_CHAIN
, "CHAIN" },
569 { E_KEYTAG
, "KEY-TAG" },
570 { E_CLIENTTAG
, "CLIENT-TAG" },
571 { E_SERVERTAG
, "SERVER-TAG" },
575 const struct tok dau_alg2str
[] = {
576 { A_DELETE
, "DELETE" },
577 { A_RSAMD5
, "RSAMD5" },
580 { A_RSASHA1
, "RSASHA1" },
581 { A_DSA_NSEC3_SHA1
, "DSA-NSEC3-SHA1" },
582 { A_RSASHA1_NSEC3_SHA1
, "RSASHA1-NSEC3-SHA1" },
583 { A_RSASHA256
, "RSASHA256" },
584 { A_RSASHA512
, "RSASHA512" },
585 { A_ECC_GOST
, "ECC-GOST" },
586 { A_ECDSAP256SHA256
, "ECDSAP256SHA256" },
587 { A_ECDSAP384SHA384
, "ECDSAP384SHA384" },
588 { A_ED25519
, "ED25519" },
589 { A_ED448
, "ED448" },
590 { A_INDIRECT
, "INDIRECT" },
591 { A_PRIVATEDNS
, "PRIVATEDNS" },
592 { A_PRIVATEOID
, "PRIVATEOID" },
596 const struct tok dhu_alg2str
[] = {
597 { DS_SHA1
, "SHA-1" },
598 { DS_SHA256
,"SHA-256" },
599 { DS_GOST
, "GOST_R_34.11-94" },
600 { DS_SHA384
,"SHA-384" },
604 const struct tok n3u_alg2str
[] = {
605 { NSEC_SHA1
,"SHA-1" },
610 static const u_char
*
611 ns_qprint(netdissect_options
*ndo
,
612 const u_char
*cp
, const u_char
*bp
, int is_mdns
)
614 const u_char
*np
= cp
;
617 cp
= ns_nskip(ndo
, cp
);
619 if (cp
== NULL
|| !ND_TTEST_4(cp
))
622 /* print the qtype */
625 ND_PRINT(" %s", tok2str(ns_type2str
, "Type%u", i
));
626 /* print the qclass (if it's not IN) */
634 ND_PRINT(" %s", tok2str(ns_class2str
, "(Class %u)", class));
636 ND_PRINT(i
& C_QU
? " (QU)" : " (QM)");
640 cp
= fqdn_print(ndo
, np
, bp
);
641 return(cp
? cp
+ 4 : NULL
);
645 static const u_char
*
646 ns_rprint(netdissect_options
*ndo
,
647 const u_char
*cp
, const u_char
*bp
, int is_mdns
)
649 u_int i
, class, opt_flags
= 0;
653 if (ndo
->ndo_vflag
) {
655 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
658 cp
= ns_nskip(ndo
, cp
);
660 if (cp
== NULL
|| !ND_TTEST_LEN(cp
, 10))
661 return (ndo
->ndo_snapend
);
663 /* print the type/qtype */
664 typ
= GET_BE_U_2(cp
);
666 /* print the class (if it's not IN and the type isn't OPT) */
670 class = (i
& ~C_CACHE_FLUSH
);
673 if (class != C_IN
&& typ
!= T_OPT
)
674 ND_PRINT(" %s", tok2str(ns_class2str
, "(Class %u)", class));
676 if (i
& C_CACHE_FLUSH
)
677 ND_PRINT(" (Cache flush)");
683 opt_flags
= GET_BE_U_2(cp
);
684 /* ignore rest of ttl field */
686 } else if (ndo
->ndo_vflag
> 2) {
689 unsigned_relts_print(ndo
, GET_BE_U_4(cp
));
697 len
= GET_BE_U_2(cp
);
702 ND_PRINT(" %s", tok2str(ns_type2str
, "Type%u", typ
));
703 if (rp
> ndo
->ndo_snapend
)
708 if (!ND_TTEST_LEN(cp
, sizeof(nd_ipv4
)))
710 ND_PRINT(" %s", intoa(GET_IPV4_TO_NETWORK_ORDER(cp
)));
718 if (fqdn_print(ndo
, cp
, bp
) == NULL
)
726 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
729 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
731 if (!ND_TTEST_LEN(cp
, 5 * 4))
733 ND_PRINT(" %u", GET_BE_U_4(cp
));
735 ND_PRINT(" %u", GET_BE_U_4(cp
));
737 ND_PRINT(" %u", GET_BE_U_4(cp
));
739 ND_PRINT(" %u", GET_BE_U_4(cp
));
741 ND_PRINT(" %u", GET_BE_U_4(cp
));
748 if (fqdn_print(ndo
, cp
+ 2, bp
) == NULL
)
750 ND_PRINT(" %u", GET_BE_U_2(cp
));
756 cp
= ns_cprint(ndo
, cp
);
767 if (fqdn_print(ndo
, cp
+ 6, bp
) == NULL
)
769 ND_PRINT(":%u %u %u", GET_BE_U_2(cp
+ 4),
770 GET_BE_U_2(cp
), GET_BE_U_2(cp
+ 2));
775 char ntop_buf
[INET6_ADDRSTRLEN
];
777 if (!ND_TTEST_LEN(cp
, sizeof(nd_ipv6
)))
780 addrtostr6(cp
, ntop_buf
, sizeof(ntop_buf
)));
789 char ntop_buf
[INET6_ADDRSTRLEN
];
794 pbyte
= (pbit
& ~7) / 8;
796 ND_PRINT(" %u(bad plen)", pbit
);
798 } else if (pbit
< 128) {
799 if (!ND_TTEST_LEN(cp
+ 1, sizeof(a
) - pbyte
))
801 memset(a
, 0, sizeof(a
));
802 memcpy(a
+ pbyte
, cp
+ 1, sizeof(a
) - pbyte
);
803 ND_PRINT(" %u %s", pbit
,
804 addrtostr6(&a
, ntop_buf
, sizeof(ntop_buf
)));
808 if (fqdn_print(ndo
, cp
+ 1 + sizeof(a
) - pbyte
, bp
) == NULL
)
815 if (!ND_TTEST_LEN(cp
, len
))
817 ND_PRINT(" %u %u ", GET_BE_U_2(cp
), GET_BE_U_2(cp
+ 2));
818 if (nd_printn(ndo
, cp
+ 4, len
- 4, ndo
->ndo_snapend
))
823 ND_PRINT(" UDPsize=%u", class);
824 if (opt_flags
& 0x8000)
829 cp
= eopt_print(ndo
, cp
);
839 case T_UNSPECA
: /* One long string */
840 if (!ND_TTEST_LEN(cp
, len
))
842 if (nd_printn(ndo
, cp
, len
, ndo
->ndo_snapend
))
848 if (cp
+ len
> ndo
->ndo_snapend
)
853 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
858 ND_PRINT(" fudge=%u", GET_BE_U_2(cp
));
862 ND_PRINT(" maclen=%u", GET_BE_U_2(cp
));
863 cp
+= 2 + GET_BE_U_2(cp
);
866 ND_PRINT(" origid=%u", GET_BE_U_2(cp
));
870 ND_PRINT(" error=%u", GET_BE_U_2(cp
));
874 ND_PRINT(" otherlen=%u", GET_BE_U_2(cp
));
878 return (rp
); /* XXX This isn't always right */
882 domain_print(netdissect_options
*ndo
,
883 const u_char
*bp
, u_int length
, int over_tcp
, int is_mdns
)
885 const dns_header_t
*np
;
886 uint16_t flags
, rcode
, rdlen
, type
;
887 u_int qdcount
, ancount
, nscount
, arcount
;
892 ndo
->ndo_protocol
= "domain";
896 * The message is prefixed with a two byte length field
897 * which gives the message length, excluding the two byte
898 * length field. (RFC 1035 - 4.2.2. TCP usage)
901 ND_PRINT(" [DNS over TCP: length %u < 2]", length
);
902 nd_print_invalid(ndo
);
905 length
-= 2; /* excluding the two byte length field */
906 if (GET_BE_U_2(bp
) != length
) {
907 ND_PRINT(" [prefix length(%u) != length(%u)]",
908 GET_BE_U_2(bp
), length
);
909 nd_print_invalid(ndo
);
913 /* in over TCP case, we need to prepend a space
914 * (not needed in over UDP case)
921 np
= (const dns_header_t
*)bp
;
923 if(length
< sizeof(*np
)) {
924 nd_print_protocol(ndo
);
925 ND_PRINT(" [length %u < %zu]", length
, sizeof(*np
));
926 nd_print_invalid(ndo
);
931 flags
= GET_BE_U_2(np
->flags
);
932 /* get the byte-order right */
933 qdcount
= GET_BE_U_2(np
->qdcount
);
934 ancount
= GET_BE_U_2(np
->ancount
);
935 nscount
= GET_BE_U_2(np
->nscount
);
936 arcount
= GET_BE_U_2(np
->arcount
);
938 /* find the opt record to extract extended rcode */
939 cp
= (const u_char
*)(np
+ 1);
940 rcode
= DNS_RCODE(flags
);
941 for (i
= 0; i
< qdcount
; i
++) {
942 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
944 cp
+= 4; /* skip QTYPE and QCLASS */
945 if (cp
>= ndo
->ndo_snapend
)
948 for (i
= 0; i
< ancount
+ nscount
; i
++) {
949 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
951 cp
+= 8; /* skip TYPE, CLASS and TTL */
952 if (cp
+ 2 > ndo
->ndo_snapend
)
954 rdlen
= GET_BE_U_2(cp
);
956 if (cp
>= ndo
->ndo_snapend
)
959 for (i
= 0; i
< arcount
; i
++) {
960 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
962 if (cp
+ 2 > ndo
->ndo_snapend
)
964 type
= GET_BE_U_2(cp
);
965 cp
+= 4; /* skip TYPE and CLASS */
966 if (cp
+ 1 > ndo
->ndo_snapend
)
969 rcode
|= (GET_U_1(cp
) << 4);
973 if (cp
+ 2 > ndo
->ndo_snapend
)
975 rdlen
= GET_BE_U_2(cp
);
977 if (cp
>= ndo
->ndo_snapend
)
983 /* this is a response */
984 ND_PRINT("%u%s%s%s%s%s%s",
986 ns_ops
[DNS_OPCODE(flags
)],
988 DNS_AA(flags
)? "*" : "",
989 DNS_RA(flags
)? "" : "-",
990 DNS_TC(flags
)? "|" : "",
991 DNS_AD(flags
)? "$" : "");
994 ND_PRINT(" [%uq]", qdcount
);
995 /* Print QUESTION section on -vv */
996 cp
= (const u_char
*)(np
+ 1);
997 for (i
= 0; i
< qdcount
; i
++) {
1000 if (ndo
->ndo_vflag
> 1) {
1002 if ((cp
= ns_qprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1005 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
1007 cp
+= 4; /* skip QTYPE and QCLASS */
1010 ND_PRINT(" %u/%u/%u", ancount
, nscount
, arcount
);
1012 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1015 while (cp
< ndo
->ndo_snapend
&& ancount
) {
1017 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1024 /* Print NS and AR sections on -vv */
1025 if (ndo
->ndo_vflag
> 1) {
1026 if (cp
< ndo
->ndo_snapend
&& nscount
) {
1028 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1031 while (cp
< ndo
->ndo_snapend
&& nscount
) {
1033 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1040 if (cp
< ndo
->ndo_snapend
&& arcount
) {
1042 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1045 while (cp
< ndo
->ndo_snapend
&& arcount
) {
1047 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1057 /* this is a request */
1058 ND_PRINT("%u%s%s%s", GET_BE_U_2(np
->id
),
1059 ns_ops
[DNS_OPCODE(flags
)],
1060 DNS_RD(flags
) ? "+" : "",
1061 DNS_CD(flags
) ? "%" : "");
1063 /* any weirdness? */
1064 b2
= GET_BE_U_2(((const u_short
*)np
) + 1);
1066 ND_PRINT(" [b2&3=0x%x]", b2
);
1068 if (DNS_OPCODE(flags
) == IQUERY
) {
1070 ND_PRINT(" [%uq]", qdcount
);
1072 ND_PRINT(" [%ua]", ancount
);
1076 ND_PRINT(" [%ua]", ancount
);
1078 ND_PRINT(" [%uq]", qdcount
);
1081 ND_PRINT(" [%un]", nscount
);
1083 ND_PRINT(" [%uau]", arcount
);
1085 cp
= (const u_char
*)(np
+ 1);
1087 cp
= ns_qprint(ndo
, cp
, (const u_char
*)np
, is_mdns
);
1091 while (cp
< ndo
->ndo_snapend
&& qdcount
) {
1092 cp
= ns_qprint(ndo
, (const u_char
*)cp
,
1103 /* Print remaining sections on -vv */
1104 if (ndo
->ndo_vflag
> 1) {
1106 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1109 while (cp
< ndo
->ndo_snapend
&& ancount
) {
1111 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1118 if (cp
< ndo
->ndo_snapend
&& nscount
) {
1120 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1123 while (cp
< ndo
->ndo_snapend
&& nscount
) {
1125 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1132 if (cp
< ndo
->ndo_snapend
&& arcount
) {
1134 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1137 while (cp
< ndo
->ndo_snapend
&& arcount
) {
1139 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1148 ND_PRINT(" (%u)", length
);
1152 nd_print_trunc(ndo
);