]> The Tcpdump Group git mirrors - tcpdump/commitdiff
More EXTRACT_8BITS(), more ND_TCHECK_nBITS(), other cleanups.
authorGuy Harris <[email protected]>
Wed, 22 Nov 2017 18:54:31 +0000 (10:54 -0800)
committerGuy Harris <[email protected]>
Wed, 22 Nov 2017 18:54:31 +0000 (10:54 -0800)
print-dvmrp.c
print-igmp.c

index eec5056a331358292116842de0366fce10ad2925..89f7f9bbb72e86b5110ce04a0736dc238355423c 100644 (file)
@@ -32,6 +32,8 @@
 #include "addrtoname.h"
 
 /*
+ * See: RFC 1075 and draft-ietf-idmr-dvmrp-v3
+ *
  * DVMRP message types and flag values shamelessly stolen from
  * mrouted/dvmrp.h.
  */
@@ -58,7 +60,7 @@
 static int print_probe(netdissect_options *, const u_char *, const u_char *, u_int);
 static int print_report(netdissect_options *, const u_char *, const u_char *, u_int);
 static int print_neighbors(netdissect_options *, const u_char *, const u_char *, u_int);
-static int print_neighbors2(netdissect_options *, const u_char *, const u_char *, u_int, uint32_t);
+static int print_neighbors2(netdissect_options *, const u_char *, const u_char *, u_int, uint8_t, uint8_t);
 static int print_prune(netdissect_options *, const u_char *);
 static int print_graft(netdissect_options *, const u_char *);
 static int print_graft_ack(netdissect_options *, const u_char *);
@@ -69,14 +71,14 @@ dvmrp_print(netdissect_options *ndo,
 {
        register const u_char *ep;
        register u_char type;
-       uint32_t target_level;
+       uint8_t major_version, minor_version;
 
        ep = (const u_char *)ndo->ndo_snapend;
        if (bp >= ep)
                return;
 
-       ND_TCHECK(bp[1]);
-       type = bp[1];
+       ND_TCHECK_8BITS(bp + 1);
+       type = EXTRACT_8BITS(bp + 1);
 
        /* Skip IGMP header */
        bp += 8;
@@ -117,15 +119,15 @@ dvmrp_print(netdissect_options *ndo,
        case DVMRP_NEIGHBORS2:
                ND_PRINT((ndo, " Neighbors2"));
                /*
-                * extract version and capabilities from IGMP group
-                * address field
+                * extract version from IGMP group address field
                 */
                bp -= 4;
                ND_TCHECK2(bp[0], 4);
-               target_level = (bp[0] << 24) | (bp[1] << 16) |
-                   (bp[2] << 8) | bp[3];
+               major_version = EXTRACT_8BITS(bp + 3);
+               minor_version = EXTRACT_8BITS(bp + 2);
                bp += 4;
-               if (print_neighbors2(ndo, bp, ep, len, target_level) < 0)
+               if (print_neighbors2(ndo, bp, ep, len, major_version,
+                   minor_version) < 0)
                        goto trunc;
                break;
 
@@ -287,15 +289,14 @@ trunc:
 static int
 print_neighbors2(netdissect_options *ndo,
                  register const u_char *bp, register const u_char *ep,
-                 register u_int len, uint32_t target_level)
+                 register u_int len, uint8_t major_version,
+                 uint8_t minor_version)
 {
        const u_char *laddr;
        register u_char metric, thresh, flags;
        register int ncount;
 
-       ND_PRINT((ndo, " (v %u.%u):",
-              target_level & 0xff,
-              (target_level >> 8) & 0xff));
+       ND_PRINT((ndo, " (v %u.%u):", major_version, minor_version));
 
        while (len > 0 && bp < ep) {
                ND_TCHECK2(bp[0], 8);
index 635c1c53e163ae391cd973cda75acf35add1a043..511b17c3306e01c6a02c80e8839ca986712e1eaf 100644 (file)
@@ -158,7 +158,7 @@ print_igmpv3_report(netdissect_options *ndo,
        ND_PRINT((ndo, " [invalid len %d]", len));
        return;
     }
-    ND_TCHECK2(bp[6], 2);
+    ND_TCHECK_16BITS(bp + 6);
     ngroups = EXTRACT_BE_16BITS(bp + 6);
     ND_PRINT((ndo, ", %d group record(s)", ngroups));
     if (ndo->ndo_vflag > 0) {
@@ -215,8 +215,8 @@ print_igmpv3_query(netdissect_options *ndo,
        ND_PRINT((ndo, " [invalid len %d]", len));
        return;
     }
-    ND_TCHECK(bp[1]);
-    mrc = bp[1];
+    ND_TCHECK_8BITS(bp + 1);
+    mrc = EXTRACT_8BITS(bp + 1);
     if (mrc < 128) {
        mrt = mrc;
     } else {
@@ -231,11 +231,11 @@ print_igmpv3_query(netdissect_options *ndo,
         }
        ND_PRINT((ndo, "]"));
     }
-    ND_TCHECK2(bp[4], 4);
+    ND_TCHECK_32BITS(bp + 4);
     if (EXTRACT_BE_32BITS(bp + 4) == 0)
        return;
     ND_PRINT((ndo, " [gaddr %s", ipaddr_string(ndo, &bp[4])));
-    ND_TCHECK2(bp[10], 2);
+    ND_TCHECK_16BITS(bp + 10);
     nsrcs = EXTRACT_BE_16BITS(bp + 10);
     if (nsrcs > 0) {
        if (len < 12 + (nsrcs << 2))
@@ -267,21 +267,21 @@ igmp_print(netdissect_options *ndo,
         return;
     }
 
-    ND_TCHECK(bp[0]);
-    switch (bp[0]) {
+    ND_TCHECK_8BITS(bp);
+    switch (EXTRACT_8BITS(bp)) {
     case 0x11:
         ND_PRINT((ndo, "igmp query"));
        if (len >= 12)
            print_igmpv3_query(ndo, bp, len);
        else {
-            ND_TCHECK(bp[1]);
-           if (bp[1]) {
+            ND_TCHECK_8BITS(bp + 1);
+           if (EXTRACT_8BITS(bp + 1)) {
                ND_PRINT((ndo, " v2"));
-               if (bp[1] != 100)
-                   ND_PRINT((ndo, " [max resp time %d]", bp[1]));
+               if (EXTRACT_8BITS(bp + 1) != 100)
+                   ND_PRINT((ndo, " [max resp time %u]", EXTRACT_8BITS(bp + 1)));
            } else
                ND_PRINT((ndo, " v1"));
-            ND_TCHECK2(bp[4], 4);
+            ND_TCHECK_32BITS(bp + 4);
            if (EXTRACT_BE_32BITS(bp + 4))
                 ND_PRINT((ndo, " [gaddr %s]", ipaddr_string(ndo, &bp[4])));
             if (len != 8)
@@ -324,7 +324,7 @@ igmp_print(netdissect_options *ndo,
         print_mtrace(ndo, bp, len);
         break;
     default:
-        ND_PRINT((ndo, "igmp-%d", bp[0]));
+        ND_PRINT((ndo, "igmp-%d", EXTRACT_8BITS(bp)));
         break;
     }