]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-domain.c
Pointers into packet data should usually be pointers to unsigned 1-byte
[tcpdump] / print-domain.c
index 6173521ddb3bf8690776a2e7f151837e7ae0122c..8e8bbecee645416e5bbac4913e1449f9d81aed89 100644 (file)
@@ -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.90 2005-04-20 20:59:30 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 %d>", 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;
@@ -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;
                                }
                        }
@@ -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;
                                }
                        }