From: Francois-Xavier Le Bail Date: Sat, 9 Dec 2017 10:40:36 +0000 (+0100) Subject: Use more the EXTRACT_U_1() macro (51/n) X-Git-Tag: tcpdump-4.99-bp~1659 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/1cfd6cd2ac8acecbcf16e083a6cd272a19ec994e Use more the EXTRACT_U_1() macro (51/n) Moreover: Use more the ND_ISPRINT() macro. --- diff --git a/print-cdp.c b/print-cdp.c index 908f55f4..0c594843 100644 --- a/print-cdp.c +++ b/print-cdp.c @@ -304,7 +304,8 @@ cdp_print_addr(netdissect_options *ndo, goto trunc; al = EXTRACT_BE_U_2(p + pl); /* address length */ - if (pt == PT_NLPID && pl == 1 && *p == NLPID_IP && al == 4) { + if (pt == PT_NLPID && pl == 1 && EXTRACT_U_1(p) == NLPID_IP && + al == 4) { /* * IPv4: protocol type = NLPID, protocol length = 1 * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4), diff --git a/print-chdlc.c b/print-chdlc.c index 47a7b165..d65e7437 100644 --- a/print-chdlc.c +++ b/print-chdlc.c @@ -95,9 +95,9 @@ chdlc_print(netdissect_options *ndo, register const u_char *p, u_int length) if (length < 2) goto trunc; ND_TCHECK_2(p); - if (*(p+1) == NLPID_CLNP || - *(p+1) == NLPID_ESIS || - *(p+1) == NLPID_ISIS) + if (EXTRACT_U_1(p + 1) == NLPID_CLNP || + EXTRACT_U_1(p + 1) == NLPID_ESIS || + EXTRACT_U_1(p + 1) == NLPID_ISIS) isoclns_print(ndo, p + 1, length - 1); else isoclns_print(ndo, p, length); diff --git a/print-dccp.c b/print-dccp.c index 59edea5a..b4d1e8e5 100644 --- a/print-dccp.c +++ b/print-dccp.c @@ -537,11 +537,11 @@ static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_in ND_TCHECK_1(option); - if (*option >= 32) { + if (EXTRACT_U_1(option) >= 32) { ND_TCHECK_1(option + 1); optlen = EXTRACT_U_1(option + 1); if (optlen < 2) { - if (*option >= 128) + if (EXTRACT_U_1(option) >= 128) ND_PRINT((ndo, "CCID option %u optlen too short", EXTRACT_U_1(option))); else ND_PRINT((ndo, "%s optlen too short", @@ -552,7 +552,7 @@ static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_in optlen = 1; if (hlen < optlen) { - if (*option >= 128) + if (EXTRACT_U_1(option) >= 128) ND_PRINT((ndo, "CCID option %u optlen goes past header length", EXTRACT_U_1(option))); else @@ -562,7 +562,7 @@ static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_in } ND_TCHECK2(*option, optlen); - if (*option >= 128) { + if (EXTRACT_U_1(option) >= 128) { ND_PRINT((ndo, "CCID option %d", EXTRACT_U_1(option))); switch (optlen) { case 4: @@ -585,7 +585,7 @@ static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_in ND_PRINT((ndo, " optlen too short")); return optlen; } - if (*(option + 2) < 10){ + if (EXTRACT_U_1(option + 2) < 10){ ND_PRINT((ndo, " %s", dccp_feature_nums[EXTRACT_U_1(option + 2)])); for (i = 0; i < optlen - 3; i++) ND_PRINT((ndo, " %d", EXTRACT_U_1(option + 3 + i))); diff --git a/print-fr.c b/print-fr.c index c8415e12..8c8bf781 100644 --- a/print-fr.c +++ b/print-fr.c @@ -499,7 +499,7 @@ mfr_print(netdissect_options *ndo, case MFR_CTRL_IE_BUNDLE_ID: /* same message format */ case MFR_CTRL_IE_LINK_ID: for (idx = 0; idx < ie_len && idx < MFR_ID_STRING_MAXLEN; idx++) { - if (*(tptr+idx) != 0) /* don't print null termination */ + if (EXTRACT_U_1(tptr + idx) != 0) /* don't print null termination */ safeputchar(ndo, EXTRACT_U_1(tptr + idx)); else break; diff --git a/print-icmp6.c b/print-icmp6.c index dabec424..2b03d6db 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -1553,7 +1553,7 @@ dnsname_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) if (cp == ep) { /* FQDN */ ND_PRINT((ndo,".")); - } else if (cp + 1 == ep && *cp == '\0') { + } else if (cp + 1 == ep && EXTRACT_U_1(cp) == '\0') { /* truncated */ } else { /* invalid */ diff --git a/print-msdp.c b/print-msdp.c index 7eb6b105..f1769de0 100644 --- a/print-msdp.c +++ b/print-msdp.c @@ -65,8 +65,9 @@ msdp_print(netdissect_options *ndo, const u_char *sp, u_int length) ND_PRINT((ndo, " [w/data]")); if (ndo->ndo_vflag > 1) { ND_PRINT((ndo, " ")); - ip_print(ndo, sp + *sp * 12 + 8 - 3, - len - (*sp * 12 + 8)); + ip_print(ndo, sp + + EXTRACT_U_1(sp) * 12 + 8 - 3, + len - (EXTRACT_U_1(sp) * 12 + 8)); } } break; diff --git a/print-pim.c b/print-pim.c index ee04fbd3..b6048c77 100644 --- a/print-pim.c +++ b/print-pim.c @@ -825,7 +825,7 @@ pimv2_print(netdissect_options *ndo, ND_PRINT((ndo, "ERROR: Option Length != 4 Bytes (%u)", olen)); } else { ND_PRINT((ndo, "v%d", EXTRACT_U_1(bp))); - if (*(bp+1) != 0) { + if (EXTRACT_U_1(bp + 1) != 0) { ND_PRINT((ndo, ", interval ")); unsigned_relts_print(ndo, EXTRACT_U_1(bp + 1)); diff --git a/print-pppoe.c b/print-pppoe.c index f1fedc75..652f82ef 100644 --- a/print-pppoe.c +++ b/print-pppoe.c @@ -156,7 +156,7 @@ pppoe_print(netdissect_options *ndo, register const u_char *bp, u_int length) /* TODO print UTF-8 decoded text */ ND_TCHECK2(*p, tag_len); for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++) - if (*v >= 32 && *v < 127) { + if (ND_ISPRINT(EXTRACT_U_1(v))) { tag_str[tag_str_len++] = EXTRACT_U_1(v); ascii_count++; } else { diff --git a/print-radius.c b/print-radius.c index 1862b0a9..fda7710c 100644 --- a/print-radius.c +++ b/print-radius.c @@ -593,7 +593,7 @@ print_attr_string(netdissect_options *ndo, case TUNNEL_PASS: if (length < 3) goto trunc; - if (*data && (*data <=0x1F) ) + if (EXTRACT_U_1(data) && (EXTRACT_U_1(data) <= 0x1F)) ND_PRINT((ndo, "Tag[%u] ", EXTRACT_U_1(data))); else ND_PRINT((ndo, "Tag[Unused] ")); @@ -613,7 +613,7 @@ print_attr_string(netdissect_options *ndo, { if (length < 1) goto trunc; - if (*data) + if (EXTRACT_U_1(data)) ND_PRINT((ndo, "Tag[%u] ", EXTRACT_U_1(data))); else ND_PRINT((ndo, "Tag[Unused] ")); @@ -731,7 +731,7 @@ print_attr_num(netdissect_options *ndo, if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) ) { - if (!*data) + if (!EXTRACT_U_1(data)) ND_PRINT((ndo, "Tag[Unused] ")); else ND_PRINT((ndo, "Tag[%d] ", EXTRACT_U_1(data))); @@ -795,7 +795,7 @@ print_attr_num(netdissect_options *ndo, break; case TUNNEL_PREFERENCE: - if (*data) + if (EXTRACT_U_1(data)) ND_PRINT((ndo, "Tag[%d] ", EXTRACT_U_1(data))); else ND_PRINT((ndo, "Tag[Unused] ")); @@ -1002,7 +1002,7 @@ print_attr_strange(netdissect_options *ndo, return; } ND_TCHECK_1(data); - if (*data) + if (EXTRACT_U_1(data)) ND_PRINT((ndo, "User can change password")); else ND_PRINT((ndo, "User cannot change password")); diff --git a/print-slow.c b/print-slow.c index f3dc330d..972af657 100644 --- a/print-slow.c +++ b/print-slow.c @@ -261,7 +261,7 @@ slow_print(netdissect_options *ndo, if (len < 2) goto tooshort; ND_TCHECK_1(pptr + 1); - if (*(pptr+1) != LACP_VERSION) { + if (EXTRACT_U_1(pptr + 1) != LACP_VERSION) { ND_PRINT((ndo, "LACP version %u packet not supported", EXTRACT_U_1(pptr + 1))); return; } @@ -272,7 +272,7 @@ slow_print(netdissect_options *ndo, if (len < 2) goto tooshort; ND_TCHECK_1(pptr + 1); - if (*(pptr+1) != MARKER_VERSION) { + if (EXTRACT_U_1(pptr + 1) != MARKER_VERSION) { ND_PRINT((ndo, "MARKER version %u packet not supported", EXTRACT_U_1(pptr + 1))); return; } diff --git a/print-snmp.c b/print-snmp.c index ec43a4dd..ee658960 100644 --- a/print-snmp.c +++ b/print-snmp.c @@ -444,8 +444,8 @@ asn1_parse(netdissect_options *ndo, class = form >> 1; /* bits 7&6 -> bits 1&0, range 0-3 */ form &= 0x1; /* bit 5 -> bit 0, range 0-1 */ #else - form = (u_char)(*p & ASN_FORM_BITS) >> ASN_FORM_SHIFT; - class = (u_char)(*p & ASN_CLASS_BITS) >> ASN_CLASS_SHIFT; + form = (u_char)(EXTRACT_U_1(p) & ASN_FORM_BITS) >> ASN_FORM_SHIFT; + class = (u_char)(EXTRACT_U_1(p) & ASN_CLASS_BITS) >> ASN_CLASS_SHIFT; #endif elem->form = form; elem->class = class; @@ -470,7 +470,7 @@ asn1_parse(netdissect_options *ndo, ND_PRINT((ndo, "[Xtagfield?]")); return -1; } - id = (id << 7) | (*p & ~ASN_BIT8); + id = (id << 7) | (EXTRACT_U_1(p) & ~ASN_BIT8); len--; hdr++; p++; @@ -771,7 +771,7 @@ asn1_print(netdissect_options *ndo, for (; i-- > 0; p++) { ND_TCHECK_1(p); - o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); + o = (o << ASN_SHIFT7) + (EXTRACT_U_1(p) & ~ASN_BIT8); if (EXTRACT_U_1(p) & ASN_LONGLEN) continue; @@ -923,7 +923,7 @@ smi_decode_oid(netdissect_options *ndo, for (*oidlen = 0; i-- > 0; p++) { ND_TCHECK_1(p); - o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); + o = (o << ASN_SHIFT7) + (EXTRACT_U_1(p) & ~ASN_BIT8); if (EXTRACT_U_1(p) & ASN_LONGLEN) continue; diff --git a/print-syslog.c b/print-syslog.c index 15720fa2..1610bd6d 100644 --- a/print-syslog.c +++ b/print-syslog.c @@ -91,17 +91,17 @@ syslog_print(netdissect_options *ndo, */ ND_TCHECK_1(pptr); - if (*(pptr+msg_off) == '<') { + if (EXTRACT_U_1(pptr + msg_off) == '<') { msg_off++; ND_TCHECK_1(pptr + msg_off); while (msg_off <= SYSLOG_MAX_DIGITS && EXTRACT_U_1(pptr + msg_off) >= '0' && EXTRACT_U_1(pptr + msg_off) <= '9') { - pri = pri * 10 + (*(pptr+msg_off) - '0'); + pri = pri * 10 + (EXTRACT_U_1(pptr + msg_off) - '0'); msg_off++; ND_TCHECK_1(pptr + msg_off); } - if (*(pptr+msg_off) != '>') { + if (EXTRACT_U_1(pptr + msg_off) != '>') { ND_PRINT((ndo, "%s", tstr)); return; }