Make it possible to edit capture comments
[metze/wireshark/wip.git] / summary.c
index 0ac1b8a5f168ee92613b8157c44b746055045dd7..bc4df8a2fcd84e2805907b9435549e78876ee29d 100644 (file)
--- a/summary.c
+++ b/summary.c
 # include "config.h"
 #endif
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
 #include <epan/packet.h>
 #include "cfile.h"
 #include "summary.h"
@@ -39,33 +43,67 @@ tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
 {
   double cur_time;
 
-  cur_time = nstime_to_sec(&cur_frame->abs_ts);
-
-  if (cur_time < sum_tally->start_time) {
-    sum_tally->start_time = cur_time;
-  }
-  if (cur_time > sum_tally->stop_time){
-    sum_tally->stop_time = cur_time;
-  }
   sum_tally->bytes += cur_frame->pkt_len;
   if (cur_frame->flags.passed_dfilter){
-    if (sum_tally->filtered_count==0){
-           sum_tally->filtered_start= cur_time;
-           sum_tally->filtered_stop = cur_time;
-    } else {
-           if (cur_time < sum_tally->filtered_start) {
-                   sum_tally->start_time = cur_time;
-           }
-           if (cur_time > sum_tally->filtered_stop) {
-                   sum_tally->filtered_stop = cur_time;
-           }
-    }
     sum_tally->filtered_count++;
-    sum_tally->filtered_bytes += cur_frame->pkt_len ;
+    sum_tally->filtered_bytes += cur_frame->pkt_len;
   }
-  if (cur_frame->flags.marked)
+  if (cur_frame->flags.marked){
     sum_tally->marked_count++;
+    sum_tally->marked_bytes += cur_frame->pkt_len;
+  }
+  if (cur_frame->flags.ignored){
+    sum_tally->ignored_count++;
+  }
+
+  if (cur_frame->flags.has_ts) {
+    /* This packet has a time stamp. */
+    cur_time = nstime_to_sec(&cur_frame->abs_ts);
 
+    sum_tally->packet_count_ts++;
+    if (cur_time < sum_tally->start_time) {
+      sum_tally->start_time = cur_time;
+    }
+    if (cur_time > sum_tally->stop_time){
+      sum_tally->stop_time = cur_time;
+    }
+    if (cur_frame->flags.passed_dfilter){
+      sum_tally->filtered_count_ts++;
+      /*
+       * If we've seen one filtered packet, this is the first
+       * one.
+       */
+      if (sum_tally->filtered_count == 1){
+        sum_tally->filtered_start= cur_time;
+        sum_tally->filtered_stop = cur_time;
+      } else {
+        if (cur_time < sum_tally->filtered_start) {
+          sum_tally->filtered_start = cur_time;
+        }
+        if (cur_time > sum_tally->filtered_stop) {
+          sum_tally->filtered_stop = cur_time;
+        }
+      }
+    }
+    if (cur_frame->flags.marked){
+      sum_tally->marked_count_ts++;
+      /*
+       * If we've seen one marked packet, this is the first
+       * one.
+       */
+      if (sum_tally->marked_count == 1){
+        sum_tally->marked_start= cur_time;
+        sum_tally->marked_stop = cur_time;
+      } else {
+        if (cur_time < sum_tally->marked_start) {
+          sum_tally->marked_start = cur_time;
+        }
+        if (cur_time > sum_tally->marked_stop) {
+          sum_tally->marked_stop = cur_time;
+        }
+      }
+    }
+  }
 }
 
 void
@@ -73,35 +111,42 @@ summary_fill_in(capture_file *cf, summary_tally *st)
 {
 
   frame_data    *first_frame, *cur_frame;
-  int          i;
-  frame_data    *cur_glist;
+  guint32        framenum;
+  wtapng_section_t* shb_inf;
 
+  st->packet_count_ts = 0;
   st->start_time = 0;
   st->stop_time = 0;
   st->bytes = 0;
   st->filtered_count = 0;
+  st->filtered_count_ts = 0;
   st->filtered_start = 0;
-  st->filtered_stop   = 0;
+  st->filtered_stop = 0;
   st->filtered_bytes = 0;
   st->marked_count = 0;
+  st->marked_count_ts = 0;
+  st->marked_start = 0;
+  st->marked_stop = 0;
+  st->marked_bytes = 0;
+  st->ignored_count = 0;
 
   /* initialize the tally */
-  if (cf->plist != NULL) {
-    first_frame = cf->plist;
-    st->start_time     = nstime_to_sec(&first_frame->abs_ts);
+  if (cf->count != 0) {
+    first_frame = frame_data_sequence_find(cf->frames, 1);
+    st->start_time = nstime_to_sec(&first_frame->abs_ts);
     st->stop_time = nstime_to_sec(&first_frame->abs_ts);
-    cur_glist = cf->plist;
 
-    for (i = 0; i < cf->count; i++) {
-      cur_frame = cur_glist;
+    for (framenum = 1; framenum <= cf->count; framenum++) {
+      cur_frame = frame_data_sequence_find(cf->frames, framenum);
       tally_frame_data(cur_frame, st);
-      cur_glist = cur_glist->next;
     }
   }
 
   st->filename = cf->filename;
   st->file_length = cf->f_datalen;
-  st->encap_type = cf->cd_t;
+  st->file_type = cf->cd_t;
+  st->is_tempfile = cf->is_tempfile;
+  st->encap_type = cf->lnk_t;
   st->has_snap = cf->has_snap;
   st->snap = cf->snap;
   st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
@@ -110,19 +155,77 @@ summary_fill_in(capture_file *cf, summary_tally *st)
   st->drops = cf->drops;
   st->dfilter = cf->dfilter;
 
-  /* capture related */
-  st->cfilter = NULL;
-  st->iface = NULL;
-  st->iface_descr = NULL;
+  /* Get info from SHB */
+  shb_inf = wtap_file_get_shb_info(cf->wth);
+
+  shb_inf = wtap_file_get_shb_info(cf->wth);
+  st->opt_comment    = shb_inf->opt_comment;
+  st->shb_hardware   = shb_inf->shb_hardware;
+  st->shb_os         = shb_inf->shb_os;
+  st->shb_user_appl  = shb_inf->shb_user_appl;
+  g_free(shb_inf);
+
+  st->ifaces  = g_array_new(FALSE, FALSE, sizeof(iface_options));
 }
 
 
 #ifdef HAVE_LIBPCAP
 void
-summary_fill_in_capture(capture_options *capture_opts, summary_tally *st)
+summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
 {
-  st->cfilter = capture_opts->cfilter;
-  st->iface = capture_opts->iface;
-  st->iface_descr = get_iface_description(capture_opts);
+  iface_options iface;
+  interface_t device;
+  guint i;
+  wtapng_iface_descriptions_t* idb_info;
+  wtapng_if_descr_t wtapng_if_descr;
+
+  while (st->ifaces->len > 0) {
+    iface = g_array_index(st->ifaces, iface_options, 0);
+    st->ifaces = g_array_remove_index(st->ifaces, 0);
+    g_free(iface.name);
+    g_free(iface.descr);
+    g_free(iface.cfilter);
+  }
+  if (st->is_tempfile) {
+    for (i = 0; i < capture_opts->all_ifaces->len; i++) {
+      device = g_array_index(capture_opts->all_ifaces, interface_t, i);
+      if (!device.selected) {
+        continue;
+      }
+      iface.cfilter = g_strdup(device.cfilter);
+      iface.name = g_strdup(device.name);
+      iface.descr = g_strdup(device.display_name);
+      iface.drops_known = cf->drops_known;
+      iface.drops = cf->drops;
+      iface.has_snap = device.has_snaplen;
+      iface.snap = device.snaplen;
+      iface.linktype = device.active_dlt;
+      g_array_append_val(st->ifaces, iface);
+    }
+  } else {
+    idb_info = wtap_file_get_idb_info(cf->wth);
+    for (i = 0; i < idb_info->number_of_interfaces; i++) {
+      wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i);
+      iface.cfilter = g_strdup(wtapng_if_descr.if_filter);
+      iface.name = g_strdup(wtapng_if_descr.if_name);
+      iface.descr = g_strdup(wtapng_if_descr.if_description);
+      iface.drops_known = FALSE;
+      iface.drops = 0;
+      iface.snap = wtapng_if_descr.snap_len;
+      iface.has_snap = (iface.snap != 65535);
+      iface.linktype = wtapng_if_descr.link_type;
+      g_array_append_val(st->ifaces, iface);
+    }
+    g_free(idb_info);
+  }
 }
 #endif
+
+void
+summary_update_comment(capture_file *cf, gchar *comment)
+{
+
+  /* Get info from SHB */
+  wtap_write_shb_comment(cf->wth, comment);
+
+}
\ No newline at end of file