]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Don't use "sizeof" to compute the sizes of various headers - the
authorguy <guy>
Thu, 14 Jun 2001 09:50:01 +0000 (09:50 +0000)
committerguy <guy>
Thu, 14 Jun 2001 09:50:01 +0000 (09:50 +0000)
structures for the headers might have padding added by the compiler (I
think at least some versions of GCC for ARM, for example, pad structures
to a multiple of 4 bytes in length), use explicit #define values.

The sequence control field of a management frame header is 16 bits long,
not 8 bits long.

ieee802_11.h
print-802_11.c

index ff21e999d2c8742bfac3c381003908e6203193bf..ac5a6f43f0ccc0b27c90f22bd2725d036064cd99 100644 (file)
@@ -1,4 +1,4 @@
-/* @(#) $Header: /tcpdump/master/tcpdump/ieee802_11.h,v 1.2 2001-06-13 07:25:57 guy Exp $ (LBL) */
+/* @(#) $Header: /tcpdump/master/tcpdump/ieee802_11.h,v 1.3 2001-06-14 09:50:01 guy Exp $ (LBL) */
 /*
  * Copyright (c) 2001
  *     Fortress Technologies
@@ -74,9 +74,11 @@ struct mgmt_header_t {
        u_int8_t        da[6];
        u_int8_t        sa[6];
        u_int8_t        bssid[6];
-       u_int8_t        seq_ctrl;
+       u_int16_t       seq_ctrl;
 };
 
+#define MGMT_HEADER_LEN        (2+2+6+6+6+2)
+
 #define CAPABILITY_ESS(cap)    ((cap) & 0x0001)
 #define CAPABILITY_IBSS(cap)   ((cap) & 0x0002)
 #define CAPABILITY_CFP(cap)    ((cap) & 0x0004)
@@ -187,6 +189,8 @@ struct ctrl_rts_t {
        u_int8_t        fcs[4];
 };
 
+#define CTRL_RTS_LEN   (2+2+6+6+4)
+
 struct ctrl_cts_t {
        u_int16_t       fc;
        u_int16_t       duration;
@@ -194,6 +198,8 @@ struct ctrl_cts_t {
        u_int8_t        fcs[4];
 };
 
+#define CTRL_CTS_LEN   (2+2+6+4)
+
 struct ctrl_ack_t {
        u_int16_t       fc;
        u_int16_t       duration;
@@ -201,6 +207,8 @@ struct ctrl_ack_t {
        u_int8_t        fcs[4];
 };
 
+#define CTRL_ACK_LEN   (2+2+6+4)
+
 struct ctrl_ps_poll_t {
        u_int16_t       fc;
        u_int16_t       aid;
@@ -209,6 +217,8 @@ struct ctrl_ps_poll_t {
        u_int8_t        fcs[4];
 };
 
+#define CTRL_PS_POLL_LEN       (2+2+6+6+4)
+
 struct ctrl_end_t {
        u_int16_t       fc;
        u_int16_t       duration;
@@ -217,6 +227,8 @@ struct ctrl_end_t {
        u_int8_t        fcs[4];
 };
 
+#define CTRL_END_LEN   (2+2+6+6+4)
+
 struct ctrl_end_ack_t {
        u_int16_t       fc;
        u_int16_t       duration;
@@ -225,6 +237,8 @@ struct ctrl_end_ack_t {
        u_int8_t        fcs[4];
 };
 
+#define CTRL_END_ACK_LEN       (2+2+6+6+4)
+
 #define IV_IV(iv)      ((iv) & 0xFFFFFF)
 #define IV_PAD(iv)     (((iv) >> 24) & 0x3F)
 #define IV_KEYID(iv)   (((iv) >> 30) & 0x03)
index 87258a342f3debb0b4b0b99386c529c0562bedd1..11d25a6f3f3c7832eda551884cdcc2075d7761a7 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.2 2001-06-13 07:25:58 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.3 2001-06-14 09:50:02 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -534,12 +534,13 @@ static int ctrl_body_print(u_int16_t fc,const u_char *p, u_int length)
        switch (FC_SUBTYPE(fc))
        {
                case CTRL_PS_POLL:
-                       if (!TTEST(*((struct ctrl_ps_poll_t *)p)))
+                       if (!TTEST2(*p, CTRL_PS_POLL_LEN))
                                return 0;
-                       printf("Power Save-Poll AID(%x)",((u_int16_t)( ((struct ctrl_ps_poll_t *)p)->aid  << 2 )) >> 2 );
+                       printf("Power Save-Poll AID(%x)",
+                           EXTRACT_LE_16BITS(&(((struct ctrl_ps_poll_t *)p)->aid)));
                        break;
                case CTRL_RTS:
-                       if (!TTEST(*((struct ctrl_rts_t *)p)))
+                       if (!TTEST2(*p, CTRL_RTS_LEN))
                                return 0;
                        if (eflag)
                                printf("Request-To-Send");
@@ -547,7 +548,7 @@ static int ctrl_body_print(u_int16_t fc,const u_char *p, u_int length)
                                printf("Request-To-Send TA:%s ", etheraddr_string( ((struct ctrl_rts_t *)p)->ta));
                        break;
                case CTRL_CTS:
-                       if (!TTEST(*((struct ctrl_cts_t *)p)))
+                       if (!TTEST2(*p, CTRL_CTS_LEN))
                                return 0;
                        if (eflag)
                                printf("Clear-To-Send");
@@ -555,7 +556,7 @@ static int ctrl_body_print(u_int16_t fc,const u_char *p, u_int length)
                                printf("Clear-To-Send RA:%s ", etheraddr_string( ((struct ctrl_cts_t *)p)->ra));
                        break;
                case CTRL_ACK:
-                       if (!TTEST(*((struct ctrl_ack_t *)p)))
+                       if (!TTEST2(*p, CTRL_ACK_LEN))
                                return 0;
                        if (eflag)
                                printf("Acknowledgment");
@@ -563,7 +564,7 @@ static int ctrl_body_print(u_int16_t fc,const u_char *p, u_int length)
                                printf("Acknowledgment RA:%s ", etheraddr_string( ((struct ctrl_ack_t *)p)->ra));
                        break;
                case CTRL_CF_END:
-                       if (!TTEST(*((struct ctrl_end_t *)p)))
+                       if (!TTEST2(*p, CTRL_END_LEN))
                                return 0;
                        if (eflag)
                                printf("CF-End");
@@ -571,7 +572,7 @@ static int ctrl_body_print(u_int16_t fc,const u_char *p, u_int length)
                                printf("CF-End RA:%s ", etheraddr_string( ((struct ctrl_end_t *)p)->ra));
                        break;
                case CTRL_END_ACK:
-                       if (!TTEST(*((struct ctrl_end_ack_t *)p)))
+                       if (!TTEST2(*p, CTRL_END_ACK_LEN))
                                return 0;
                        if (eflag)
                                printf("CF-End+CF-Ack");
@@ -677,28 +678,28 @@ static int GetHeaderLength(u_int16_t fc)
        switch (FC_TYPE(fc))
        {
                case T_MGMT:
-                       iLength=sizeof(struct mgmt_header_t);
+                       iLength=MGMT_HEADER_LEN;
                        break;
                case T_CTRL:
                        switch (FC_SUBTYPE(fc))
                        {
                                case CTRL_PS_POLL:
-                                       iLength=sizeof(struct ctrl_ps_poll_t);
+                                       iLength=CTRL_PS_POLL_LEN;
                                        break;
                                case CTRL_RTS:
-                                       iLength=sizeof(struct ctrl_rts_t);
+                                       iLength=CTRL_RTS_LEN;
                                        break;
                                case CTRL_CTS:
-                                       iLength=sizeof(struct ctrl_cts_t);
+                                       iLength=CTRL_CTS_LEN;
                                        break;
                                case CTRL_ACK:
-                                       iLength=sizeof(struct ctrl_ack_t);
+                                       iLength=CTRL_ACK_LEN;
                                        break;
                                case CTRL_CF_END:
-                                       iLength=sizeof(struct ctrl_end_t);
+                                       iLength=CTRL_END_LEN;
                                        break;
                                case CTRL_END_ACK:
-                                       iLength=sizeof(struct ctrl_end_ack_t);
+                                       iLength=CTRL_END_ACK_LEN;
                                        break;
                                default:
                                        iLength=0;