From Michael Mann:
authorAnders Broman <anders.broman@ericsson.com>
Mon, 4 Jul 2011 21:43:34 +0000 (21:43 -0000)
committerAnders Broman <anders.broman@ericsson.com>
Mon, 4 Jul 2011 21:43:34 +0000 (21:43 -0000)
Added ability to display UTC time or UTC time with date.  I liked having the
difference between UTC and local time, not just setting local=UTC.

https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=2629

svn path=/trunk/; revision=37898

12 files changed:
epan/column-utils.c
epan/column.c
epan/column_info.h
epan/frame_data.c
epan/timestamp.h
epan/wslua/wslua_pinfo.c
gtk/main.c
gtk/menus.c
gtk/packet_list_store.c
gtk/recent.c
rawshark.c
tshark.c

index ddd2ffa7c23687b0c984a0e7c74f983a95a4b30c..e3397aa9a498379930a05ba26355e94e7f5bab68 100644 (file)
@@ -613,19 +613,24 @@ col_has_time_fmt(column_info *cinfo, const gint col)
   return ((cinfo->fmt_matx[col][COL_CLS_TIME]) ||
           (cinfo->fmt_matx[col][COL_ABS_TIME]) ||
           (cinfo->fmt_matx[col][COL_ABS_DATE_TIME]) ||
+          (cinfo->fmt_matx[col][COL_UTC_TIME]) ||
+          (cinfo->fmt_matx[col][COL_UTC_DATE_TIME]) ||
           (cinfo->fmt_matx[col][COL_REL_TIME]) ||
           (cinfo->fmt_matx[col][COL_DELTA_TIME]) ||
           (cinfo->fmt_matx[col][COL_DELTA_TIME_DIS]));
 }
 
 static gint
-set_abs_date_time(const frame_data *fd, gchar *buf)
+set_abs_date_time(const frame_data *fd, gchar *buf, gboolean local)
 {
   struct tm *tmp;
   time_t then;
 
   then = fd->abs_ts.secs;
-  tmp = localtime(&then);
+  if (local)
+     tmp = localtime(&then);
+  else
+     tmp = gmtime(&then);
   if (tmp != NULL) {
       switch(timestamp_get_precision()) {
       case TS_PREC_FIXED_SEC:
@@ -705,7 +710,17 @@ set_abs_date_time(const frame_data *fd, gchar *buf)
 static void
 col_set_abs_date_time(const frame_data *fd, column_info *cinfo, const int col)
 {
-  if (set_abs_date_time(fd, cinfo->col_buf[col])) {
+  if (set_abs_date_time(fd, cinfo->col_buf[col], TRUE)) {
+      cinfo->col_expr.col_expr[col] = "frame.time";
+      g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
+  }
+  cinfo->col_data[col] = cinfo->col_buf[col];
+}
+
+static void
+col_set_utc_date_time(const frame_data *fd, column_info *cinfo, const int col)
+{
+  if (set_abs_date_time(fd, cinfo->col_buf[col], FALSE)) {
       cinfo->col_expr.col_expr[col] = "frame.time";
       g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
   }
@@ -969,13 +984,16 @@ col_set_delta_time_dis(const frame_data *fd, column_info *cinfo, const int col)
 }
 
 static gint
-set_abs_time(const frame_data *fd, gchar *buf)
+set_abs_time(const frame_data *fd, gchar *buf, gboolean local)
 {
   struct tm *tmp;
   time_t then;
 
   then = fd->abs_ts.secs;
-  tmp = localtime(&then);
+  if (local)
+     tmp = localtime(&then);
+  else
+     tmp = gmtime(&then);
   if (tmp != NULL) {
       switch(timestamp_get_precision()) {
       case TS_PREC_FIXED_SEC:
@@ -1038,7 +1056,17 @@ set_abs_time(const frame_data *fd, gchar *buf)
 static void
 col_set_abs_time(const frame_data *fd, column_info *cinfo, const int col)
 {
-  if (set_abs_time(fd, cinfo->col_buf[col])) {
+  if (set_abs_time(fd, cinfo->col_buf[col], TRUE)) {
+      cinfo->col_expr.col_expr[col] = "frame.time";
+      g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
+  }
+  cinfo->col_data[col] = cinfo->col_buf[col];
+}
+
+static void
+col_set_utc_time(const frame_data *fd, column_info *cinfo, const int col)
+{
+  if (set_abs_time(fd, cinfo->col_buf[col], FALSE)) {
       cinfo->col_expr.col_expr[col] = "frame.time";
       g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
   }
@@ -1169,6 +1197,14 @@ col_set_cls_time(const frame_data *fd, column_info *cinfo, const gint col)
       col_set_epoch_time(fd, cinfo, col);
       break;
 
+    case TS_UTC:
+      col_set_utc_time(fd, cinfo, col);
+      break;
+
+    case TS_UTC_WITH_DATE:
+      col_set_utc_date_time(fd, cinfo, col);
+      break;
+
     case TS_NOT_SET:
       /* code is missing for this case, but I don't know which [jmayer20051219] */
       g_assert_not_reached();
@@ -1213,6 +1249,14 @@ col_set_fmt_time(const frame_data *fd, column_info *cinfo, const gint fmt, const
       col_set_delta_time_dis(fd, cinfo, col);
       break;
 
+    case TS_UTC:
+      col_set_utc_time(fd, cinfo, col);
+      break;
+
+    case TS_UTC_WITH_DATE:
+      col_set_utc_date_time(fd, cinfo, col);
+      break;
+
     default:
       g_assert_not_reached();
       break;
@@ -1456,6 +1500,8 @@ col_based_on_frame_data(column_info *cinfo, const gint col)
     case COL_CLS_TIME:
     case COL_ABS_TIME:
     case COL_ABS_DATE_TIME:
+    case COL_UTC_TIME:
+    case COL_UTC_DATE_TIME:
     case COL_REL_TIME:
     case COL_DELTA_TIME:
     case COL_DELTA_TIME_DIS:
@@ -1481,6 +1527,8 @@ col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col,
     case COL_CLS_TIME:
     case COL_ABS_TIME:
     case COL_ABS_DATE_TIME:
+    case COL_UTC_TIME:
+    case COL_UTC_DATE_TIME:
     case COL_REL_TIME:
     case COL_DELTA_TIME:
     case COL_DELTA_TIME_DIS:
@@ -1515,6 +1563,8 @@ col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col,
     case COL_CLS_TIME:
     case COL_ABS_TIME:
     case COL_ABS_DATE_TIME:
+    case COL_UTC_TIME:
+    case COL_UTC_DATE_TIME:
     case COL_REL_TIME:
     case COL_DELTA_TIME:
     case COL_DELTA_TIME_DIS:
@@ -1549,6 +1599,8 @@ col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fi
     case COL_CLS_TIME:
     case COL_ABS_TIME:
     case COL_ABS_DATE_TIME:
+    case COL_UTC_TIME:
+    case COL_UTC_DATE_TIME:
     case COL_REL_TIME:
     case COL_DELTA_TIME:
     case COL_DELTA_TIME_DIS:
@@ -1671,6 +1723,8 @@ col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col
     case COL_CLS_TIME:
     case COL_ABS_TIME:
     case COL_ABS_DATE_TIME:
+    case COL_UTC_TIME:
+    case COL_UTC_DATE_TIME:
     case COL_REL_TIME:
     case COL_DELTA_TIME:
     case COL_DELTA_TIME_DIS:
@@ -1741,7 +1795,9 @@ col_fill_fdata(packet_info *pinfo)
     case COL_CUMULATIVE_BYTES: /* fd->cum_bytes */
     case COL_CLS_TIME:
     case COL_ABS_TIME:
-    case COL_ABS_DATE_TIME:    /* from fd structures */
+    case COL_ABS_DATE_TIME:
+    case COL_UTC_TIME:
+    case COL_UTC_DATE_TIME:  /* from fd structures */
     case COL_REL_TIME:
     case COL_DELTA_TIME:
     case COL_DELTA_TIME_DIS:
@@ -1879,10 +1935,16 @@ gchar  *ptr;
       set_cls_time(fd, buf);
       break;
     case COL_ABS_TIME:
-      set_abs_time(fd, buf);
+      set_abs_time(fd, buf, TRUE);
+      break;
+    case COL_UTC_TIME:
+      set_abs_time(fd, buf, FALSE);
       break;
     case COL_ABS_DATE_TIME:
-      set_abs_date_time(fd, buf);
+      set_abs_date_time(fd, buf, TRUE);
+      break;
+    case COL_UTC_DATE_TIME:
+      set_abs_date_time(fd, buf, FALSE);
       break;
     case COL_REL_TIME:
       set_rel_time(fd, buf);
index 3cbbb6d876e22abc84ffd873130c8d5329300fbc..a3d3513a42088d94d467893ce5feaff28f1c01fb 100644 (file)
@@ -105,7 +105,9 @@ col_format_to_string(const gint fmt) {
     "%rS",                                      /* 55) COL_RES_SRC_PORT */
     "%uS",                                      /* 56) COL_UNRES_SRC_PORT */
     "%E",                                       /* 57) COL_TEI */
-    "%t"                                        /* 58) COL_CLS_TIME */
+    "%Yut",                                     /* 58) COL_UTC_DATE_TIME */
+    "%Aut",                                     /* 59) COL_UTC_TIME */
+    "%t"                                        /* 60) COL_CLS_TIME */
   };
 
   if (fmt < 0 || fmt >= NUM_COL_FMTS)
@@ -175,7 +177,9 @@ static const gchar *dlist[NUM_COL_FMTS] = {
     "Src port (resolved)",                      /* 55) COL_RES_SRC_PORT */
     "Src port (unresolved)",                    /* 56) COL_UNRES_SRC_PORT */
     "TEI",                                      /* 57) COL_TEI */
-    "Time (format as specified)"                /* 58) COL_CLS_TIME */
+    "UTC date and time",                        /* 58) COL_UTC_DATE_TIME */
+    "UTC time",                                 /* 59) COL_UTC_TIME */
+    "Time (format as specified)"                /* 60) COL_CLS_TIME */
 };
 
 const gchar *
@@ -316,6 +320,7 @@ get_timestamp_column_longest_string(const gint type, const gint precision)
 
     switch(type) {
     case(TS_ABSOLUTE_WITH_DATE):
+    case(TS_UTC_WITH_DATE):
         switch(precision) {
             case(TS_PREC_AUTO_SEC):
             case(TS_PREC_FIXED_SEC):
@@ -346,6 +351,7 @@ get_timestamp_column_longest_string(const gint type, const gint precision)
         }
             break;
     case(TS_ABSOLUTE):
+    case(TS_UTC):
         switch(precision) {
             case(TS_PREC_AUTO_SEC):
             case(TS_PREC_FIXED_SEC):
@@ -486,9 +492,15 @@ get_column_longest_string(const gint format)
     case COL_ABS_DATE_TIME:
       return get_timestamp_column_longest_string(TS_ABSOLUTE_WITH_DATE, timestamp_get_precision());
       break;
+    case COL_UTC_DATE_TIME:
+      return get_timestamp_column_longest_string(TS_UTC_WITH_DATE, timestamp_get_precision());
+      break;
     case COL_ABS_TIME:
       return get_timestamp_column_longest_string(TS_ABSOLUTE, timestamp_get_precision());
       break;
+    case COL_UTC_TIME:
+      return get_timestamp_column_longest_string(TS_UTC, timestamp_get_precision());
+      break;
     case COL_REL_TIME:
       return get_timestamp_column_longest_string(TS_RELATIVE, timestamp_get_precision());
       break;
index 8bf4c051911941d6ccddf86d0cd1429f2e29faca..74d22575b2802ba67fb3b963658bacb5f0a42d15 100644 (file)
@@ -132,8 +132,10 @@ enum {
   COL_RES_SRC_PORT,   /**< 55) Resolved source port */
   COL_UNRES_SRC_PORT, /**< 56) Unresolved source port */
   COL_TEI,            /**< 57) Q.921 TEI */
-  COL_CLS_TIME,       /**< 58) Command line-specified time (default relative) */
-  NUM_COL_FMTS        /**< 59) Should always be last */
+  COL_UTC_DATE_TIME,  /**< 58) UTC date and time */
+  COL_UTC_TIME,       /**< 59) UTC time */
+  COL_CLS_TIME,       /**< 60) Command line-specified time (default relative) */
+  NUM_COL_FMTS        /**< 61) Should always be last */
 };
 
 #ifdef __cplusplus
index 4bde07fa33600f27c280303bfa7857cb16cccee1..1154090ae60c001684ba698431dd34f1fd1a752f 100644 (file)
@@ -143,6 +143,8 @@ frame_data_compare(const frame_data *fdata1, const frame_data *fdata2, int field
             switch (timestamp_get_type()) {
                 case TS_ABSOLUTE:
                 case TS_ABSOLUTE_WITH_DATE:
+                case TS_UTC:
+                case TS_UTC_WITH_DATE:
                 case TS_EPOCH:
                     return COMPARE_TS(abs_ts);
 
@@ -162,6 +164,8 @@ frame_data_compare(const frame_data *fdata1, const frame_data *fdata2, int field
 
         case COL_ABS_TIME:
         case COL_ABS_DATE_TIME:
+        case COL_UTC_TIME:
+        case COL_UTC_DATE_TIME:
             return COMPARE_TS(abs_ts);
 
         case COL_REL_TIME:
index bdc9ab0d6211d9fcb9eb0b65116c8c2e94fc86e7..9282ac5216f86f6fe803101a57219c4953eca0e5 100644 (file)
@@ -35,6 +35,8 @@ typedef enum {
        TS_DELTA,               /* Since previous captured packet */
        TS_DELTA_DIS,           /* Since previous displayed packet */
        TS_EPOCH,               /* Seconds (and fractions) since epoch */
+       TS_UTC,
+       TS_UTC_WITH_DATE,
 
 /*
  * Special value used for the command-line setting in Wireshark, to indicate
index 2e12ac59b6df56444c7a4dcc69390df09f46781f..9a0969dcfcfe251c3f507c3b2374586b4a8bc52d 100644 (file)
@@ -299,9 +299,11 @@ struct col_names_t {
 static const struct col_names_t colnames[] = {
     {"number",COL_NUMBER},
     {"abs_time",COL_ABS_TIME},
+    {"utc_time",COL_UTC_TIME},
     {"cls_time",COL_CLS_TIME},
     {"rel_time",COL_REL_TIME},
     {"date",COL_ABS_DATE_TIME},
+    {"utc_date",COL_UTC_DATE_TIME},
     {"delta_time",COL_DELTA_TIME},
     {"delta_time_displayed",COL_DELTA_TIME_DIS},
     {"src",COL_DEF_SRC},
index f4213486ed0047a1919d764799afee1d43d73ea5..8214fee1171c3d470a9efb6cdf2106f0d24ed3b7 100644 (file)
@@ -2568,6 +2568,10 @@ main(int argc, char *argv[])
           timestamp_set_type(TS_DELTA_DIS);
         else if (strcmp(optarg, "e") == 0)
           timestamp_set_type(TS_EPOCH);
+        else if (strcmp(optarg, "u") == 0)
+          timestamp_set_type(TS_UTC);
+        else if (strcmp(optarg, "ud") == 0)
+          timestamp_set_type(TS_UTC_WITH_DATE);
         else {
           cmdarg_err("Invalid time stamp type \"%s\"", optarg);
           cmdarg_err_cont("It must be \"r\" for relative, \"a\" for absolute,");
index 7958b0224f02fb1b785917662983f6d07aa6e5d5..253db6702f331c9124bd939a0ef8501814aa1f55 100644 (file)
@@ -2015,6 +2015,10 @@ static GtkItemFactoryEntry menu_items[] =
                         TS_DELTA, "/View/Time Display Format/Date and Time of Day:   1970-01-01 01:02:03.123456", NULL,},
     {"/View/Time Display Format/Seconds Since Previous Displayed Packet:   1.123456", "<alt><control>6", GTK_MENU_FUNC(timestamp_format_cb),
                         TS_DELTA_DIS, "/View/Time Display Format/Date and Time of Day:   1970-01-01 01:02:03.123456", NULL,},
+    {"/View/Time Display Format/UTC Date and Time of Day:   1970-01-01 01:02:03.123456", "<alt><control>7", GTK_MENU_FUNC(timestamp_format_cb),
+                        TS_UTC_WITH_DATE, "/View/Time Display Format/Date and Time of Day:   1970-01-01 01:02:03.123456", NULL,},
+    {"/View/Time Display Format/UTC Time of Day:   01:02:03.123456", "<alt><control>8", GTK_MENU_FUNC(timestamp_format_cb),
+                        TS_UTC, "/View/Time Display Format/Date and Time of Day:   1970-01-01 01:02:03.123456", NULL,},
     {"/View/Time Display Format/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
     {"/View/Time Display Format/Automatic (File Format Precision)", NULL, GTK_MENU_FUNC(timestamp_precision_cb),
                         TS_PREC_AUTO, "<RadioItem>", NULL,},
@@ -5638,6 +5642,14 @@ menu_recent_read_finished(void) {
         menu = gtk_item_factory_get_widget(main_menu_factory,
             "/View/Time Display Format/Seconds Since Epoch (1970-01-01):   1234567890.123456");
         break;
+    case(TS_UTC_WITH_DATE):
+        menu = gtk_item_factory_get_widget(main_menu_factory,
+            "/View/Time Display Format/UTC Date and Time of Day:   1970-01-01 01:02:03.123456");
+        break;
+    case(TS_UTC):
+        menu = gtk_item_factory_get_widget(main_menu_factory,
+            "/View/Time Display Format/UTC Time of Day:   01:02:03.123456");
+        break;
     default:
         g_assert_not_reached();
     }
index cd1ff3d7a4c08be15fe4e8e8b74bb81676ad37a0..b974b5e278e57a433956140d18644d7ca41cc9e4 100644 (file)
@@ -1254,10 +1254,9 @@ packet_list_get_widest_column_string(PacketList *packet_list, gint col)
                                        fdata.cum_bytes = record->fdata->cum_bytes;
                                break;
                        case COL_ABS_TIME:
-                               if (nstime_cmp(&record->fdata->abs_ts, &fdata.abs_ts) > 0)
-                                       fdata.abs_ts = record->fdata->abs_ts;
-                               break;
                        case COL_ABS_DATE_TIME:
+                       case COL_UTC_TIME:
+                       case COL_UTC_DATE_TIME:
                                if (nstime_cmp(&record->fdata->abs_ts, &fdata.abs_ts) > 0)
                                        fdata.abs_ts = record->fdata->abs_ts;
                                break;
@@ -1276,11 +1275,9 @@ packet_list_get_widest_column_string(PacketList *packet_list, gint col)
                        case COL_CLS_TIME:
                                switch (timestamp_get_type()) {
                                case TS_ABSOLUTE:
-                                 if (nstime_cmp(&record->fdata->abs_ts, &fdata.abs_ts) > 0)
-                                         fdata.abs_ts = record->fdata->abs_ts;
-                                 break;
-
                                case TS_ABSOLUTE_WITH_DATE:
+                               case TS_UTC:
+                               case TS_UTC_WITH_DATE:
                                  if (nstime_cmp(&record->fdata->abs_ts, &fdata.abs_ts) > 0)
                                          fdata.abs_ts = record->fdata->abs_ts;
                                  break;
index e49543e2fefa5cbd8f5a10db6893ffe6ee708a60..43e6aedbdec36849ccee9832f92fec7d17a45184 100644 (file)
@@ -91,7 +91,7 @@
 recent_settings_t recent;
 
 static const char *ts_type_text[] =
-  { "RELATIVE", "ABSOLUTE", "ABSOLUTE_WITH_DATE", "DELTA", "DELTA_DIS", "EPOCH", NULL };
+  { "RELATIVE", "ABSOLUTE", "ABSOLUTE_WITH_DATE", "DELTA", "DELTA_DIS", "EPOCH", "UTC", "UTC_WITH_DATE", NULL };
 
 static const char *ts_precision_text[] =
        { "AUTO", "SEC", "DSEC", "CSEC", "MSEC", "USEC", "NSEC", NULL };
@@ -349,7 +349,7 @@ write_profile_recent(void)
                  recent.packet_list_colorize == TRUE ? "TRUE" : "FALSE");
 
   fprintf(rf, "\n# Timestamp display format.\n");
-  fprintf(rf, "# One of: RELATIVE, ABSOLUTE, ABSOLUTE_WITH_DATE, DELTA, DELTA_DIS, EPOCH\n");
+  fprintf(rf, "# One of: RELATIVE, ABSOLUTE, ABSOLUTE_WITH_DATE, DELTA, DELTA_DIS, EPOCH, UTC, UTC_WITH_DATE\n");
   fprintf(rf, RECENT_GUI_TIME_FORMAT ": %s\n",
           ts_type_text[recent.gui_time_format]);
 
index 4d2e0fef57bb6d1d4b31b424f5ca8ae1fb5165c2..df30037b8995ac76c1183e7b47a3516d9fd0f0d6 100644 (file)
@@ -691,6 +691,10 @@ main(int argc, char *argv[])
                     timestamp_set_type(TS_DELTA_DIS);
                 else if (strcmp(optarg, "e") == 0)
                     timestamp_set_type(TS_EPOCH);
+                else if (strcmp(optarg, "u") == 0)
+                    timestamp_set_type(TS_UTC);
+                else if (strcmp(optarg, "ud") == 0)
+                    timestamp_set_type(TS_UTC_WITH_DATE);
                 else {
                     cmdarg_err("Invalid time stamp type \"%s\"",
                                optarg);
index 1a3d761f40a2b7b12846ab225a96ff405530e47c..5d19b2d5ec5c70ef45ff436c7d29a5cbbb8c15bd 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -1263,6 +1263,10 @@ main(int argc, char *argv[])
         timestamp_set_type(TS_DELTA_DIS);
       else if (strcmp(optarg, "e") == 0)
         timestamp_set_type(TS_EPOCH);
+      else if (strcmp(optarg, "u") == 0)
+        timestamp_set_type(TS_UTC);
+      else if (strcmp(optarg, "ud") == 0)
+        timestamp_set_type(TS_UTC_WITH_DATE);
       else {
         cmdarg_err("Invalid time stamp type \"%s\"",
                    optarg);
@@ -3108,7 +3112,9 @@ print_columns(capture_file *cf)
     case COL_CLS_TIME:
     case COL_REL_TIME:
     case COL_ABS_TIME:
-    case COL_ABS_DATE_TIME: /* XXX - wider */
+    case COL_ABS_DATE_TIME:
+    case COL_UTC_TIME:
+    case COL_UTC_DATE_TIME: /* XXX - wider */
       column_len = strlen(cf->cinfo.col_data[i]);
       if (column_len < 10)
         column_len = 10;