X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/39727479314a287fae9a03c63d8a98f9725d6051..01fe0ebe27b2fe957f699ffa4dbdedc46e12f85b:/print-domain.c diff --git a/print-domain.c b/print-domain.c index 0ffa872d..a50e5918 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.84 2003-04-04 03:49:25 fenner Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.89.2.1 2005-04-20 20:59:00 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) @@ -305,7 +306,7 @@ 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; @@ -321,7 +322,9 @@ ns_qprint(register const u_char *cp, register const u_char *bp) printf(" %s", tok2str(ns_type2str, "Type%d", i)); i = EXTRACT_16BITS(cp); cp += 2; - if (i != C_IN) + if (is_mdns && i == (C_IN|C_CACHE_FLUSH)) + printf(" (Cache flush)"); + else if (i != C_IN) printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); fputs("? ", stdout); @@ -331,7 +334,7 @@ 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_short typ, len; @@ -352,7 +355,9 @@ ns_rprint(register const u_char *cp, register const u_char *bp) cp += 2; class = EXTRACT_16BITS(cp); cp += 2; - if (class != C_IN && typ != T_OPT) + if (is_mdns && class == (C_IN|C_CACHE_FLUSH)) + printf(" (Cache flush)"); + else if (class != C_IN && typ != T_OPT) printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); /* ignore ttl */ @@ -518,7 +523,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; @@ -542,7 +547,7 @@ ns_print(register const u_char *bp, u_int length) DNS_AA(np)? "*" : "", DNS_RA(np)? "" : "-", DNS_TC(np)? "|" : "", - DNS_CD(np)? "%" : ""); + DNS_AD(np)? "$" : ""); if (qdcount != 1) printf(" [%dq]", qdcount); @@ -553,7 +558,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 +568,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 +582,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 +594,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; } } @@ -605,7 +610,7 @@ ns_print(register const u_char *bp, u_int length) /* this is a request */ printf(" %d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], DNS_RD(np) ? "+" : "", - DNS_AD(np) ? "$" : ""); + DNS_CD(np) ? "%" : ""); /* any weirdness? */ b2 = EXTRACT_16BITS(((u_short *)np)+1); @@ -631,12 +636,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 +653,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 +665,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 +677,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; } }