]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use more the EXTRACT_U_1() macro (53/n)
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 9 Dec 2017 16:15:55 +0000 (17:15 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 10 Dec 2017 10:40:35 +0000 (11:40 +0100)
Assignment, p[n], (more)

15 files changed:
print-babel.c
print-bgp.c
print-carp.c
print-dvmrp.c
print-geonet.c
print-hncp.c
print-icmp6.c
print-ip.c
print-ip6opts.c
print-juniper.c
print-mobility.c
print-pppoe.c
print-smb.c
print-vrrp.c
smbutil.c

index 5c5ab308170a2d117a669fa2635176ed873fa01e..10408e9f8676a5d0e2052d109d50d6377bf6ce4c 100644 (file)
@@ -501,12 +501,12 @@ babel_print_v2(netdissect_options *ndo,
                 u_char prefix[16];
                 ND_PRINT((ndo, "\n\tUpdate"));
                 if(len < 10) goto invalid;
-                plen = message[4] + (message[2] == 1 ? 96 : 0);
+                plen = EXTRACT_U_1(message + 4) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0);
                 rc = network_prefix(EXTRACT_U_1(message + 2),
                                     EXTRACT_U_1(message + 4),
                                     EXTRACT_U_1(message + 5),
                                     message + 12,
-                                    message[2] == 1 ? v4_prefix : v6_prefix,
+                                    EXTRACT_U_1(message + 2) == 1 ? v4_prefix : v6_prefix,
                                     len - 10, prefix);
                 if(rc < 0) goto invalid;
                 interval = EXTRACT_BE_U_2(message + 6);
@@ -539,7 +539,7 @@ babel_print_v2(netdissect_options *ndo,
                 u_char prefix[16], plen;
                 ND_PRINT((ndo, "\n\tRequest "));
                 if(len < 2) goto invalid;
-                plen = message[3] + (message[2] == 1 ? 96 : 0);
+                plen = EXTRACT_U_1(message + 3) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0);
                 rc = network_prefix(EXTRACT_U_1(message + 2),
                                     EXTRACT_U_1(message + 3), 0,
                                     message + 4, NULL, len - 2, prefix);
@@ -564,7 +564,7 @@ babel_print_v2(netdissect_options *ndo,
                                     EXTRACT_U_1(message + 3), 0,
                                     message + 16, NULL, len - 14, prefix);
                 if(rc < 0) goto invalid;
-                plen = message[3] + (message[2] == 1 ? 96 : 0);
+                plen = EXTRACT_U_1(message + 3) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0);
                 ND_PRINT((ndo, "(%u hops) for %s seqno %u id %s",
                        EXTRACT_U_1(message + 6), format_prefix(ndo, prefix, plen),
                        seqno, format_id(message + 8)));
index 5c5d880f8f9b13f1da7ffa103da00cdc8a7aa207..0ff3da054bc7ec01991b4b58d2c0c8dfebb8f868 100644 (file)
@@ -1351,7 +1351,7 @@ bgp_attr_get_as_size(netdissect_options *ndo,
             goto trunc;
         }
         ND_TCHECK_1(tptr + 1);
-        tptr += 2 + tptr[1] * 2;
+        tptr += 2 + EXTRACT_U_1(tptr + 1) * 2;
     }
 
     /*
@@ -1446,7 +1446,7 @@ bgp_attr_print(netdissect_options *ndo,
                         ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_close_values,
                                                "?", EXTRACT_U_1(tptr))));
                         ND_TCHECK_1(tptr + 1);
-                        tptr += 2 + tptr[1] * as_size;
+                        tptr += 2 + EXTRACT_U_1(tptr + 1) * as_size;
                }
                break;
        case BGPTYPE_NEXT_HOP:
@@ -1747,7 +1747,7 @@ bgp_attr_print(netdissect_options *ndo,
                        for (/*nothing*/; snpa > 0; snpa--) {
                                ND_TCHECK_1(tptr);
                                ND_PRINT((ndo, "\n\t      %d bytes", EXTRACT_U_1(tptr)));
-                               tptr += tptr[0] + 1;
+                               tptr += EXTRACT_U_1(tptr) + 1;
                        }
                } else {
                        ND_PRINT((ndo, ", no SNPA"));
index 622d308e9fb03eeb6a5e4f6fb4214f62ed9b41a4..b439a2d7a6fb4e92a45a59410162a946e5009354 100644 (file)
@@ -52,8 +52,8 @@ carp_print(netdissect_options *ndo, register const u_char *bp, register u_int le
        const char *type_s;
 
        ND_TCHECK_1(bp);
-       version = (bp[0] & 0xf0) >> 4;
-       type = bp[0] & 0x0f;
+       version = (EXTRACT_U_1(bp) & 0xf0) >> 4;
+       type = EXTRACT_U_1(bp) & 0x0f;
        if (type == 1)
                type_s = "advertise";
        else
index c954e001fee22a768a5f446f175d986dc165488a..5f56043bf1f7e639f618e1b9b8a36353b1b70fe1 100644 (file)
@@ -175,7 +175,8 @@ print_report(netdissect_options *ndo,
                        return (0);
                }
                ND_TCHECK_3(bp);
-               mask = (uint32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2];
+               mask = (uint32_t)0xff << 24 | EXTRACT_U_1(bp) << 16 |
+                       EXTRACT_U_1(bp + 1) << 8 | EXTRACT_U_1(bp + 2);
                width = 1;
                if (EXTRACT_U_1(bp))
                        width = 2;
@@ -233,7 +234,8 @@ print_probe(netdissect_options *ndo,
                ND_PRINT((ndo, " [|}"));
                return (0);
        }
-       genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3];
+       genid = (EXTRACT_U_1(bp) << 24) | (EXTRACT_U_1(bp + 1) << 16) |
+                (EXTRACT_U_1(bp + 2) << 8) | EXTRACT_U_1(bp + 3);
        bp += 4;
        len -= 4;
        ND_PRINT((ndo, ndo->ndo_vflag > 1 ? "\n\t" : " "));
index b59071910d14d167d3f072a3f0c2587fa06f7519..e96b0c491e3fc120f725617cc26adad413026799 100644 (file)
@@ -128,10 +128,10 @@ geonet_print(netdissect_options *ndo, const u_char *bp, u_int length,
                goto invalid;
 
        ND_TCHECK_8(bp);
-       version = bp[0] >> 4;
-       next_hdr = bp[0] & 0x0f;
-       hdr_type = bp[1] >> 4;
-       hdr_subtype = bp[1] & 0x0f;
+       version = EXTRACT_U_1(bp) >> 4;
+       next_hdr = EXTRACT_U_1(bp) & 0x0f;
+       hdr_type = EXTRACT_U_1(bp + 1) >> 4;
+       hdr_subtype = EXTRACT_U_1(bp + 1) & 0x0f;
        payload_length = EXTRACT_BE_U_2(bp + 4);
        hop_limit = EXTRACT_U_1(bp + 7);
 
index a1341923951411bc9850c668a8a6313d91d2ca93..09acbcf4715c5c5eb1c61546f1e024b669923ce4 100644 (file)
@@ -212,7 +212,7 @@ print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length)
         struct in_addr addr;
         u_int plen;
 
-        plen = prefix[0]-96;
+        plen = EXTRACT_U_1(prefix) - 96;
         if (32 < plen)
             return -1;
         max_length -= 1;
@@ -730,7 +730,7 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            prty = value[4] & 0xf;
+            prty = EXTRACT_U_1(value + 4) & 0xf;
             ND_PRINT((ndo, " EPID: %08x Prty: %u",
                 EXTRACT_BE_U_4(value),
                 prty
index 6a3799b94f0205b9a07291e9372628ad367b141d..7e607543933b683878acf4107ac223d97135c823 100644 (file)
@@ -1433,7 +1433,8 @@ mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len)
             ND_PRINT((ndo," [gaddr %s", ip6addr_string(ndo, bp + group + 4)));
            ND_PRINT((ndo," %s", tok2str(mldv2report2str, " [v2-report-#%d]",
                                          EXTRACT_U_1(bp + group))));
-            nsrcs = (bp[group + 2] << 8) + bp[group + 3];
+            nsrcs = (EXTRACT_U_1(bp + group + 2) << 8) +
+                    EXTRACT_U_1(bp + group + 3);
            /* Check the number of sources and print them */
            if (len < group + 20 + (nsrcs * sizeof(struct in6_addr))) {
                     ND_PRINT((ndo," [invalid number of sources %d]", nsrcs));
@@ -1500,7 +1501,8 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
        if (EXTRACT_U_1(bp + 25) < 128) {
                qqi = EXTRACT_U_1(bp + 25);
        } else {
-               qqi = ((bp[25] & 0x0f) | 0x10) << (((bp[25] & 0x70) >> 4) + 3);
+               qqi = ((EXTRACT_U_1(bp + 25) & 0x0f) | 0x10) <<
+                      (((EXTRACT_U_1(bp + 25) & 0x70) >> 4) + 3);
        }
        ND_PRINT((ndo," qqi=%d", qqi));
     }
index 036c57cda73f87a54ff83446d962ab8fb5f58487..b9d39cf511dde65db4230b6596419e9091e9fe46 100644 (file)
@@ -68,7 +68,7 @@ ip_printroute(netdissect_options *ndo,
        if ((length + 1) & 3)
                ND_PRINT((ndo, " [bad length %u]", length));
        ND_TCHECK_1(cp + 2);
-       ptr = cp[2] - 1;
+       ptr = EXTRACT_U_1(cp + 2) - 1;
        if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1)
                ND_PRINT((ndo, " [bad ptr %u]", EXTRACT_U_1(cp + 2)));
 
@@ -182,11 +182,12 @@ ip_printts(netdissect_options *ndo,
                return (0);
        }
        ND_PRINT((ndo, " TS{"));
-       hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4;
+       ND_TCHECK_1(cp + 3);
+       hoplen = ((EXTRACT_U_1(cp + 3) & 0xF) != IPOPT_TS_TSONLY) ? 8 : 4;
        if ((length - 4) & (hoplen-1))
                ND_PRINT((ndo, "[bad length %u]", length));
        ND_TCHECK_1(cp + 2);
-       ptr = cp[2] - 1;
+       ptr = EXTRACT_U_1(cp + 2) - 1;
        len = 0;
        if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1)
                ND_PRINT((ndo, "[bad ptr %u]", EXTRACT_U_1(cp + 2)));
index 7ed8c0133297e5dba3b675f0df4efb03d16546f6..5cf8ba4a235ddd098f29c56fa9bde01fbe7cc139 100644 (file)
@@ -52,7 +52,7 @@ ip6_sopt_print(netdissect_options *ndo, const u_char *bp, int len)
            optlen = 1;
        else {
            if (i + 1 < len)
-               optlen = bp[i + 1] + 2;
+               optlen = EXTRACT_U_1(bp + i + 1) + 2;
            else
                goto trunc;
        }
@@ -98,7 +98,7 @@ ip6_opt_print(netdissect_options *ndo, const u_char *bp, int len)
            optlen = 1;
        else {
            if (i + 1 < len)
-               optlen = bp[i + 1] + 2;
+               optlen = EXTRACT_U_1(bp + i + 1) + 2;
            else
                goto trunc;
        }
index 85c38b6c9ac24c11df88de99523defc677c4bc49..b8b3ec04e9e75a7548750396636a9dd3af43b292 100644 (file)
@@ -1196,7 +1196,7 @@ juniper_parse_header(netdissect_options *ndo,
     l2info->caplen = h->caplen;
     ND_TCHECK_4(p);
     l2info->flags = EXTRACT_U_1(p + 3);
-    l2info->direction = p[3]&JUNIPER_BPF_PKT_IN;
+    l2info->direction = EXTRACT_U_1(p + 3) & JUNIPER_BPF_PKT_IN;
 
     if (EXTRACT_BE_U_3(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */
         ND_PRINT((ndo, "no magic-number found!"));
index 61768a9ed696f8198f1fe31788742f4e91075e5e..6ad7c718924d4f3b35092b1ab4aea18ceb3217be 100644 (file)
@@ -124,7 +124,7 @@ mobility_opt_print(netdissect_options *ndo,
                else {
                        if (i + 1 < len) {
                                ND_TCHECK_1(bp + i + 1);
-                               optlen = bp[i + 1] + 2;
+                               optlen = EXTRACT_U_1(bp + i + 1) + 2;
                        }
                        else
                                goto trunc;
index 9c4fdfa7b7344ed1dae78f39e12568cf361aa3f5..18baba9cb4da26ca80b7f38282171ec35c16d601 100644 (file)
@@ -104,8 +104,8 @@ pppoe_print(netdissect_options *ndo, register const u_char *bp, u_int length)
        length -= PPPOE_HDRLEN;
        pppoe_packet = bp;
        ND_TCHECK2(*pppoe_packet, PPPOE_HDRLEN);
-       pppoe_ver  = (pppoe_packet[0] & 0xF0) >> 4;
-       pppoe_type  = (pppoe_packet[0] & 0x0F);
+       pppoe_ver  = (EXTRACT_U_1(pppoe_packet) & 0xF0) >> 4;
+       pppoe_type  = (EXTRACT_U_1(pppoe_packet) & 0x0F);
        pppoe_code = EXTRACT_U_1(pppoe_packet + 1);
        pppoe_sessionid = EXTRACT_BE_U_2(pppoe_packet + 2);
        pppoe_length    = EXTRACT_BE_U_2(pppoe_packet + 4);
index 1e81fcc8d014dec057aa2e3a7196ea4d05f4e1cc..3ef9225305caa8f9790e017ca705a06b1e83e2b2 100644 (file)
@@ -808,7 +808,7 @@ print_smb(netdissect_options *ndo,
     int smboffset;
 
     ND_TCHECK_1(buf + 9);
-    request = (buf[9] & 0x80) ? 0 : 1;
+    request = (EXTRACT_U_1(buf + 9) & 0x80) ? 0 : 1;
     startbuf = buf;
 
     command = EXTRACT_U_1(buf + 4);
@@ -1112,10 +1112,10 @@ nbt_udp137_print(netdissect_options *ndo,
 
     ND_TCHECK_2(data + 10);
     name_trn_id = EXTRACT_BE_U_2(data);
-    response = (data[2] >> 7);
-    opcode = (data[2] >> 3) & 0xF;
-    nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4);
-    rcode = data[3] & 0xF;
+    response = (EXTRACT_U_1(data + 2) >> 7);
+    opcode = (EXTRACT_U_1(data + 2) >> 3) & 0xF;
+    nm_flags = ((EXTRACT_U_1(data + 2) & 0x7) << 4) + (EXTRACT_U_1(data + 3) >> 4);
+    rcode = EXTRACT_U_1(data + 3) & 0xF;
     qdcount = EXTRACT_BE_U_2(data + 4);
     ancount = EXTRACT_BE_U_2(data + 6);
     nscount = EXTRACT_BE_U_2(data + 8);
index 79e0a586fae0a6e5e1b0b1bd9c7e100189188c17..20da88e6c013f6d6869c2ff223a376b347cc3e1f 100644 (file)
@@ -111,8 +111,8 @@ vrrp_print(netdissect_options *ndo,
        const char *type_s;
 
        ND_TCHECK_1(bp);
-       version = (bp[0] & 0xf0) >> 4;
-       type = bp[0] & 0x0f;
+       version = (EXTRACT_U_1(bp) & 0xf0) >> 4;
+       type = EXTRACT_U_1(bp) & 0x0f;
        type_s = tok2str(type2str, "unknown type (%u)", type);
        ND_PRINT((ndo, "VRRPv%u, %s", version, type_s));
        if (ttl != 255)
@@ -128,7 +128,7 @@ vrrp_print(netdissect_options *ndo,
                ND_PRINT((ndo, ", authtype %s", tok2str(auth2str, NULL, auth_type)));
                ND_PRINT((ndo, ", intvl %us, length %u", EXTRACT_U_1(bp + 5), len));
        } else { /* version == 3 */
-               uint16_t intvl = (bp[4] & 0x0f) << 8 | bp[5];
+               uint16_t intvl = (EXTRACT_U_1(bp + 4) & 0x0f) << 8 | EXTRACT_U_1(bp + 5);
                ND_PRINT((ndo, ", intvl %ucs, length %u", intvl, len));
        }
 
index 8f081b7240a9d5ac325af7e6c8a339656dffc851..5a292a3600432f144330ae87978fb484c5a285e7 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -103,7 +103,7 @@ interpret_long_date(const u_char *p)
     time_t ret;
 
     /* this gives us seconds since jan 1st 1601 (approx) */
-    d = (EXTRACT_LE_U_4(p + 4) * 256.0 + p[3]) * (1.0e-7 * (1 << 24));
+    d = (EXTRACT_LE_U_4(p + 4) * 256.0 + EXTRACT_U_1(p + 3)) * (1.0e-7 * (1 << 24));
 
     /* now adjust by 369 years to make the secs since 1970 */
     d -= 369.0 * 365.25 * 24 * 60 * 60;
@@ -150,7 +150,7 @@ name_interpret(netdissect_options *ndo,
            *out = 0;
            return(0);
        }
-       *out = ((in[0] - 'A') << 4) + (in[1] - 'A');
+       *out = ((EXTRACT_U_1(in) - 'A') << 4) + (EXTRACT_U_1(in + 1) - 'A');
        in += 2;
        out++;
     }