]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Make "subtype_text[]" have 16 elements, for all 16 possible subtypes,
authorguy <guy>
Sat, 30 Jul 2005 00:05:32 +0000 (00:05 +0000)
committerguy <guy>
Sat, 30 Jul 2005 00:05:32 +0000 (00:05 +0000)
and make all unknown subtypes have null pointers and, if the pointer for
a subtype is null, print the subtype as "Unknown subtype".

Compute the sizes of the tables of authentication algorithm names,
status code strings, and reason code strings at compile time, and use
those values to check whether the value is in the table or not.  Get rid
of trailing NULL pointers in those tables.

Fix a typo in one reason code string.

print-802_11.c

index e7acb79ec96745493bf6a067afabd93a6c468c4a..968379e2b47af7640513e3efa16ba583b7df7544 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.33 2005-07-07 01:22:16 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.34 2005-07-30 00:05:32 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -62,22 +62,25 @@ do { \
 } while (0)
 
 static const char *auth_alg_text[]={"Open System","Shared Key","EAP"};
-static const char *subtype_text[]={
+#define NUM_AUTH_ALGS  (sizeof auth_alg_text / sizeof auth_alg_text[0])
+
+static const char *subtype_text[16]={
        "Assoc Request",
        "Assoc Response",
        "ReAssoc Request",
        "ReAssoc Response",
        "Probe Request",
        "Probe Response",
-       "",
-       "",
+       NULL,
+       NULL,
        "Beacon",
        "ATIM",
        "Disassociation",
        "Authentication",
        "DeAuthentication",
-       "",
-       ""
+       NULL,
+       NULL,
+       NULL
 };
 
 static const char *status_text[] = {
@@ -102,8 +105,8 @@ static const char *status_text[] = {
        "Association denied because AP is unable to handle additional associated stations",       /*  17 */
        "Association denied due to requesting station not supporting all of the " \
                "data rates in BSSBasicRateSet parameter",        /*  18 */
-       NULL
 };
+#define NUM_STATUSES   (sizeof status_text / sizeof status_text[0])
 
 static const char *reason_text[] = {
        "Reserved", /* 0 */
@@ -112,12 +115,12 @@ static const char *reason_text[] = {
        "Deauthenticated because sending station is leaving (or has left) IBSS or ESS", /* 3 */
        "Disassociated due to inactivity", /* 4 */
        "Disassociated because AP is unable to handle all currently associated stations", /* 5 */
-       "Class 2 frame receivedfrom nonauthenticated station", /* 6 */
+       "Class 2 frame received from nonauthenticated station", /* 6 */
        "Class 3 frame received from nonassociated station", /* 7 */
        "Disassociated because sending station is leaving (or has left) BSS", /* 8 */
        "Station requesting (re)association is not authenticated with responding station", /* 9 */
-       NULL
 };
+#define NUM_REASONS    (sizeof reason_text / sizeof reason_text[0])
 
 static int
 wep_print(const u_char *p)
@@ -309,7 +312,9 @@ handle_assoc_response(const u_char *p)
 
        printf(" AID(%x) :%s: %s", ((u_int16_t)(pbody.aid << 2 )) >> 2 ,
            CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "",
-           (pbody.status_code < 19 ? status_text[pbody.status_code] : "n/a"));
+           (pbody.status_code < NUM_STATUSES
+               ? status_text[pbody.status_code]
+               : "n/a"));
 
        return 1;
 }
@@ -419,8 +424,9 @@ handle_disassoc(const u_char *p)
        pbody.reason_code = EXTRACT_LE_16BITS(p);
 
        printf(": %s",
-           (pbody.reason_code < 10) ? reason_text[pbody.reason_code]
-                                    : "Reserved" );
+           (pbody.reason_code < NUM_REASONS)
+               ? reason_text[pbody.reason_code]
+               : "Reserved" );
 
        return 1;
 }
@@ -449,21 +455,25 @@ handle_auth(const u_char *p)
            ((pbody.auth_trans_seq_num == 2) ||
             (pbody.auth_trans_seq_num == 3))) {
                printf(" (%s)-%x [Challenge Text] %s",
-                   (pbody.auth_alg < 4) ? auth_alg_text[pbody.auth_alg]
-                                        : "Reserved",
+                   (pbody.auth_alg < NUM_AUTH_ALGS)
+                       ? auth_alg_text[pbody.auth_alg]
+                       : "Reserved",
                    pbody.auth_trans_seq_num,
                    ((pbody.auth_trans_seq_num % 2)
-                       ? ((pbody.status_code < 19)
+                       ? ((pbody.status_code < NUM_STATUSES)
                               ? status_text[pbody.status_code]
                               : "n/a") : ""));
                return 1;
        }
        printf(" (%s)-%x: %s",
-           (pbody.auth_alg < 4) ? auth_alg_text[pbody.auth_alg] : "Reserved",
+           (pbody.auth_alg < NUM_AUTH_ALGS)
+               ? auth_alg_text[pbody.auth_alg]
+               : "Reserved",
            pbody.auth_trans_seq_num,
            (pbody.auth_trans_seq_num % 2)
-               ? ((pbody.status_code < 19) ? status_text[pbody.status_code]
-                                           : "n/a")
+               ? ((pbody.status_code < NUM_STATUSES)
+                   ? status_text[pbody.status_code]
+                   : "n/a")
                : "");
 
        return 1;
@@ -483,8 +493,9 @@ handle_deauth(const struct mgmt_header_t *pmh, const u_char *p)
        pbody.reason_code = EXTRACT_LE_16BITS(p);
        offset += IEEE802_11_REASON_LEN;
 
-       reason = (pbody.reason_code < 10) ? reason_text[pbody.reason_code]
-                                         : "Reserved";
+       reason = (pbody.reason_code < NUM_REASONS)
+                       ? reason_text[pbody.reason_code]
+                       : "Reserved";
 
        if (eflag) {
                printf(": %s", reason);
@@ -504,7 +515,10 @@ static int
 mgmt_body_print(u_int16_t fc, const struct mgmt_header_t *pmh,
     const u_char *p)
 {
-       printf("%s", subtype_text[FC_SUBTYPE(fc)]);
+       if (subtype_text[FC_SUBTYPE(fc)] != NULL)
+               printf("%s", subtype_text[FC_SUBTYPE(fc)]);
+       else
+               printf("Unknown subtype %u", FC_SUBTYPE(fc));
 
        switch (FC_SUBTYPE(fc)) {
        case ST_ASSOC_REQUEST: