Add a "abs_time_secs_to_str()" routine that takes a UNIX time-since-the-
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 11 Feb 2003 19:42:38 +0000 (19:42 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 11 Feb 2003 19:42:38 +0000 (19:42 +0000)
epoch-in-seconds value and converts it to a string.

Use that routine in the RADIUS dissector, rather than using "ctime()"
and "tzname[]" - "tzname[]" strings might contain non-ASCII characters,
which currently give the GTK+ 1.3[.x] used on Windows, and also, I
think, GTK+ 2.x, heartburn, as they expect UTF-8, not, for example, ISO
8859/1.

Fix the string length in "abs_time_to_str()".

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@7124 f5534014-38df-0310-8fa8-9805f1628bb7

epan/to_str.c
epan/to_str.h
packet-radius.c

index a7a7b5d95859a5aee6752c8842189cb45539b85c..a0315c30de125cd107552ae17413fcb836bf2d8a 100644 (file)
@@ -1,7 +1,7 @@
 /* to_str.c
  * Routines for utilities to convert various other types to strings.
  *
- * $Id: to_str.c,v 1.23 2003/01/21 05:04:07 guy Exp $
+ * $Id: to_str.c,v 1.24 2003/02/11 19:42:38 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -416,7 +416,7 @@ abs_time_to_str(nstime_t *abs_time)
 {
         struct tm *tmp;
         static gchar *cur;
-        static char str[3][3+1+2+2+4+1+2+1+2+1+2+1+6+1 + 5 /* extra */];
+        static char str[3][3+1+2+2+4+1+2+1+2+1+2+1+9+1];
 
         if (cur == &str[0][0]) {
                 cur = &str[1][0];
@@ -428,17 +428,45 @@ abs_time_to_str(nstime_t *abs_time)
 
         tmp = localtime(&abs_time->secs);
         if (tmp) {
-          sprintf(cur, "%s %2d, %d %02d:%02d:%02d.%09ld",
-                  mon_names[tmp->tm_mon],
-                  tmp->tm_mday,
-                  tmp->tm_year + 1900,
-                  tmp->tm_hour,
-                  tmp->tm_min,
-                  tmp->tm_sec,
-                  (long)abs_time->nsecs);
+               sprintf(cur, "%s %2d, %d %02d:%02d:%02d.%09ld",
+                   mon_names[tmp->tm_mon],
+                   tmp->tm_mday,
+                   tmp->tm_year + 1900,
+                   tmp->tm_hour,
+                   tmp->tm_min,
+                   tmp->tm_sec,
+                   (long)abs_time->nsecs);
+        } else
+               strncpy(cur, "Not representable", sizeof(str[0]));
+        return cur;
+}
+
+gchar *
+abs_time_secs_to_str(guint32 abs_time)
+{
+        struct tm *tmp;
+        static gchar *cur;
+        static char str[3][3+1+2+2+4+1+2+1+2+1+2+1];
+
+        if (cur == &str[0][0]) {
+                cur = &str[1][0];
+        } else if (cur == &str[1][0]) {
+                cur = &str[2][0];
         } else {
-          strncpy(cur, "Not representable", sizeof(str[0]));
+                cur = &str[0][0];
         }
+
+        tmp = localtime(&abs_time);
+        if (tmp) {
+               sprintf(cur, "%s %2d, %d %02d:%02d:%02d",
+                   mon_names[tmp->tm_mon],
+                   tmp->tm_mday,
+                   tmp->tm_year + 1900,
+                   tmp->tm_hour,
+                   tmp->tm_min,
+                   tmp->tm_sec);
+        } else
+               strncpy(cur, "Not representable", sizeof(str[0]));
         return cur;
 }
 
index 4743d7c6a86e45c649f4c47bf6cd75e81f0beb92..e14c44bd090c7163e4fd590f55267975bbc68c27 100644 (file)
@@ -1,7 +1,7 @@
 /* to_str.h
  * Definitions for utilities to convert various other types to strings.
  *
- * $Id: to_str.h,v 1.12 2002/12/09 21:34:58 guy Exp $
+ * $Id: to_str.h,v 1.13 2003/02/11 19:42:38 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -58,6 +58,7 @@ extern gchar* vines_addr_to_str(const guint8 *addrp);
 extern gchar*  time_secs_to_str(guint32);
 extern gchar*  time_msecs_to_str(guint32);
 extern gchar*  abs_time_to_str(nstime_t*);
+extern gchar*  abs_time_secs_to_str(guint32);
 extern void    display_signed_time(gchar *, int, gint32, gint32, time_res_t);
 extern gchar*  rel_time_to_str(nstime_t*);
 extern gchar*  rel_time_to_secs_str(nstime_t*);
index 339fa3ccba003e398ddfc2e00e789fbac7f2a25d..81f920713ee7f34fe567aa500697328045c14621 100644 (file)
@@ -5,7 +5,7 @@
  *
  * RFC 2865, RFC 2866, RFC 2867, RFC 2868, RFC 2869
  *
- * $Id: packet-radius.c,v 1.73 2003/01/28 16:31:03 guy Exp $
+ * $Id: packet-radius.c,v 1.74 2003/02/11 19:42:36 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -2523,8 +2523,6 @@ static gchar *rd_value_to_str_2(gchar *dest, const e_avphdr *avph, tvbuff_t *tvb
   guint32 intval;
   const guint8 *pd;
   guint8 tag;
-  char *rtimestamp;
-  extern char *tzname[2];
 
   int vsa_length;
   int vsa_len;
@@ -2729,9 +2727,7 @@ static gchar *rd_value_to_str_2(gchar *dest, const e_avphdr *avph, tvbuff_t *tvb
 
         case( RADIUS_TIMESTAMP ):
                intval=tvb_get_ntohl(tvb,offset+2);
-               rtimestamp=ctime((time_t*)&intval);
-               rtimestamp[strlen(rtimestamp)-1]=0;
-               sprintf(cont,"%d (%s %s)", tvb_get_ntohl(tvb,offset+2), rtimestamp, *tzname);
+               sprintf(cont,"%d (%s)", intval, abs_time_secs_to_str(intval));
                break;
         case( RADIUS_INTEGER4_TAGGED ):
                intval = tvb_get_ntohl(tvb,offset+2);