Store pointers to previously displayed and captured packet, not nstime_t deltas.
[metze/wireshark/wip.git] / tshark.c
index 6a53f1b10eb9a011b2e0878d56723c57373511d7..118c75e2058d672b2a5ad40a3668056403d9c94a 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -24,9 +24,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -105,10 +103,13 @@ static const gchar decode_as_arg_template[] = "<layer_type>==<selector>,<decode_
 
 static guint32 cum_bytes;
 static nstime_t first_ts;
-static nstime_t prev_dis_ts;
-static nstime_t prev_cap_ts;
+static frame_data *prev_dis;
+static frame_data prev_dis_frame;
+static frame_data *prev_cap;
+static frame_data prev_cap_frame;
 
 static gboolean print_packet_info;      /* TRUE if we're to print packet information */
+static const char* prev_display_dissector_name = NULL;
 
 static gboolean perform_two_pass_analysis;
 
@@ -372,7 +373,11 @@ static void
 display_dissector_table_names(const char *table_name, const char *ui_name,
                               gpointer output)
 {
-  fprintf((FILE *)output, "\t%s (%s)\n", table_name, ui_name);
+  if ((prev_display_dissector_name == NULL) ||
+      (strcmp(prev_display_dissector_name, table_name) != 0)) {
+     fprintf((FILE *)output, "\t%s (%s)\n", table_name, ui_name);
+     prev_display_dissector_name = table_name;
+  }
 }
 
 /*
@@ -395,9 +400,13 @@ display_dissector_names(const gchar *table _U_, gpointer handle, gpointer output
     g_assert(proto_filter_name != NULL);
     g_assert(proto_ui_name != NULL);
 
-    fprintf((FILE *)output, "\t%s (%s)\n",
-            proto_filter_name,
-            proto_ui_name);
+    if ((prev_display_dissector_name == NULL) ||
+        (strcmp(prev_display_dissector_name, proto_filter_name) != 0)) {
+      fprintf((FILE *)output, "\t%s (%s)\n",
+              proto_filter_name,
+              proto_ui_name);
+       prev_display_dissector_name = proto_filter_name;
+    }
   }
 }
 
@@ -448,6 +457,16 @@ find_protocol_name_func(const gchar *table _U_, gpointer handle, gpointer user_d
   }
 }
 
+/*
+ * Allow dissector key names to be sorted alphabetically
+ */
+
+static gint
+compare_dissector_key_name(gconstpointer dissector_a, gconstpointer dissector_b)
+{
+  return strcmp((const char*)dissector_a, (const char*)dissector_b);
+}
+
 /*
  * Print all layer type names supported.
  * We send the output to the stream described by the handle output.
@@ -457,7 +476,8 @@ static void
 fprint_all_layer_types(FILE *output)
 
 {
-  dissector_all_tables_foreach_table(display_dissector_table_names, (gpointer)output);
+  prev_display_dissector_name = NULL;
+  dissector_all_tables_foreach_table(display_dissector_table_names, (gpointer)output, (GCompareFunc)compare_dissector_key_name);
 }
 
 /*
@@ -470,6 +490,7 @@ static void
 fprint_all_protocols_for_layer_types(FILE *output, gchar *table_name)
 
 {
+  prev_display_dissector_name = NULL;
   dissector_table_foreach_handle(table_name,
                                  display_dissector_names,
                                  (gpointer)output);
@@ -2542,7 +2563,7 @@ process_packet_first_pass(capture_file *cf,
       epan_dissect_prime_dfilter(&edt, cf->rfcode);
 
     frame_data_set_before_dissect(&fdlocal, &cf->elapsed_time,
-                                  &first_ts, &prev_dis_ts, &prev_cap_ts);
+                                  &first_ts, prev_dis, prev_cap);
 
     epan_dissect_run(&edt, pseudo_header, pd, &fdlocal, NULL);
 
@@ -2552,11 +2573,16 @@ process_packet_first_pass(capture_file *cf,
   }
 
   if (passed) {
-    frame_data_set_after_dissect(&fdlocal, &cum_bytes, &prev_dis_ts);
+    frame_data_set_after_dissect(&fdlocal, &cum_bytes);
+    prev_dis_frame = fdlocal;
+    prev_dis = &prev_dis_frame;
     frame_data_sequence_add(cf->frames, &fdlocal);
     cf->count++;
   }
 
+  prev_cap_frame = fdlocal;
+  prev_cap = &prev_cap_frame;
+
   if (do_dissection)
     epan_dissect_cleanup(&edt);
 
@@ -3077,7 +3103,7 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
       cinfo = NULL;
 
     frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
-                                  &first_ts, &prev_dis_ts, &prev_cap_ts);
+                                  &first_ts, prev_dis, prev_cap);
 
     epan_dissect_run(&edt, pseudo_header, pd, &fdata, cinfo);
 
@@ -3089,7 +3115,9 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
   }
 
   if (passed) {
-    frame_data_set_after_dissect(&fdata, &cum_bytes, &prev_dis_ts);
+    frame_data_set_after_dissect(&fdata, &cum_bytes);
+    prev_dis_frame = fdata;
+    prev_dis = &prev_dis_frame;
 
     /* Process this packet. */
     if (print_packet_info) {
@@ -3130,6 +3158,9 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
     }
   }
 
+  prev_cap_frame = fdata;
+  prev_cap = &prev_cap_frame;
+
   if (do_dissection) {
     epan_dissect_cleanup(&edt);
     frame_data_cleanup(&fdata);
@@ -3558,8 +3589,8 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
     cf->has_snap = TRUE;
   nstime_set_zero(&cf->elapsed_time);
   nstime_set_unset(&first_ts);
-  nstime_set_unset(&prev_dis_ts);
-  nstime_set_unset(&prev_cap_ts);
+  prev_dis = NULL;
+  prev_cap = NULL;
 
   cf->state = FILE_READ_IN_PROGRESS;