]>
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 */
26 #include "netdissect-stdinc.h"
30 #include "netdissect.h"
31 #include "addrtoname.h"
32 #include "addrtostr.h"
37 static const char *ns_ops
[] = {
38 "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7",
39 " op8", " updateA", " updateD", " updateDA",
40 " updateM", " updateMA", " zoneInit", " zoneRef",
43 static const char *ns_resp
[] = {
44 "", " FormErr", " ServFail", " NXDomain",
45 " NotImp", " Refused", " YXDomain", " YXRRSet",
46 " NXRRSet", " NotAuth", " NotZone", " Resp11",
47 " Resp12", " Resp13", " Resp14", " NoChange",
48 " BadVers", "Resp17", " Resp18", " Resp19",
49 " Resp20", "Resp21", " Resp22", " BadCookie",
53 ns_rcode(u_int rcode
) {
54 static char buf
[sizeof(" Resp4095")];
56 if (rcode
< sizeof(ns_resp
)/sizeof(ns_resp
[0])) {
57 return (ns_resp
[rcode
]);
59 snprintf(buf
, sizeof(buf
), " Resp%u", rcode
& 0xfff);
63 /* skip over a domain name */
65 ns_nskip(netdissect_options
*ndo
,
75 switch (i
& TYPE_MASK
) {
83 if ((i
& ~TYPE_MASK
) != EDNS0_ELT_BITLABEL
)
84 return(NULL
); /* unknown ELT */
87 if ((bitlen
= GET_U_1(cp
)) == 0)
90 bytelen
= (bitlen
+ 7) / 8;
110 static const u_char
*
111 blabel_print(netdissect_options
*ndo
,
114 u_int bitlen
, slen
, b
;
115 const u_char
*bitp
, *lim
;
120 if ((bitlen
= GET_U_1(cp
)) == 0)
122 slen
= (bitlen
+ 3) / 4;
125 /* print the bit string as a hex string */
127 for (bitp
= cp
+ 1, b
= bitlen
; bitp
< lim
&& b
> 7; b
-= 8, bitp
++) {
128 ND_PRINT("%02x", GET_U_1(bitp
));
133 ND_PRINT("%02x", tc
& (0xff << (8 - b
)));
137 ND_PRINT("%1x", ((tc
>> 4) & 0x0f) & (0x0f << (4 - b
)));
139 ND_PRINT("/%u]", bitlen
);
144 labellen(netdissect_options
*ndo
,
152 switch (i
& TYPE_MASK
) {
156 if ((elt
= (i
& ~TYPE_MASK
)) != EDNS0_ELT_BITLABEL
) {
157 ND_PRINT("<ELT %d>", elt
);
160 if (!ND_TTEST_1(cp
+ 1))
162 if ((bitlen
= GET_U_1(cp
+ 1)) == 0)
164 return(((bitlen
+ 7) / 8) + 1);
173 * TYPE_RESERVED, but we use default to suppress compiler
174 * warnings about falling out of the switch statement.
176 ND_PRINT("<BAD LABEL TYPE>");
181 /* print a <domain-name> */
183 fqdn_print(netdissect_options
*ndo
,
184 const u_char
*cp
, const u_char
*bp
)
187 const u_char
*rp
= NULL
;
190 u_int offset
, max_offset
;
191 u_int name_chars
= 0;
193 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
197 max_offset
= (u_int
)(cp
- bp
);
200 if ((i
& TYPE_MASK
) != TYPE_INDIR
) {
206 while (i
&& cp
< ndo
->ndo_snapend
) {
207 switch (i
& TYPE_MASK
) {
216 offset
= (((i
<< 8) | GET_U_1(cp
)) & 0x3fff);
218 * This must move backwards in the packet.
219 * No RFC explicitly says that, but BIND's
220 * name decompression code requires it,
221 * as a way of preventing infinite loops
222 * and other bad behavior, and it's probably
223 * what was intended (compress by pointing
224 * to domain name suffixes already seen in
227 if (offset
>= max_offset
) {
228 ND_PRINT("<BAD PTR>");
236 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
242 elt
= (i
& ~TYPE_MASK
);
244 case EDNS0_ELT_BITLABEL
:
245 if (blabel_print(ndo
, cp
) == NULL
)
250 ND_PRINT("<ELT %u>", elt
);
256 ND_PRINT("<BAD LABEL TYPE>");
260 if (name_chars
+ l
<= MAXCDNAME
) {
261 if (nd_printn(ndo
, cp
, l
, ndo
->ndo_snapend
))
263 } else if (name_chars
< MAXCDNAME
) {
264 if (nd_printn(ndo
, cp
,
265 MAXCDNAME
- name_chars
, ndo
->ndo_snapend
))
273 if (name_chars
<= MAXCDNAME
)
279 if ((l
= labellen(ndo
, cp
)) == (u_int
)-1)
285 if (name_chars
> MAXCDNAME
)
286 ND_PRINT("<DOMAIN NAME TOO LONG>");
292 /* print a <character-string> */
293 static const u_char
*
294 ns_cprint(netdissect_options
*ndo
,
303 if (nd_printn(ndo
, cp
, i
, ndo
->ndo_snapend
))
309 print_eopt_ecs(netdissect_options
*ndo
, const u_char
*cp
,
312 u_int family
, addr_bits
, src_len
, scope_len
;
315 char addr
[INET6_ADDRSTRLEN
];
317 /* ecs option must at least contain family, src len, and scope len */
319 nd_print_invalid(ndo
);
323 family
= GET_BE_U_2(cp
);
325 src_len
= GET_U_1(cp
);
327 scope_len
= GET_U_1(cp
);
332 else if (family
== 2)
335 nd_print_invalid(ndo
);
339 if (data_len
- 4 > (addr_bits
/ 8)) {
340 nd_print_invalid(ndo
);
343 /* checks for invalid ecs scope or source length */
344 if (src_len
> addr_bits
|| scope_len
> addr_bits
|| ((src_len
+ 7) / 8) != (data_len
- 4)) {
345 nd_print_invalid(ndo
);
349 /* pad the truncated address from ecs with zeros */
350 memset(padded
, 0, sizeof(padded
));
351 memcpy(padded
, cp
, data_len
- 4);
355 ND_PRINT("%s/%d/%d", addrtostr(padded
, addr
, INET_ADDRSTRLEN
),
358 ND_PRINT("%s/%d/%d", addrtostr6(padded
, addr
, INET6_ADDRSTRLEN
),
363 extern const struct tok edns_opt2str
[];
364 extern const struct tok dau_alg2str
[];
365 extern const struct tok dhu_alg2str
[];
366 extern const struct tok n3u_alg2str
[];
369 /* print an <EDNS-option> */
370 static const u_char
*
371 eopt_print(netdissect_options
*ndo
,
374 u_int opt
, data_len
, i
;
378 opt
= GET_BE_U_2(cp
);
380 ND_PRINT("%s", tok2str(edns_opt2str
, "Opt%u", opt
));
383 data_len
= GET_BE_U_2(cp
);
386 ND_TCHECK_LEN(cp
, data_len
);
393 print_eopt_ecs(ndo
, cp
, data_len
);
396 if (data_len
< 8 || (data_len
> 8 && data_len
< 16) || data_len
> 40)
397 nd_print_invalid(ndo
);
399 for (i
= 0; i
< data_len
; ++i
) {
400 /* split client and server cookie */
403 ND_PRINT("%02x", GET_U_1(cp
+ i
));
409 nd_print_invalid(ndo
);
411 /* keepalive is in increments of 100ms. Convert to seconds */
412 ND_PRINT("%0.1f sec", (GET_BE_U_2(cp
) / 10.0));
416 nd_print_invalid(ndo
);
418 ND_PRINT("%u sec", GET_BE_U_4(cp
));
421 /* ignore contents and just print length */
422 ND_PRINT("(%u)", data_len
);
425 if (data_len
% 2 != 0)
426 nd_print_invalid(ndo
);
428 for (i
= 0; i
< data_len
; i
+= 2) {
431 ND_PRINT("%u", GET_BE_U_2(cp
+ i
));
435 for (i
= 0; i
< data_len
; ++i
) {
438 ND_PRINT("%s", tok2str(dau_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
442 for (i
= 0; i
< data_len
; ++i
) {
445 ND_PRINT("%s", tok2str(dhu_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
449 for (i
= 0; i
< data_len
; ++i
) {
452 ND_PRINT("%s", tok2str(n3u_alg2str
, "Alg_%u", GET_U_1(cp
+ i
)));
456 fqdn_print(ndo
, cp
, cp
+ data_len
);
459 /* intentional fall-through. NSID is an undefined byte string */
461 for (i
= 0; i
< data_len
; ++i
)
462 ND_PRINT("%02x", GET_U_1(cp
+ i
));
466 return (cp
+ data_len
);
475 extern const struct tok ns_type2str
[];
477 /* https://www.iana.org/assignments/dns-parameters */
478 const struct tok ns_type2str
[] = {
479 { T_A
, "A" }, /* RFC 1035 */
480 { T_NS
, "NS" }, /* RFC 1035 */
481 { T_MD
, "MD" }, /* RFC 1035 */
482 { T_MF
, "MF" }, /* RFC 1035 */
483 { T_CNAME
, "CNAME" }, /* RFC 1035 */
484 { T_SOA
, "SOA" }, /* RFC 1035 */
485 { T_MB
, "MB" }, /* RFC 1035 */
486 { T_MG
, "MG" }, /* RFC 1035 */
487 { T_MR
, "MR" }, /* RFC 1035 */
488 { T_NULL
, "NULL" }, /* RFC 1035 */
489 { T_WKS
, "WKS" }, /* RFC 1035 */
490 { T_PTR
, "PTR" }, /* RFC 1035 */
491 { T_HINFO
, "HINFO" }, /* RFC 1035 */
492 { T_MINFO
, "MINFO" }, /* RFC 1035 */
493 { T_MX
, "MX" }, /* RFC 1035 */
494 { T_TXT
, "TXT" }, /* RFC 1035 */
495 { T_RP
, "RP" }, /* RFC 1183 */
496 { T_AFSDB
, "AFSDB" }, /* RFC 5864 */
497 { T_X25
, "X25" }, /* RFC 1183 */
498 { T_ISDN
, "ISDN" }, /* RFC 1183 */
499 { T_RT
, "RT" }, /* RFC 1183 */
500 { T_NSAP
, "NSAP" }, /* RFC 1706 */
501 { T_NSAP_PTR
, "NSAP_PTR" }, /* RFC 1706 */
502 { T_SIG
, "SIG" }, /* RFC 3008 */
503 { T_KEY
, "KEY" }, /* RFC 3110 */
504 { T_PX
, "PX" }, /* RFC 2163 */
505 { T_GPOS
, "GPOS" }, /* RFC 1712 */
506 { T_AAAA
, "AAAA" }, /* RFC 3596 */
507 { T_LOC
, "LOC" }, /* RFC 1876 */
508 { T_NXT
, "NXT" }, /* RFC 3755 */
509 { T_EID
, "EID" }, /* Nimrod */
510 { T_NIMLOC
, "NIMLOC" }, /* Nimrod */
511 { T_SRV
, "SRV" }, /* RFC 2782 */
512 { T_ATMA
, "ATMA" }, /* ATM Forum */
513 { T_NAPTR
, "NAPTR" }, /* RFC 3403 */
514 { T_KX
, "KX" }, /* RFC 2230 */
515 { T_CERT
, "CERT" }, /* RFC 4398 */
516 { T_A6
, "A6" }, /* RFC 6563 */
517 { T_DNAME
, "DNAME" }, /* RFC 6672 */
519 { T_OPT
, "OPT" }, /* RFC 6891 */
520 { T_APL
, "APL" }, /* RFC 3123 */
521 { T_DS
, "DS" }, /* RFC 4034 */
522 { T_SSHFP
, "SSHFP" }, /* RFC 4255 */
523 { T_IPSECKEY
, "IPSECKEY" }, /* RFC 4025 */
524 { T_RRSIG
, "RRSIG" }, /* RFC 4034 */
525 { T_NSEC
, "NSEC" }, /* RFC 4034 */
526 { T_DNSKEY
, "DNSKEY" }, /* RFC 4034 */
527 { T_DHCID
, "DHCID" }, /* RFC 4071 */
528 { T_NSEC3
, "NSEC3" }, /* RFC 5155 */
529 { T_NSEC3PARAM
, "NSEC3PARAM" }, /* RFC 5155 */
530 { T_TLSA
, "TLSA" }, /* RFC 6698 */
531 { T_SMIMEA
, "SMIMEA" }, /* RFC 8162 */
532 { T_HIP
, "HIP" }, /* RFC 8005 */
533 { T_NINFO
, "NINFO" },
535 { T_TALINK
, "TALINK" },
536 { T_CDS
, "CDS" }, /* RFC 7344 */
537 { T_CDNSKEY
, "CDNSKEY" }, /* RFC 7344 */
538 { T_OPENPGPKEY
, "OPENPGPKEY" }, /* RFC 7929 */
539 { T_CSYNC
, "CSYNC" }, /* RFC 7477 */
540 { T_ZONEMD
, "ZONEMD" }, /* RFC 8976 */
542 { T_HTTPS
, "HTTPS" },
543 { T_SPF
, "SPF" }, /* RFC 7208 */
544 { T_UINFO
, "UINFO" },
547 { T_UNSPEC
, "UNSPEC" },
548 { T_NID
, "NID" }, /* RFC 6742 */
549 { T_L32
, "L32" }, /* RFC 6742 */
550 { T_L64
, "L64" }, /* RFC 6742 */
551 { T_LP
, "LP" }, /* RFC 6742 */
552 { T_EUI48
, "EUI48" }, /* RFC 7043 */
553 { T_EUI64
, "EUI64" }, /* RFC 7043 */
554 { T_TKEY
, "TKEY" }, /* RFC 2930 */
555 { T_TSIG
, "TSIG" }, /* RFC 8945 */
556 { T_IXFR
, "IXFR" }, /* RFC 1995 */
557 { T_AXFR
, "AXFR" }, /* RFC 5936 */
558 { T_MAILB
, "MAILB" }, /* RFC 1035 */
559 { T_MAILA
, "MAILA" }, /* RFC 1035 */
560 { T_ANY
, "ANY" }, /* RFC 8482 */
561 { T_URI
, "URI" }, /* RFC 7553 */
562 { T_CAA
, "CAA" }, /* RFC 8659 */
565 { T_AMTRELAY
, "AMTRELAY" }, /* RFC 8777 */
567 { T_DLV
, "DLV" }, /* RFC 8749 */
571 extern const struct tok ns_class2str
[];
573 const struct tok ns_class2str
[] = {
574 { C_IN
, "IN" }, /* Not used */
575 { C_CHAOS
, "CHAOS" },
581 const struct tok edns_opt2str
[] = {
589 { E_EXPIRE
, "EXPIRE" },
590 { E_COOKIE
, "COOKIE" },
591 { E_KEEPALIVE
, "KEEPALIVE" },
592 { E_PADDING
, "PADDING" },
593 { E_CHAIN
, "CHAIN" },
594 { E_KEYTAG
, "KEY-TAG" },
595 { E_CLIENTTAG
, "CLIENT-TAG" },
596 { E_SERVERTAG
, "SERVER-TAG" },
600 const struct tok dau_alg2str
[] = {
601 { A_DELETE
, "DELETE" },
602 { A_RSAMD5
, "RSAMD5" },
605 { A_RSASHA1
, "RSASHA1" },
606 { A_DSA_NSEC3_SHA1
, "DSA-NSEC3-SHA1" },
607 { A_RSASHA1_NSEC3_SHA1
, "RSASHA1-NSEC3-SHA1" },
608 { A_RSASHA256
, "RSASHA256" },
609 { A_RSASHA512
, "RSASHA512" },
610 { A_ECC_GOST
, "ECC-GOST" },
611 { A_ECDSAP256SHA256
, "ECDSAP256SHA256" },
612 { A_ECDSAP384SHA384
, "ECDSAP384SHA384" },
613 { A_ED25519
, "ED25519" },
614 { A_ED448
, "ED448" },
615 { A_INDIRECT
, "INDIRECT" },
616 { A_PRIVATEDNS
, "PRIVATEDNS" },
617 { A_PRIVATEOID
, "PRIVATEOID" },
621 const struct tok dhu_alg2str
[] = {
622 { DS_SHA1
, "SHA-1" },
623 { DS_SHA256
,"SHA-256" },
624 { DS_GOST
, "GOST_R_34.11-94" },
625 { DS_SHA384
,"SHA-384" },
629 const struct tok n3u_alg2str
[] = {
630 { NSEC_SHA1
,"SHA-1" },
635 static const u_char
*
636 ns_qprint(netdissect_options
*ndo
,
637 const u_char
*cp
, const u_char
*bp
, int is_mdns
)
639 const u_char
*np
= cp
;
642 cp
= ns_nskip(ndo
, cp
);
644 if (cp
== NULL
|| !ND_TTEST_4(cp
))
647 /* print the qtype */
650 ND_PRINT(" %s", tok2str(ns_type2str
, "Type%u", i
));
651 /* print the qclass (if it's not IN) */
659 ND_PRINT(" %s", tok2str(ns_class2str
, "(Class %u)", class));
661 ND_PRINT(i
& C_QU
? " (QU)" : " (QM)");
665 cp
= fqdn_print(ndo
, np
, bp
);
666 return(cp
? cp
+ 4 : NULL
);
670 static const u_char
*
671 ns_rprint(netdissect_options
*ndo
,
672 const u_char
*cp
, const u_char
*bp
, int is_mdns
)
674 u_int i
, class, opt_flags
= 0;
678 if (ndo
->ndo_vflag
) {
680 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
683 cp
= ns_nskip(ndo
, cp
);
685 if (cp
== NULL
|| !ND_TTEST_LEN(cp
, 10))
686 return (ndo
->ndo_snapend
);
688 /* print the type/qtype */
689 typ
= GET_BE_U_2(cp
);
691 /* print the class (if it's not IN and the type isn't OPT) */
695 class = (i
& ~C_CACHE_FLUSH
);
698 if (class != C_IN
&& typ
!= T_OPT
)
699 ND_PRINT(" %s", tok2str(ns_class2str
, "(Class %u)", class));
701 if (i
& C_CACHE_FLUSH
)
702 ND_PRINT(" (Cache flush)");
708 opt_flags
= GET_BE_U_2(cp
);
709 /* ignore rest of ttl field */
711 } else if (ndo
->ndo_vflag
> 2) {
714 unsigned_relts_print(ndo
, GET_BE_U_4(cp
));
722 len
= GET_BE_U_2(cp
);
725 ND_PRINT(" %s", tok2str(ns_type2str
, "Type%u", typ
));
727 ND_TCHECK_LEN(cp
, len
);
732 if (!ND_TTEST_LEN(cp
, sizeof(nd_ipv4
)))
734 ND_PRINT(" %s", intoa(GET_IPV4_TO_NETWORK_ORDER(cp
)));
742 if (fqdn_print(ndo
, cp
, bp
) == NULL
)
750 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
753 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
755 if (!ND_TTEST_LEN(cp
, 5 * 4))
757 ND_PRINT(" %u", GET_BE_U_4(cp
));
759 ND_PRINT(" %u", GET_BE_U_4(cp
));
761 ND_PRINT(" %u", GET_BE_U_4(cp
));
763 ND_PRINT(" %u", GET_BE_U_4(cp
));
765 ND_PRINT(" %u", GET_BE_U_4(cp
));
772 if (fqdn_print(ndo
, cp
+ 2, bp
) == NULL
)
774 ND_PRINT(" %u", GET_BE_U_2(cp
));
780 cp
= ns_cprint(ndo
, cp
);
791 if (fqdn_print(ndo
, cp
+ 6, bp
) == NULL
)
793 ND_PRINT(":%u %u %u", GET_BE_U_2(cp
+ 4),
794 GET_BE_U_2(cp
), GET_BE_U_2(cp
+ 2));
799 char ntop_buf
[INET6_ADDRSTRLEN
];
801 if (!ND_TTEST_LEN(cp
, sizeof(nd_ipv6
)))
804 addrtostr6(cp
, ntop_buf
, sizeof(ntop_buf
)));
813 char ntop_buf
[INET6_ADDRSTRLEN
];
818 pbyte
= (pbit
& ~7) / 8;
820 ND_PRINT(" %u(bad plen)", pbit
);
822 } else if (pbit
< 128) {
823 memset(a
, 0, sizeof(a
));
824 GET_CPY_BYTES(a
+ pbyte
, cp
+ 1, sizeof(a
) - pbyte
);
825 ND_PRINT(" %u %s", pbit
,
826 addrtostr6(&a
, ntop_buf
, sizeof(ntop_buf
)));
830 if (fqdn_print(ndo
, cp
+ 1 + sizeof(a
) - pbyte
, bp
) == NULL
)
837 if (!ND_TTEST_LEN(cp
, len
))
840 ND_PRINT(" len %u is too short (< 4)", len
);
843 ND_PRINT(" %u %u ", GET_BE_U_2(cp
), GET_BE_U_2(cp
+ 2));
844 if (nd_printn(ndo
, cp
+ 4, len
- 4, ndo
->ndo_snapend
))
849 ND_PRINT(" UDPsize=%u", class);
850 if (opt_flags
& 0x8000)
855 cp
= eopt_print(ndo
, cp
);
867 if (cp
+ len
> ndo
->ndo_snapend
)
872 if ((cp
= fqdn_print(ndo
, cp
, bp
)) == NULL
)
877 ND_PRINT(" fudge=%u", GET_BE_U_2(cp
));
881 ND_PRINT(" maclen=%u", GET_BE_U_2(cp
));
882 cp
+= 2 + GET_BE_U_2(cp
);
885 ND_PRINT(" origid=%u", GET_BE_U_2(cp
));
889 ND_PRINT(" error=%u", GET_BE_U_2(cp
));
893 ND_PRINT(" otherlen=%u", GET_BE_U_2(cp
));
897 return (rp
); /* XXX This isn't always right */
904 domain_print(netdissect_options
*ndo
,
905 const u_char
*bp
, u_int length
, int over_tcp
, int is_mdns
)
907 const dns_header_t
*np
;
908 uint16_t flags
, rcode
, rdlen
, type
;
909 u_int qdcount
, ancount
, nscount
, arcount
;
914 ndo
->ndo_protocol
= "domain";
918 * The message is prefixed with a two byte length field
919 * which gives the message length, excluding the two byte
920 * length field. (RFC 1035 - 4.2.2. TCP usage)
923 ND_PRINT(" [DNS over TCP: length %u < 2]", length
);
924 nd_print_invalid(ndo
);
927 length
-= 2; /* excluding the two byte length field */
928 if (GET_BE_U_2(bp
) != length
) {
929 ND_PRINT(" [prefix length(%u) != length(%u)]",
930 GET_BE_U_2(bp
), length
);
931 nd_print_invalid(ndo
);
935 /* in over TCP case, we need to prepend a space
936 * (not needed in over UDP case)
943 np
= (const dns_header_t
*)bp
;
945 if(length
< sizeof(*np
)) {
946 nd_print_protocol(ndo
);
947 ND_PRINT(" [length %u < %zu]", length
, sizeof(*np
));
948 nd_print_invalid(ndo
);
953 flags
= GET_BE_U_2(np
->flags
);
954 /* get the byte-order right */
955 qdcount
= GET_BE_U_2(np
->qdcount
);
956 ancount
= GET_BE_U_2(np
->ancount
);
957 nscount
= GET_BE_U_2(np
->nscount
);
958 arcount
= GET_BE_U_2(np
->arcount
);
960 /* find the opt record to extract extended rcode */
961 cp
= (const u_char
*)(np
+ 1);
962 rcode
= DNS_RCODE(flags
);
963 for (i
= 0; i
< qdcount
; i
++) {
964 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
966 cp
+= 4; /* skip QTYPE and QCLASS */
967 if (cp
>= ndo
->ndo_snapend
)
970 for (i
= 0; i
< ancount
+ nscount
; i
++) {
971 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
973 cp
+= 8; /* skip TYPE, CLASS and TTL */
974 if (cp
+ 2 > ndo
->ndo_snapend
)
976 rdlen
= GET_BE_U_2(cp
);
978 if (cp
>= ndo
->ndo_snapend
)
981 for (i
= 0; i
< arcount
; i
++) {
982 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
984 if (cp
+ 2 > ndo
->ndo_snapend
)
986 type
= GET_BE_U_2(cp
);
987 cp
+= 4; /* skip TYPE and CLASS */
988 if (cp
+ 1 > ndo
->ndo_snapend
)
991 rcode
|= (GET_U_1(cp
) << 4);
995 if (cp
+ 2 > ndo
->ndo_snapend
)
997 rdlen
= GET_BE_U_2(cp
);
999 if (cp
>= ndo
->ndo_snapend
)
1004 if (DNS_QR(flags
)) {
1005 /* this is a response */
1006 ND_PRINT("%u%s%s%s%s%s%s",
1008 ns_ops
[DNS_OPCODE(flags
)],
1010 DNS_AA(flags
)? "*" : "",
1011 DNS_RA(flags
)? "" : "-",
1012 DNS_TC(flags
)? "|" : "",
1013 DNS_AD(flags
)? "$" : "");
1016 ND_PRINT(" [%uq]", qdcount
);
1017 /* Print QUESTION section on -vv */
1018 cp
= (const u_char
*)(np
+ 1);
1019 for (i
= 0; i
< qdcount
; i
++) {
1022 if (ndo
->ndo_vflag
> 1) {
1024 if ((cp
= ns_qprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1027 if ((cp
= ns_nskip(ndo
, cp
)) == NULL
)
1029 cp
+= 4; /* skip QTYPE and QCLASS */
1032 ND_PRINT(" %u/%u/%u", ancount
, nscount
, arcount
);
1034 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1037 while (cp
< ndo
->ndo_snapend
&& ancount
) {
1039 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1046 /* Print NS and AR sections on -vv */
1047 if (ndo
->ndo_vflag
> 1) {
1048 if (cp
< ndo
->ndo_snapend
&& nscount
) {
1050 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1053 while (cp
< ndo
->ndo_snapend
&& nscount
) {
1055 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1062 if (cp
< ndo
->ndo_snapend
&& arcount
) {
1064 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1067 while (cp
< ndo
->ndo_snapend
&& arcount
) {
1069 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1078 /* this is a request */
1079 ND_PRINT("%u%s%s%s", GET_BE_U_2(np
->id
),
1080 ns_ops
[DNS_OPCODE(flags
)],
1081 DNS_RD(flags
) ? "+" : "",
1082 DNS_CD(flags
) ? "%" : "");
1084 /* any weirdness? */
1085 b2
= GET_BE_U_2(((const u_short
*)np
) + 1);
1087 ND_PRINT(" [b2&3=0x%x]", b2
);
1089 if (DNS_OPCODE(flags
) == IQUERY
) {
1091 ND_PRINT(" [%uq]", qdcount
);
1093 ND_PRINT(" [%ua]", ancount
);
1096 ND_PRINT(" [%ua]", ancount
);
1098 ND_PRINT(" [%uq]", qdcount
);
1101 ND_PRINT(" [%un]", nscount
);
1103 ND_PRINT(" [%uau]", arcount
);
1105 cp
= (const u_char
*)(np
+ 1);
1107 cp
= ns_qprint(ndo
, cp
, (const u_char
*)np
, is_mdns
);
1111 while (cp
< ndo
->ndo_snapend
&& qdcount
) {
1112 cp
= ns_qprint(ndo
, (const u_char
*)cp
,
1123 /* Print remaining sections on -vv */
1124 if (ndo
->ndo_vflag
> 1) {
1126 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1129 while (cp
< ndo
->ndo_snapend
&& ancount
) {
1131 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1138 if (cp
< ndo
->ndo_snapend
&& nscount
) {
1140 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1143 while (cp
< ndo
->ndo_snapend
&& nscount
) {
1145 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1152 if (cp
< ndo
->ndo_snapend
&& arcount
) {
1154 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1157 while (cp
< ndo
->ndo_snapend
&& arcount
) {
1159 if ((cp
= ns_rprint(ndo
, cp
, bp
, is_mdns
)) == NULL
)
1168 ND_PRINT(" (%u)", length
);
1172 nd_print_trunc(ndo
);