X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/454da6698381af918b5ec804874c8ca934b02817..05ec05a87b3a7c6983a16b5ae62d0f1512c4ce89:/print-domain.c diff --git a/print-domain.c b/print-domain.c index 6173521d..4bf1a52d 100644 --- a/print-domain.c +++ b/print-domain.c @@ -20,8 +20,8 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.85 2003-09-25 22:30:22 guy Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.98 2007-12-09 01:40:32 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -89,7 +89,6 @@ static const u_char * blabel_print(const u_char *cp) { int bitlen, slen, b; - int truncated = 0; const u_char *bitp, *lim; char tc; @@ -98,27 +97,28 @@ blabel_print(const u_char *cp) if ((bitlen = *cp) == 0) bitlen = 256; slen = (bitlen + 3) / 4; - if ((lim = cp + 1 + slen) > snapend) { - truncated = 1; - lim = snapend; - } + lim = cp + 1 + slen; /* print the bit string as a hex string */ printf("\\[x"); - for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) + for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) { + TCHECK(*bitp); printf("%02x", *bitp); - if (bitp == lim) - printf("..."); - else if (b > 4) { + } + if (b > 4) { + TCHECK(*bitp); tc = *bitp++; printf("%02x", tc & (0xff << (8 - b))); } else if (b > 0) { + TCHECK(*bitp); tc = *bitp++; printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b))); } printf("/%d]", bitlen); - - return(truncated ? NULL : lim); + return lim; +trunc: + printf(".../%d]", bitlen); + return NULL; } static int @@ -131,9 +131,10 @@ labellen(const u_char *cp) i = *cp; if ((i & INDIR_MASK) == EDNS0_MASK) { int bitlen, elt; - - if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) + if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) { + printf("", elt); return(-1); + } if (!TTEST2(*(cp + 1), 1)) return(-1); if ((bitlen = *(cp + 1)) == 0) @@ -143,7 +144,7 @@ labellen(const u_char *cp) return(i); } -static const u_char * +const u_char * ns_nprint(register const u_char *cp, register const u_char *bp) { register u_int i, l; @@ -277,9 +278,20 @@ struct tok ns_type2str[] = { { T_SRV, "SRV" }, /* RFC 2782 */ { T_ATMA, "ATMA" }, /* ATM Forum */ { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */ + { T_KX, "KX" }, /* RFC 2230 */ + { T_CERT, "CERT" }, /* RFC 2538 */ { T_A6, "A6" }, /* RFC 2874 */ { T_DNAME, "DNAME" }, /* RFC 2672 */ + { T_SINK, "SINK" }, { T_OPT, "OPT" }, /* RFC 2671 */ + { T_APL, "APL" }, /* RFC 3123 */ + { T_DS, "DS" }, /* RFC 4034 */ + { T_SSHFP, "SSHFP" }, /* RFC 4255 */ + { T_IPSECKEY, "IPSECKEY" }, /* RFC 4025 */ + { T_RRSIG, "RRSIG" }, /* RFC 4034 */ + { T_NSEC, "NSEC" }, /* RFC 4034 */ + { T_DNSKEY, "DNSKEY" }, /* RFC 4034 */ + { T_SPF, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */ { T_UINFO, "UINFO" }, { T_UID, "UID" }, { T_GID, "GID" }, @@ -305,24 +317,35 @@ struct tok ns_class2str[] = { /* print a query */ static const u_char * -ns_qprint(register const u_char *cp, register const u_char *bp) +ns_qprint(register const u_char *cp, register const u_char *bp, int is_mdns) { register const u_char *np = cp; - register u_int i; + register u_int i, class; cp = ns_nskip(cp); if (cp == NULL || !TTEST2(*cp, 4)) return(NULL); - /* print the qtype and qclass (if it's not IN) */ + /* print the qtype */ i = EXTRACT_16BITS(cp); cp += 2; printf(" %s", tok2str(ns_type2str, "Type%d", i)); + /* print the qclass (if it's not IN) */ i = EXTRACT_16BITS(cp); cp += 2; - if (i != C_IN) - printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); + if (is_mdns) + class = (i & ~C_QU); + else + class = i; + if (class != C_IN) + printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); + if (is_mdns) { + if (i & C_QU) + printf(" (QU)"); + else + printf(" (QM)"); + } fputs("? ", stdout); cp = ns_nprint(np, bp); @@ -331,9 +354,9 @@ ns_qprint(register const u_char *cp, register const u_char *bp) /* print a reply */ static const u_char * -ns_rprint(register const u_char *cp, register const u_char *bp) +ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) { - register u_int class; + register u_int i, class, opt_flags = 0; register u_short typ, len; register const u_char *rp; @@ -347,16 +370,39 @@ ns_rprint(register const u_char *cp, register const u_char *bp) if (cp == NULL || !TTEST2(*cp, 10)) return (snapend); - /* print the type/qtype and class (if it's not IN) */ + /* print the type/qtype */ typ = EXTRACT_16BITS(cp); cp += 2; - class = EXTRACT_16BITS(cp); + /* print the class (if it's not IN and the type isn't OPT) */ + i = EXTRACT_16BITS(cp); cp += 2; + if (is_mdns) + class = (i & ~C_CACHE_FLUSH); + else + class = i; if (class != C_IN && typ != T_OPT) printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); + if (is_mdns) { + if (i & C_CACHE_FLUSH) + printf(" (Cache flush)"); + } - /* ignore ttl */ - cp += 4; + if (typ == T_OPT) { + /* get opt flags */ + cp += 2; + opt_flags = EXTRACT_16BITS(cp); + /* ignore rest of ttl field */ + cp += 2; + } else if (vflag > 2) { + /* print ttl */ + printf(" ["); + relts_print(EXTRACT_32BITS(cp)); + printf("]"); + cp += 4; + } else { + /* ignore ttl */ + cp += 4; + } len = EXTRACT_16BITS(cp); cp += 2; @@ -371,7 +417,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) case T_A: if (!TTEST2(*cp, sizeof(struct in_addr))) return(NULL); - printf(" %s", ipaddr_string(cp)); + printf(" %s", intoa(htonl(EXTRACT_32BITS(cp)))); break; case T_NS: @@ -438,15 +484,24 @@ ns_rprint(register const u_char *cp, register const u_char *bp) #ifdef INET6 case T_AAAA: + { + struct in6_addr addr; + char ntop_buf[INET6_ADDRSTRLEN]; + if (!TTEST2(*cp, sizeof(struct in6_addr))) return(NULL); - printf(" %s", ip6addr_string(cp)); + memcpy(&addr, cp, sizeof(struct in6_addr)); + printf(" %s", + inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf))); + break; + } case T_A6: { struct in6_addr a; int pbit, pbyte; + char ntop_buf[INET6_ADDRSTRLEN]; if (!TTEST2(*cp, 1)) return(NULL); @@ -460,7 +515,8 @@ ns_rprint(register const u_char *cp, register const u_char *bp) return(NULL); memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); - printf(" %u %s", pbit, ip6addr_string(&a)); + printf(" %u %s", pbit, + inet_ntop(AF_INET6, &a, ntop_buf, sizeof(ntop_buf))); } if (pbit > 0) { putchar(' '); @@ -473,6 +529,8 @@ ns_rprint(register const u_char *cp, register const u_char *bp) case T_OPT: printf(" UDPsize=%u", class); + if (opt_flags & 0x8000) + printf(" OK"); break; case T_UNSPECA: /* One long string */ @@ -518,7 +576,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) } void -ns_print(register const u_char *bp, u_int length) +ns_print(register const u_char *bp, u_int length, int is_mdns) { register const HEADER *np; register int qdcount, ancount, nscount, arcount; @@ -535,7 +593,7 @@ ns_print(register const u_char *bp, u_int length) if (DNS_QR(np)) { /* this is a response */ - printf(" %d%s%s%s%s%s%s", + printf("%d%s%s%s%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], ns_resp[DNS_RCODE(np)], @@ -553,7 +611,7 @@ ns_print(register const u_char *bp, u_int length) putchar(','); if (vflag > 1) { fputs(" q:", stdout); - if ((cp = ns_qprint(cp, bp)) == NULL) + if ((cp = ns_qprint(cp, bp, is_mdns)) == NULL) goto trunc; } else { if ((cp = ns_nskip(cp)) == NULL) @@ -563,11 +621,11 @@ ns_print(register const u_char *bp, u_int length) } printf(" %d/%d/%d", ancount, nscount, arcount); if (ancount--) { - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && ancount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -577,11 +635,11 @@ ns_print(register const u_char *bp, u_int length) if (vflag > 1) { if (cp < snapend && nscount--) { fputs(" ns:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && nscount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -589,11 +647,11 @@ ns_print(register const u_char *bp, u_int length) goto trunc; if (cp < snapend && arcount--) { fputs(" ar:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && arcount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -603,7 +661,7 @@ ns_print(register const u_char *bp, u_int length) } else { /* this is a request */ - printf(" %d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], + printf("%d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], DNS_RD(np) ? "+" : "", DNS_CD(np) ? "%" : ""); @@ -631,12 +689,13 @@ ns_print(register const u_char *bp, u_int length) cp = (const u_char *)(np + 1); if (qdcount--) { - cp = ns_qprint(cp, (const u_char *)np); + cp = ns_qprint(cp, (const u_char *)np, is_mdns); if (!cp) goto trunc; while (cp < snapend && qdcount--) { cp = ns_qprint((const u_char *)cp, - (const u_char *)np); + (const u_char *)np, + is_mdns); if (!cp) goto trunc; } @@ -647,11 +706,11 @@ ns_print(register const u_char *bp, u_int length) /* Print remaining sections on -vv */ if (vflag > 1) { if (ancount--) { - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && ancount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -659,11 +718,11 @@ ns_print(register const u_char *bp, u_int length) goto trunc; if (cp < snapend && nscount--) { fputs(" ns:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (nscount-- && cp < snapend) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -671,11 +730,11 @@ ns_print(register const u_char *bp, u_int length) goto trunc; if (cp < snapend && arcount--) { fputs(" ar:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && arcount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } }