]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Don't use bitfields in on-the-wire structures.
authorGuy Harris <[email protected]>
Mon, 11 Jan 2010 01:56:49 +0000 (17:56 -0800)
committerGuy Harris <[email protected]>
Mon, 11 Jan 2010 01:56:49 +0000 (17:56 -0800)
C doesn't guarantee that bit fields will be in any particular order.

forces.h
print-forces.c

index 2a777b20211af8f55dc4606c52c3ea9255f5b873..eb06dc8d4a327853ef252f6535f121802bf77d05 100644 (file)
--- a/forces.h
+++ b/forces.h
@@ -196,13 +196,8 @@ static inline const char *ForCES_TPp(u_int32_t flg)
  * Structure of forces header, naked of TLVs.
  */
 struct forcesh {
-#if BYTE_ORDER == LITTLE_ENDIAN
-       u_int8_t fm_rsvd:4, fm_version:4;
-#elif BYTE_ORDER == BIG_ENDIAN
-       u_int8_t fm_version:4, fm_rsvd:4;
-#endif
-
-#define ForCES_V(forcesh)      (forcesh)->fm_version
+       u_int8_t fm_vrsvd;      /* version and reserved */
+#define ForCES_V(forcesh)      ((forcesh)->fm_vrsvd >> 4)
        u_int8_t fm_tom;        /* type of message */
        u_int16_t fm_len;       /* total length * 4 bytes */
 #define ForCES_BLN(forcesh)    ntohs((forcesh)->fm_len) << 2
@@ -211,13 +206,14 @@ struct forcesh {
        u_int32_t fm_did;       /* Destination ID */
 #define ForCES_DID(forcesh)    ntohl((forcesh)->fm_did)
        u_int8_t fm_cor[8];     /* correlator */
-#if BYTE_ORDER == LITTLE_ENDIAN
-       u_int16_t f_rs1:3, f_pri:3, f_ack:2, f_rs2:3, f_tp:2, f_at:1, f_em:2;
-#elif BYTE_ORDER == BIG_ENDIAN
-       u_int16_t f_ack:2, f_pri:3, f_rs1:3, f_em:2, f_at:1, f_tp:2, f_rs2:3;
-#endif
-       u_int16_t f_rs3;
-
+       u_int32_t fm_flags;     /* flags */
+#define ForCES_ACK(forcesh)    ((ntohl((forcesh)->fm_flags)&0xC0000000) >> 30)
+#define ForCES_PRI(forcesh)    ((ntohl((forcesh)->fm_flags)&0x38000000) >> 27)
+#define ForCES_RS1(forcesh)    ((ntohl((forcesh)->fm_flags)&0x07000000) >> 24)
+#define ForCES_EM(forcesh)     ((ntohl((forcesh)->fm_flags)&0x00C00000) >> 22)
+#define ForCES_AT(forcesh)     ((ntohl((forcesh)->fm_flags)&0x00200000) >> 21)
+#define ForCES_TP(forcesh)     ((ntohl((forcesh)->fm_flags)&0x00180000) >> 19)
+#define ForCES_RS2(forcesh)    ((ntohl((forcesh)->fm_flags)&0x0007FFFF) >> 0)
 };
 
 #define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= (int)sizeof(struct forcesh) && \
index 2ad063bc852315c6afed60a7a146016523a8bf59..ff79d6d5606da6513adb1b362d13fdc88fa8a8a3 100644 (file)
@@ -765,12 +765,14 @@ void forces_print(register const u_char * pptr, register u_int len)
        if (vflag >= 2) {
                printf
                    ("\n\tForCES flags:\n\t  %s(0x%x), prio=%d, %s(0x%x),\n\t  %s(0x%x), %s(0x%x)\n",
-                    ForCES_ACKp(fhdr->f_ack), fhdr->f_ack, fhdr->f_pri,
-                    ForCES_EMp(fhdr->f_em), fhdr->f_em, ForCES_ATp(fhdr->f_at),
-                    fhdr->f_at, ForCES_TPp(fhdr->f_tp), fhdr->f_tp);
+                    ForCES_ACKp(ForCES_ACK(fhdr)), ForCES_ACK(fhdr),
+                    ForCES_PRI(fhdr),
+                    ForCES_EMp(ForCES_EM(fhdr)), ForCES_EM(fhdr),
+                    ForCES_ATp(ForCES_AT(fhdr)), ForCES_AT(fhdr),
+                    ForCES_TPp(ForCES_TP(fhdr)), ForCES_TP(fhdr));
                printf
-                   ("\t  Extra flags: rsv(b5-7) 0x%x rsv(b13-15) 0x%x rsv(b16-31) 0x%x\n",
-                    fhdr->f_rs1, fhdr->f_rs2, ntohs(fhdr->f_rs3));
+                   ("\t  Extra flags: rsv(b5-7) 0x%x rsv(b13-31) 0x%x\n",
+                    ForCES_RS1(fhdr), ForCES_RS2(fhdr));
        }
        rc = forces_type_print(pptr, fhdr, mlen, tops);
        if (rc < 0) {