]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use #defines rather than sizeof.
authorGuy Harris <[email protected]>
Mon, 8 Feb 2010 00:05:46 +0000 (16:05 -0800)
committerGuy Harris <[email protected]>
Mon, 8 Feb 2010 00:05:46 +0000 (16:05 -0800)
Use ForCES_HDRL, TLV_HDRL, and ILV_HDRL instead of various sizeof's, to
make it clearer what certain tests ensure are true (as, in other cases,
the #defines are subtracted from values that should be, at that point,
ensured not to be less than the #define in question).

forces.h
print-forces.c

index 092a30b1501b09d777abc46d66d4323763d6846e..b9cf072fb6113827f5834d5eb53af71be009c82d 100644 (file)
--- a/forces.h
+++ b/forces.h
@@ -216,8 +216,8 @@ struct forcesh {
 #define ForCES_RS2(forcesh)    ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x0007FFFF) >> 0)
 };
 
-#define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= sizeof(struct forcesh) && \
-                                  (fhl) >= sizeof(struct forcesh) && \
+#define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= ForCES_HDRL && \
+                                  (fhl) >= ForCES_HDRL && \
                                   (fhl) == (tlen))
 
 #define F_LFB_RSVD 0x0
@@ -428,14 +428,14 @@ int otlv_print(const struct forces_tlv *otlv, u_int16_t op_msk, int indent);
 
 #define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) )
 #define        GET_TOP_TLV(fhdr) ((struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
-#define TLV_SET_LEN(len)  (F_ALN_LEN(sizeof(struct forces_tlv)) + (len))
+#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_DATA(tlvp)   ((void*)(((char*)(tlvp)) + TLV_SET_LEN(0)))
 #define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length)), \
                              (struct forces_tlv*)(((char*)(tlv)) \
                                      + F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length))))
-#define ILV_SET_LEN(len)  (F_ALN_LEN(sizeof(struct forces_ilv)) + (len))
+#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_32BITS(&(ilv)->length)) - ILV_SET_LEN(0))
 #define ILV_DATA(ilvp)   ((void*)(((char*)(ilvp)) + ILV_SET_LEN(0)))
@@ -457,9 +457,9 @@ static const struct tok ForCES_TLV_err[] = {
 
 static inline int tlv_valid(const struct forces_tlv *tlv, u_int rlen)
 {
-       if (rlen < (int) sizeof(struct forces_tlv))
+       if (rlen < TLV_HDRL)
                return INVALID_RLEN;
-       if (EXTRACT_16BITS(&tlv->length) < sizeof(struct forces_tlv))
+       if (EXTRACT_16BITS(&tlv->length) < TLV_HDRL)
                return INVALID_STLN;
        if (EXTRACT_16BITS(&tlv->length) > rlen)
                return INVALID_LTLN;
@@ -471,9 +471,9 @@ static inline int tlv_valid(const struct forces_tlv *tlv, u_int rlen)
 
 static inline int ilv_valid(const struct forces_ilv *ilv, u_int rlen)
 {
-       if (rlen < sizeof(struct forces_ilv))
+       if (rlen < ILV_HDRL)
                return INVALID_RLEN;
-       if (EXTRACT_32BITS(&ilv->length) < sizeof(struct forces_ilv))
+       if (EXTRACT_32BITS(&ilv->length) < ILV_HDRL)
                return INVALID_STLN;
        if (EXTRACT_32BITS(&ilv->length) > rlen)
                return INVALID_LTLN;
index 760d3b1b7a6aa13ef2a67e34be72fcb64a92b6d6..efe7b5f53ce507144ea47c2aece15927561989bc 100644 (file)
@@ -213,7 +213,6 @@ pdatacnt_print(register const u_char * pptr, register u_int len,
 
                TCHECK(*pdtlv);
                type = EXTRACT_16BITS(&pdtlv->type);
-               tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
                aln = F_ALN_LEN(EXTRACT_16BITS(&pdtlv->length));
                invtlv = tlv_valid(pdtlv, len);
                if (invtlv) {
@@ -223,6 +222,7 @@ pdatacnt_print(register const u_char * pptr, register u_int len,
                             EXTRACT_16BITS(&pdtlv->length));
                        goto pd_err;
                }
+               tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
                if (aln > EXTRACT_16BITS(&pdtlv->length)) {
                        if (aln > len) {
                                printf
@@ -769,7 +769,7 @@ forces_type_print(register const u_char * pptr, const struct forcesh *fhdr _U_,
        int rc = 0;
        int ttlv = 0;
 
-       tll = mlen - sizeof(struct forcesh);
+       tll = mlen - ForCES_HDRL;
 
        if (tll > TLV_HLN) {
                if (tops->flags & ZERO_TTLV) {
@@ -821,9 +821,8 @@ forces_type_print(register const u_char * pptr, const struct forcesh *fhdr _U_,
                        break;
        }
        if (tll) {
-               printf("\tMess TopTLV header: min %lu, total %d advertised %d ",
-                      (unsigned long)sizeof(struct forces_tlv),
-                      tll, EXTRACT_16BITS(&tltlv->length));
+               printf("\tMess TopTLV header: min %u, total %d advertised %d ",
+                      TLV_HDRL, tll, EXTRACT_16BITS(&tltlv->length));
                return -1;
        }
 
@@ -860,8 +859,8 @@ void forces_print(register const u_char * pptr, register u_int len)
        printf("\n\tForCES %s ", tops->s);
        if (!ForCES_HLN_VALID(mlen, len)) {
                printf
-                   ("Illegal ForCES pkt len - min %lu, total recvd %d, advertised %d ",
-                    (unsigned long)sizeof(struct forcesh), len, ForCES_BLN(fhdr));
+                   ("Illegal ForCES pkt len - min %u, total recvd %d, advertised %d ",
+                    ForCES_HDRL, len, ForCES_BLN(fhdr));
                goto error;
        }