]> The Tcpdump Group git mirrors - tcpdump/commitdiff
More EXTRACT_8BITS() and other cleanups.
authorGuy Harris <[email protected]>
Wed, 22 Nov 2017 18:15:49 +0000 (10:15 -0800)
committerGuy Harris <[email protected]>
Wed, 22 Nov 2017 18:15:49 +0000 (10:15 -0800)
Get rid of casts to (int) that aren't needed or wanted.

If a field is unsigned, use an unsigned variable for it, print it with
%u, not %d, and don't cast it to int.

Replace a static variable in print-dvmrp.c with a local variable in
dvmrp_print() and a parameter to print_neighbors2().

netdissect.h
print-dhcp6.c
print-dvmrp.c
print-esp.c
print-forces.c
print-ip.c
print-ip6.c
print-ip6opts.c
print-isakmp.c
print-rsvp.c

index b093e0e67396f1d600184d2d7ee02260d3139784..ec64cfe42ab51c6d5ab3dd66448d4aa3e3c4345d 100644 (file)
@@ -506,7 +506,7 @@ extern void dvmrp_print(netdissect_options *, const u_char *, u_int);
 extern void eap_print(netdissect_options *, const u_char *, u_int);
 extern void egp_print(netdissect_options *, const u_char *, u_int);
 extern void eigrp_print(netdissect_options *, const u_char *, u_int);
-extern int esp_print(netdissect_options *, const u_char *, const int, const u_char *, int *, int *);
+extern int esp_print(netdissect_options *, const u_char *, const int, const u_char *, u_int *, u_int *);
 extern u_int ether_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), const u_char *);
 extern int ethertype_print(netdissect_options *, u_short, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *);
 extern u_int fddi_print(netdissect_options *, const u_char *, u_int, u_int);
index 804494971bc82003591713f12eae779633b8169c..92ca980ca9133f2f75940cb10a173b26bb50c0b9 100644 (file)
@@ -665,7 +665,7 @@ dhcp6opt_print(netdissect_options *ndo,
                                ND_PRINT((ndo, " by-clientID"));
                                break;
                        default:
-                               ND_PRINT((ndo, " type_%d", (int)dh6_lq_query_type));
+                               ND_PRINT((ndo, " type_%u", dh6_lq_query_type));
                                break;
                        }
                        ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[1])));
index cab00a5537743abe9d3c4fab7de91fcddd5c7b66..eec5056a331358292116842de0366fce10ad2925 100644 (file)
 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);
+static int print_neighbors2(netdissect_options *, const u_char *, const u_char *, u_int, uint32_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 *);
 
-static uint32_t target_level;
-
 void
 dvmrp_print(netdissect_options *ndo,
             register const u_char *bp, register u_int len)
 {
        register const u_char *ep;
        register u_char type;
+       uint32_t target_level;
 
        ep = (const u_char *)ndo->ndo_snapend;
        if (bp >= ep)
@@ -126,7 +125,7 @@ dvmrp_print(netdissect_options *ndo,
                target_level = (bp[0] << 24) | (bp[1] << 16) |
                    (bp[2] << 8) | bp[3];
                bp += 4;
-               if (print_neighbors2(ndo, bp, ep, len) < 0)
+               if (print_neighbors2(ndo, bp, ep, len, target_level) < 0)
                        goto trunc;
                break;
 
@@ -288,15 +287,15 @@ trunc:
 static int
 print_neighbors2(netdissect_options *ndo,
                  register const u_char *bp, register const u_char *ep,
-                 register u_int len)
+                 register u_int len, uint32_t target_level)
 {
        const u_char *laddr;
        register u_char metric, thresh, flags;
        register int ncount;
 
-       ND_PRINT((ndo, " (v %d.%d):",
-              (int)target_level & 0xff,
-              (int)(target_level >> 8) & 0xff));
+       ND_PRINT((ndo, " (v %u.%u):",
+              target_level & 0xff,
+              (target_level >> 8) & 0xff));
 
        while (len > 0 && bp < ep) {
                ND_TCHECK2(bp[0], 8);
index 59d109d410e9e834086ef58df2c8545c32eb7670..d19b36da940196a9762818d98a86947e5a067755 100644 (file)
@@ -636,12 +636,12 @@ esp_print(netdissect_options *ndo,
        _U_
 #endif
        ,
-       int *nhdr
+       u_int *nhdr
 #ifndef HAVE_LIBCRYPTO
        _U_
 #endif
        ,
-       int *padlen
+       u_int *padlen
 #ifndef HAVE_LIBCRYPTO
        _U_
 #endif
@@ -807,14 +807,14 @@ esp_print(netdissect_options *ndo,
                advance = sizeof(struct newesp);
 
        /* sanity check for pad length */
-       if (ep - bp < *(ep - 2))
+       if (ep - bp < EXTRACT_8BITS(ep - 2))
                goto fail;
 
        if (padlen)
-               *padlen = *(ep - 2) + 2;
+               *padlen = EXTRACT_8BITS(ep - 2) + 2;
 
        if (nhdr)
-               *nhdr = *(ep - 1);
+               *nhdr = EXTRACT_8BITS(ep - 1);
 
        ND_PRINT((ndo, ": "));
        return advance;
index b74227e656edc7a6d85dc59ce2716a825f0cda56..bfc49e9fd1b3158847cdb8aee06f4b626d57816c 100644 (file)
@@ -387,14 +387,14 @@ struct forces_tlv {
 #define        GET_TOP_TLV(fhdr) ((const struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
 #define TLV_SET_LEN(len)  (F_ALN_LEN(TLV_HDRL) + (len))
 #define TLV_ALN_LEN(len)  F_ALN_LEN(TLV_SET_LEN(len))
-#define TLV_RDAT_LEN(tlv) ((int)(EXTRACT_16BITS(&(tlv)->length) - TLV_SET_LEN(0))
+#define TLV_RDAT_LEN(tlv) (EXTRACT_16BITS(&(tlv)->length) - TLV_SET_LEN(0)
 #define TLV_DATA(tlvp)   ((const void*)(((const char*)(tlvp)) + TLV_SET_LEN(0)))
 #define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_BE_16BITS(&(tlv)->length)), \
                              (const struct forces_tlv*)(((const char*)(tlv)) \
                                      + F_ALN_LEN(EXTRACT_BE_16BITS(&(tlv)->length))))
 #define ILV_SET_LEN(len)  (F_ALN_LEN(ILV_HDRL) + (len))
 #define ILV_ALN_LEN(len)  F_ALN_LEN(ILV_SET_LEN(len))
-#define ILV_RDAT_LEN(ilv) ((int)(EXTRACT_BE_32BITS(&(ilv)->length)) - ILV_SET_LEN(0))
+#define ILV_RDAT_LEN(ilv) (EXTRACT_BE_32BITS(&(ilv)->length)) - ILV_SET_LEN(0)
 #define ILV_DATA(ilvp)   ((const void*)(((const char*)(ilvp)) + ILV_SET_LEN(0)))
 #define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_BE_32BITS(&(ilv)->length)), \
                              (const struct forces_ilv *)(((const char*)(ilv)) \
index 519cd793d30464839c07f3d93dbf2be9a2c20153..8adf3fc283336c45c5364336c83a282022f96eaf 100644 (file)
@@ -359,7 +359,7 @@ again:
 
        case IPPROTO_ESP:
        {
-               int enh, padlen;
+               u_int enh, padlen;
                ipds->advance = esp_print(ndo, ipds->cp, ipds->len,
                                    (const u_char *)ipds->ip,
                                    &enh, &padlen);
@@ -598,7 +598,7 @@ ip_print(netdissect_options *ndo,
        ipds->off = EXTRACT_BE_16BITS(&ipds->ip->ip_off);
 
         if (ndo->ndo_vflag) {
-            ND_PRINT((ndo, "(tos 0x%x", (int)ipds->ip->ip_tos));
+            ND_PRINT((ndo, "(tos 0x%x", ipds->ip->ip_tos));
             /* ECN bits */
             switch (ipds->ip->ip_tos & 0x03) {
 
index 862dfb2c7f99e33c78027421f6af5bd88a1d18e9..fc296b81a9cfe5bd3830092b74628e69ab493244 100644 (file)
@@ -48,7 +48,7 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
             const struct ip6_hdr *ip6)
 {
        const u_char *cp;
-       int advance;
+       u_int advance;
        u_int nh;
        const void *dst_addr;
        const struct ip6_rthdr *dp;
@@ -77,7 +77,7 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
                         * the first 8 octets.
                         */
                        ND_TCHECK2(*cp, 2);
-                       advance = (int)((*(cp + 1) + 1) << 3);
+                       advance = (EXTRACT_8BITS(cp + 1) + 1) << 3;
                        nh = *cp;
                        break;
 
@@ -219,7 +219,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
        const u_char *ipend;
        register const u_char *cp;
        register u_int payload_len;
-       int nh;
+       u_int nh;
        int fragmented = 0;
        u_int flow;
 
@@ -297,19 +297,19 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                        advance = hbhopt_print(ndo, cp);
                        if (advance < 0)
                                return;
-                       nh = *cp;
+                       nh = EXTRACT_8BITS(cp);
                        break;
                case IPPROTO_DSTOPTS:
                        advance = dstopt_print(ndo, cp);
                        if (advance < 0)
                                return;
-                       nh = *cp;
+                       nh = EXTRACT_8BITS(cp);
                        break;
                case IPPROTO_FRAGMENT:
                        advance = frag6_print(ndo, cp, (const u_char *)ip6);
                        if (advance < 0 || ndo->ndo_snapend <= cp + advance)
                                return;
-                       nh = *cp;
+                       nh = EXTRACT_8BITS(cp);
                        fragmented = 1;
                        break;
 
@@ -326,14 +326,14 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                        advance = mobility_print(ndo, cp, (const u_char *)ip6);
                        if (advance < 0)
                                return;
-                       nh = *cp;
+                       nh = EXTRACT_8BITS(cp);
                        return;
                case IPPROTO_ROUTING:
                        ND_TCHECK(*cp);
                        advance = rt6_print(ndo, cp, (const u_char *)ip6);
                        if (advance < 0)
                                return;
-                       nh = *cp;
+                       nh = EXTRACT_8BITS(cp);
                        break;
                case IPPROTO_SCTP:
                        sctp_print(ndo, cp, (const u_char *)ip6, len);
@@ -354,11 +354,11 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                        advance = ah_print(ndo, cp);
                        if (advance < 0)
                                return;
-                       nh = *cp;
+                       nh = EXTRACT_8BITS(cp);
                        break;
                case IPPROTO_ESP:
                    {
-                       int enh, padlen;
+                       u_int enh, padlen;
                        advance = esp_print(ndo, cp, len, (const u_char *)ip6, &enh, &padlen);
                        if (advance < 0)
                                return;
index ff1d1246c424891b771d1a7066946504b99c6bb8..c4edd4b645de2281c9547eb28352ab54d3feb4ae 100644 (file)
@@ -174,10 +174,10 @@ int
 hbhopt_print(netdissect_options *ndo, register const u_char *bp)
 {
     const struct ip6_hbh *dp = (const struct ip6_hbh *)bp;
-    int hbhlen = 0;
+    u_int hbhlen = 0;
 
     ND_TCHECK(dp->ip6h_len);
-    hbhlen = (int)((dp->ip6h_len + 1) << 3);
+    hbhlen = (dp->ip6h_len + 1) << 3;
     ND_TCHECK2(*dp, hbhlen);
     ND_PRINT((ndo, "HBH "));
     if (ndo->ndo_vflag)
@@ -194,10 +194,10 @@ int
 dstopt_print(netdissect_options *ndo, register const u_char *bp)
 {
     const struct ip6_dest *dp = (const struct ip6_dest *)bp;
-    int dstoptlen = 0;
+    u_int dstoptlen = 0;
 
     ND_TCHECK(dp->ip6d_len);
-    dstoptlen = (int)((dp->ip6d_len + 1) << 3);
+    dstoptlen = (dp->ip6d_len + 1) << 3;
     ND_TCHECK2(*dp, dstoptlen);
     ND_PRINT((ndo, "DSTOPT "));
     if (ndo->ndo_vflag) {
index a3eb0bea69faa73c37dc84fc566edd7baed64091..52f7e558e90c3fb5f5d0fe0ba6e20705f902538a 100644 (file)
@@ -3115,7 +3115,7 @@ isakmp_rfc3948_print(netdissect_options *ndo,
 
        /* must be an ESP packet */
        {
-               int nh, enh, padlen;
+               u_int nh, enh, padlen;
                int advance;
 
                ND_PRINT((ndo, "UDP-encap: "));
index 5a652d4df6316d565ce35c83d0d7f2955870e548..ad518aad7e2db25b7390e1f41bbcf1a87a1dcbe1 100644 (file)
@@ -738,7 +738,7 @@ rsvp_obj_print(netdissect_options *ndo,
                 ND_PRINT((ndo, "%s  IPv4 DestAddress: %s, Protocol ID: 0x%02x",
                        indent,
                        ipaddr_string(ndo, obj_tptr),
-                       *(obj_tptr + sizeof(struct in_addr))));
+                       EXTRACT_8BITS(obj_tptr + sizeof(struct in_addr))));
                 ND_PRINT((ndo, "%s  Flags: [0x%02x], DestPort %u",
                        indent,
                        EXTRACT_8BITS((obj_tptr + 5)),
@@ -752,7 +752,7 @@ rsvp_obj_print(netdissect_options *ndo,
                 ND_PRINT((ndo, "%s  IPv6 DestAddress: %s, Protocol ID: 0x%02x",
                        indent,
                        ip6addr_string(ndo, obj_tptr),
-                       *(obj_tptr + sizeof(struct in6_addr))));
+                       EXTRACT_8BITS(obj_tptr + sizeof(struct in6_addr))));
                 ND_PRINT((ndo, "%s  Flags: [0x%02x], DestPort %u",
                        indent,
                        EXTRACT_8BITS((obj_tptr + sizeof(struct in6_addr) + 1)),
@@ -910,7 +910,7 @@ rsvp_obj_print(netdissect_options *ndo,
                        tok2str(rsvp_resstyle_values,
                                "Unknown",
                                EXTRACT_BE_24BITS(obj_tptr + 1)),
-                       *(obj_tptr)));
+                       EXTRACT_8BITS(obj_tptr)));
                 obj_tlen-=4;
                 obj_tptr+=4;
                 break;
@@ -1005,7 +1005,7 @@ rsvp_obj_print(netdissect_options *ndo,
                        tok2str(ethertype_values,
                                "Unknown Protocol (0x%04x)",
                                EXTRACT_BE_16BITS(obj_tptr + 2))));
-                ND_PRINT((ndo, ",%s merge capability",((*(obj_tptr + 4)) & 0x80) ? "no" : "" ));
+                ND_PRINT((ndo, ",%s merge capability",((EXTRACT_8BITS(obj_tptr + 4)) & 0x80) ? "no" : "" ));
                 ND_PRINT((ndo, "%s  Minimum VPI/VCI: %u/%u",
                        indent,
                        (EXTRACT_BE_16BITS(obj_tptr + 4))&0xfff,
@@ -1042,13 +1042,13 @@ rsvp_obj_print(netdissect_options *ndo,
                        tok2str(gmpls_encoding_values,
                                "Unknown",
                                EXTRACT_8BITS(obj_tptr)),
-                       *obj_tptr));
+                       EXTRACT_8BITS(obj_tptr)));
                 ND_PRINT((ndo, "%s  Switching Type: %s (%u), Payload ID: %s (0x%04x)",
                        indent,
                        tok2str(gmpls_switch_cap_values,
                                "Unknown",
                                EXTRACT_8BITS((obj_tptr + 1))),
-                       *(obj_tptr+1),
+                       EXTRACT_8BITS(obj_tptr+1),
                        tok2str(gmpls_payload_values,
                                "Unknown",
                                EXTRACT_BE_16BITS(obj_tptr + 2)),
@@ -1115,7 +1115,7 @@ rsvp_obj_print(netdissect_options *ndo,
                                bittok2str(rsvp_obj_rro_label_flag_values,
                                    "none",
                                    EXTRACT_8BITS((obj_tptr + 2))),
-                               *(obj_tptr+2),
+                               EXTRACT_8BITS(obj_tptr+2),
                                tok2str(rsvp_ctype_values,
                                        "Unknown",
                                        EXTRACT_8BITS((obj_tptr + 3)) + (256 * RSVP_OBJ_RRO)),
@@ -1176,15 +1176,15 @@ rsvp_obj_print(netdissect_options *ndo,
                     return-1;
                 ND_PRINT((ndo, "%s  Session Name: ", indent));
                 for (i = 0; i < namelen; i++)
-                    safeputchar(ndo, *(obj_tptr + 4 + i));
+                    safeputchar(ndo, EXTRACT_8BITS(obj_tptr + 4 + i));
                 ND_PRINT((ndo, "%s  Setup Priority: %u, Holding Priority: %u, Flags: [%s] (%#x)",
                        indent,
-                       (int)*obj_tptr,
-                       (int)*(obj_tptr+1),
+                       EXTRACT_8BITS(obj_tptr),
+                       EXTRACT_8BITS(obj_tptr+1),
                        bittok2str(rsvp_session_attribute_flag_values,
                                   "none",
                                   EXTRACT_8BITS((obj_tptr + 2))),
-                       *(obj_tptr + 2)));
+                       EXTRACT_8BITS(obj_tptr + 2)));
                 obj_tlen-=4+EXTRACT_8BITS((obj_tptr + 3));
                 obj_tptr+=4+EXTRACT_8BITS((obj_tptr + 3));
                 break;
@@ -1379,8 +1379,8 @@ rsvp_obj_print(netdissect_options *ndo,
                     ND_PRINT((ndo, "%s  Service Type: %s (%u), break bit %s set, Service length: %u",
                            indent,
                            tok2str(rsvp_intserv_service_type_values,"unknown",EXTRACT_8BITS((obj_tptr))),
-                           *(obj_tptr),
-                           (*(obj_tptr+1)&0x80) ? "" : "not",
+                           EXTRACT_8BITS(obj_tptr),
+                           (EXTRACT_8BITS(obj_tptr+1)&0x80) ? "" : "not",
                            intserv_serv_tlen));
 
                     obj_tptr+=4; /* get to the start of the parameter list */
@@ -1497,10 +1497,10 @@ rsvp_obj_print(netdissect_options *ndo,
                 bw.i = EXTRACT_BE_32BITS(obj_ptr.rsvp_obj_frr->bandwidth);
                 ND_PRINT((ndo, "%s  Setup Priority: %u, Holding Priority: %u, Hop-limit: %u, Bandwidth: %.10g Mbps",
                        indent,
-                       (int)obj_ptr.rsvp_obj_frr->setup_prio,
-                       (int)obj_ptr.rsvp_obj_frr->hold_prio,
-                       (int)obj_ptr.rsvp_obj_frr->hop_limit,
-                        bw.f * 8 / 1000000));
+                       obj_ptr.rsvp_obj_frr->setup_prio,
+                       obj_ptr.rsvp_obj_frr->hold_prio,
+                       obj_ptr.rsvp_obj_frr->hop_limit,
+                       bw.f * 8 / 1000000));
                 ND_PRINT((ndo, "%s  Include-any: 0x%08x, Exclude-any: 0x%08x, Include-all: 0x%08x",
                        indent,
                        EXTRACT_BE_32BITS(obj_ptr.rsvp_obj_frr->include_any),
@@ -1516,10 +1516,10 @@ rsvp_obj_print(netdissect_options *ndo,
                 bw.i = EXTRACT_BE_32BITS(obj_ptr.rsvp_obj_frr->bandwidth);
                 ND_PRINT((ndo, "%s  Setup Priority: %u, Holding Priority: %u, Hop-limit: %u, Bandwidth: %.10g Mbps",
                        indent,
-                       (int)obj_ptr.rsvp_obj_frr->setup_prio,
-                       (int)obj_ptr.rsvp_obj_frr->hold_prio,
-                       (int)obj_ptr.rsvp_obj_frr->hop_limit,
-                        bw.f * 8 / 1000000));
+                       obj_ptr.rsvp_obj_frr->setup_prio,
+                       obj_ptr.rsvp_obj_frr->hold_prio,
+                       obj_ptr.rsvp_obj_frr->hop_limit,
+                       bw.f * 8 / 1000000));
                 ND_PRINT((ndo, "%s  Include Colors: 0x%08x, Exclude Colors: 0x%08x",
                        indent,
                        EXTRACT_BE_32BITS(obj_ptr.rsvp_obj_frr->include_any),
@@ -1576,7 +1576,7 @@ rsvp_obj_print(netdissect_options *ndo,
                 ND_PRINT((ndo, "%s  Error Node Address: %s, Flags: [0x%02x]%s  Error Code: %s (%u)",
                        indent,
                        ipaddr_string(ndo, obj_tptr),
-                       *(obj_tptr+4),
+                       EXTRACT_8BITS(obj_tptr+4),
                        indent,
                        tok2str(rsvp_obj_error_code_values,"unknown",error_code),
                        error_code));
@@ -1608,7 +1608,7 @@ rsvp_obj_print(netdissect_options *ndo,
                 ND_PRINT((ndo, "%s  Error Node Address: %s, Flags: [0x%02x]%s  Error Code: %s (%u)",
                        indent,
                        ip6addr_string(ndo, obj_tptr),
-                       *(obj_tptr+16),
+                       EXTRACT_8BITS(obj_tptr+16),
                        indent,
                        tok2str(rsvp_obj_error_code_values,"unknown",error_code),
                        error_code));
@@ -1648,12 +1648,12 @@ rsvp_obj_print(netdissect_options *ndo,
                            indent,
                            tok2str(rsvp_obj_prop_tlv_values,"unknown",EXTRACT_8BITS(obj_tptr)),
                            EXTRACT_8BITS(obj_tptr),
-                           *(obj_tptr + 1)));
+                           EXTRACT_8BITS(obj_tptr + 1)));
                     if (obj_tlen < EXTRACT_8BITS((obj_tptr + 1)))
                         return-1;
-                    if (*(obj_tptr+1) < 2)
+                    if (EXTRACT_8BITS(obj_tptr+1) < 2)
                         return -1;
-                    print_unknown_data(ndo, obj_tptr + 2, "\n\t\t", *(obj_tptr + 1) - 2);
+                    print_unknown_data(ndo, obj_tptr + 2, "\n\t\t", EXTRACT_8BITS(obj_tptr + 1) - 2);
                     obj_tlen-=EXTRACT_8BITS(obj_tptr + 1);
                     obj_tptr+=EXTRACT_8BITS(obj_tptr + 1);
                 }