]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-domain.c
Revert partially the commit 21b1273
[tcpdump] / print-domain.c
index 28c7f2b9a549647012e4a1b751af6c3bc12e97f1..ad08073f129c51d0468f4d8cfd85dbb38c399dcd 100644 (file)
@@ -116,25 +116,19 @@ blabel_print(netdissect_options *ndo,
        /* print the bit string as a hex string */
        ND_PRINT("\\[x");
        for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) {
-               ND_TCHECK_1(bitp);
                ND_PRINT("%02x", GET_U_1(bitp));
        }
        if (b > 4) {
-               ND_TCHECK_1(bitp);
                tc = GET_U_1(bitp);
                bitp++;
                ND_PRINT("%02x", tc & (0xff << (8 - b)));
        } else if (b > 0) {
-               ND_TCHECK_1(bitp);
                tc = GET_U_1(bitp);
                bitp++;
                ND_PRINT("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
        }
        ND_PRINT("/%u]", bitlen);
        return lim;
-trunc:
-       ND_PRINT(".../%u]", bitlen);
-       return NULL;
 }
 
 static int
@@ -842,7 +836,7 @@ ns_rprint(netdissect_options *ndo,
 
 void
 domain_print(netdissect_options *ndo,
-         const u_char *bp, u_int length, int is_mdns)
+             const u_char *bp, u_int length, int over_tcp, int is_mdns)
 {
        const dns_header_t *np;
        uint16_t flags, rcode, rdlen, type;
@@ -852,6 +846,34 @@ domain_print(netdissect_options *ndo,
        uint16_t b2;
 
        ndo->ndo_protocol = "domain";
+
+       if (over_tcp) {
+               /*
+                * The message is prefixed with a two byte length field
+                * which gives the message length, excluding the two byte
+                * length field. (RFC 1035 - 4.2.2. TCP usage)
+                */
+               if (length < 2) {
+                       ND_PRINT(" [DNS over TCP: length %u < 2]", length);
+                       nd_print_invalid(ndo);
+                       return;
+               } else {
+                       length -= 2; /* excluding the two byte length field */
+                       if (GET_BE_U_2(bp) != length) {
+                               ND_PRINT(" [prefix length(%u) != length(%u)]",
+                                        GET_BE_U_2(bp), length);
+                               nd_print_invalid(ndo);
+                               return;
+                       } else {
+                               bp += 2;
+                               /* in over TCP case, we need to prepend a space
+                                * (not needed in over UDP case)
+                                */
+                               ND_PRINT(" ");
+                       }
+               }
+       }
+
        np = (const dns_header_t *)bp;
 
        if(length < sizeof(*np)) {
@@ -900,7 +922,7 @@ domain_print(netdissect_options *ndo,
                if (cp + 1 > ndo->ndo_snapend)
                        goto print;
                if (type == T_OPT) {
-                       rcode |= (*cp << 4);
+                       rcode |= (GET_U_1(cp) << 4);
                        goto print;
                }
                cp += 4;