From: Francois-Xavier Le Bail Date: Sat, 9 Dec 2017 16:15:55 +0000 (+0100) Subject: Use more the EXTRACT_U_1() macro (53/n) X-Git-Tag: tcpdump-4.99-bp~1657 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/6bb65331a5f9d35186238af0ed736a3949616bc2 Use more the EXTRACT_U_1() macro (53/n) Assignment, p[n], (more) --- diff --git a/print-babel.c b/print-babel.c index 5c5ab308..10408e9f 100644 --- a/print-babel.c +++ b/print-babel.c @@ -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))); diff --git a/print-bgp.c b/print-bgp.c index 5c5d880f..0ff3da05 100644 --- a/print-bgp.c +++ b/print-bgp.c @@ -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")); diff --git a/print-carp.c b/print-carp.c index 622d308e..b439a2d7 100644 --- a/print-carp.c +++ b/print-carp.c @@ -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 diff --git a/print-dvmrp.c b/print-dvmrp.c index c954e001..5f56043b 100644 --- a/print-dvmrp.c +++ b/print-dvmrp.c @@ -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" : " ")); diff --git a/print-geonet.c b/print-geonet.c index b5907191..e96b0c49 100644 --- a/print-geonet.c +++ b/print-geonet.c @@ -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); diff --git a/print-hncp.c b/print-hncp.c index a1341923..09acbcf4 100644 --- a/print-hncp.c +++ b/print-hncp.c @@ -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 diff --git a/print-icmp6.c b/print-icmp6.c index 6a3799b9..7e607543 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -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)); } diff --git a/print-ip.c b/print-ip.c index 036c57cd..b9d39cf5 100644 --- a/print-ip.c +++ b/print-ip.c @@ -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))); diff --git a/print-ip6opts.c b/print-ip6opts.c index 7ed8c013..5cf8ba4a 100644 --- a/print-ip6opts.c +++ b/print-ip6opts.c @@ -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; } diff --git a/print-juniper.c b/print-juniper.c index 85c38b6c..b8b3ec04 100644 --- a/print-juniper.c +++ b/print-juniper.c @@ -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!")); diff --git a/print-mobility.c b/print-mobility.c index 61768a9e..6ad7c718 100644 --- a/print-mobility.c +++ b/print-mobility.c @@ -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; diff --git a/print-pppoe.c b/print-pppoe.c index 9c4fdfa7..18baba9c 100644 --- a/print-pppoe.c +++ b/print-pppoe.c @@ -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); diff --git a/print-smb.c b/print-smb.c index 1e81fcc8..3ef92253 100644 --- a/print-smb.c +++ b/print-smb.c @@ -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); diff --git a/print-vrrp.c b/print-vrrp.c index 79e0a586..20da88e6 100644 --- a/print-vrrp.c +++ b/print-vrrp.c @@ -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)); } diff --git a/smbutil.c b/smbutil.c index 8f081b72..5a292a36 100644 --- 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++; }