]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Get rid of some includes, and use "u_int8_t" and "u_int16_t" in packet
authorguy <guy>
Tue, 10 Oct 2000 05:14:35 +0000 (05:14 +0000)
committerguy <guy>
Tue, 10 Oct 2000 05:14:35 +0000 (05:14 +0000)
layout definitions, as per Alfredo AndrĂ©s's suggestion.

Don't use expressions with side effects inside EXTRACT macros - the
arguments of those macros are used more than once, so the side-effects
(incrementing the pointer) occurs more than once, and they occur in a
sequence that may not be the same for all compilers.

When printing a UNIX time value, extract the value into a "time_t"
variable, and then pass a pointer to that variable to "ctime()", don't
cast the result of "EXTRACT_32BITS()" to a pointer.  Also, when printing
the result of "ctime()", print only the first 24 characters, so that the
newline at the end isn't printed.

Cast the first argument passed to "radius_attr_print()", and the
argument passed to the print function for an attribute, to "u_char *",
not "char *", as those routines expect a "u_char *".

print-radius.c

index 9cf4a919c7361ee7dfc5ac63f4a6bac7bee12240..70a40336fcfc9bd3d84c2b62d9beb5cea8fdbb96 100644 (file)
@@ -23,7 +23,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "$Id: print-radius.c,v 1.2 2000-10-08 08:48:48 guy Exp $";
+    "$Id: print-radius.c,v 1.3 2000-10-10 05:14:35 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -40,9 +40,6 @@ static const char rcsid[] =
 #include "addrtoname.h"
 #include "extract.h"
 
-#include "ip.h"
-#include "udp.h"
-
 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
 
 #define PRINT_HEX(bytes_len, ptr_data)                               \
@@ -112,15 +109,15 @@ static void print_attr_time(register u_char *, u_int, u_short);
 static void print_attr_strange(register u_char *, u_int, u_short);
 
 
-struct radius_hdr { u_char  code; /* Radius packet code  */
-                    u_char  id;   /* Radius packet id    */
-                    u_short len;  /* Radius total length */
-                    u_char  auth[16]; /* Authenticator   */
+struct radius_hdr { u_int8_t  code; /* Radius packet code  */
+                    u_int8_t  id;   /* Radius packet id    */
+                    u_int16_t len;  /* Radius total length */
+                    u_int8_t  auth[16]; /* Authenticator   */
                   };
 
 
-struct radius_attr { u_char type; /* Attribute type   */
-                     u_char len;  /* Attribute length */
+struct radius_attr { u_int8_t type; /* Attribute type   */
+                     u_int8_t len;  /* Attribute length */
                    };
 
 
@@ -470,6 +467,7 @@ print_attr_string(register u_char *data, u_int length, u_short attr_code )
 static void
 print_attr_num(register u_char *data, u_int length, u_short attr_code )
 {
+   u_int8_t tag;
    u_int32_t timeout;
    
    TCHECK2(data[0],4);
@@ -486,10 +484,14 @@ print_attr_num(register u_char *data, u_int length, u_short attr_code )
             printf("{Tag[Unused]");
          else
             printf("{Tag[%d]", *data);
-         data_value = EXTRACT_24BITS(++data);
+         data++;
+         data_value = EXTRACT_24BITS(data);
       }
       else
-         data_value = EXTRACT_32BITS(++data);
+      {
+        data++;
+         data_value = EXTRACT_32BITS(data);
+      }
       if ( data_value <= (attr_type[attr_code].siz_subtypes - 1 +
             attr_type[attr_code].first_subtype) )
          printf("{%s}",table[data_value]);
@@ -542,10 +544,12 @@ print_attr_num(register u_char *data, u_int length, u_short attr_code )
           break;
 
         case TUNNEL_PREFERENCE:
-            if (!*data)
-               printf("{Tag[Unused] %d}",EXTRACT_24BITS(++data) );
+            tag = *data;
+            data++;
+            if (tag == 0)
+               printf("{Tag[Unused] %d}",EXTRACT_24BITS(data) );
             else
-               printf("{Tag[%d] %d}", *data, EXTRACT_24BITS(++data) );
+               printf("{Tag[%d] %d}", tag, EXTRACT_24BITS(data) );
           break;
 
         default:
@@ -610,9 +614,12 @@ print_attr_address(register u_char *data, u_int length, u_short attr_code )
 /*************************************/
 static void print_attr_time(register u_char *data, u_int length, u_short attr_code)
 {
+   time_t attr_time;
+
    TCHECK2(data[0],4);
    
-   printf("{%s}", ctime( ((const time_t *)EXTRACT_32BITS(data) )) );
+   attr_time = EXTRACT_32BITS(data);
+   printf("{%.24s}", ctime(&attr_time));
    return;
    
    trunc:
@@ -700,7 +707,7 @@ radius_attr_print(register u_char *attr, u_int length)
            printf(" %s",attr_type[rad_attr->type].name);
 
            if ( attr_type[rad_attr->type].print_func )
-              (*attr_type[rad_attr->type].print_func)( ((char *)(rad_attr+1)),
+              (*attr_type[rad_attr->type].print_func)( ((u_char *)(rad_attr+1)),
                                            rad_attr->len - 2, rad_attr->type);
         }
      }
@@ -778,5 +785,5 @@ radius_print(const u_char *dat, u_int length)
    printf(" [id %d]", rad->id);
  
    if (i)
-      radius_attr_print( ((char *)(rad+1)), i);  
+      radius_attr_print( ((u_char *)(rad+1)), i);  
 }