Add a question about whether hf_pn_rt_frag_data should be FT_STRING or FT_BYTES.
[metze/wireshark/wip.git] / summary.c
index e147d7053efeae1c44683a1997cae7eb09cf0fc7..dbec423b172ce6bee5aca781401e6ff18f6fd828 100644 (file)
--- a/summary.c
+++ b/summary.c
@@ -1,13 +1,12 @@
 /* summary.c
- * Routines for capture file summary window
+ * Routines for capture file summary info
  *
- * $Id: summary.c,v 1.6 1999/07/13 03:08:06 gram Exp $
+ * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "config.h"
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#include <gtk/gtk.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef NEED_SNPRINTF_H
-# ifdef HAVE_STDARG_H
-#  include <stdarg.h>
-# else
-#  include <varargs.h>
-# endif
-# include "snprintf.h"
-#endif
-
-#ifdef HAVE_SYS_SOCKIO_H
-# include <sys/sockio.h>
-#endif
+#include <wiretap/pcap-encap.h>
 
-#include "ethereal.h"
-#include "packet.h"
-#include "file.h"
-#include "menu.h"
+#include <epan/packet.h>
+#include "cfile.h"
 #include "summary.h"
-#include "capture.h"
-#include "etypes.h"
-#include "util.h"
-#include "prefs.h"
-
-extern capture_file  cf;
-
-/* File selection data keys */
-#define E_SUM_PREP_FS_KEY "sum_prep_fs"
-#define E_SUM_PREP_TE_KEY "sum_prep_te"
-
-/* Summary callback data keys */
-#define E_SUM_IFACE_KEY "sum_iface"
-#define E_SUM_FILT_KEY  "sum_filter"
-#define E_SUM_COUNT_KEY "sum_count"
-#define E_SUM_OPEN_KEY  "sum_open"
-#define E_SUM_SNAP_KEY  "sum_snap"
+#ifdef HAVE_LIBPCAP
+#include "capture_ui_utils.h"
+#endif
 
-#define SUM_STR_MAX 1024
 
-/* Summary filter key */
-#define E_SUM_FILT_TE_KEY "sum_filt_te"
+static void
+tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
+{
+  double cur_time;
 
-char * string_for_format(guint16 cd_t){
-  switch (cd_t) {
-  case WTAP_FILE_WTAP:
-    return "wiretap";
-  case WTAP_FILE_PCAP:
-    return "pcap";
-  case WTAP_FILE_LANALYZER:
-    return "LanAlyzer";
-  case WTAP_FILE_NGSNIFFER:
-    return "Sniffer";
-  case WTAP_FILE_SNOOP:
-    return "snoop";
-  case WTAP_FILE_IPTRACE:
-    return "iptrace";
-  case WTAP_FILE_NETMON:
-    return "Network Monitor";
-  case WTAP_FILE_NETXRAY:
-    return "NetXray/Sniffer Pro";
-  default:
-    return "unknown";
+  sum_tally->bytes += cur_frame->pkt_len;
+  if (cur_frame->flags.passed_dfilter){
+    sum_tally->filtered_count++;
+    sum_tally->filtered_bytes += cur_frame->pkt_len;
+  }
+  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++;
   }
-}
-
-double
-secs_usecs( guint32 s, guint32 us) {
-  return (us / 1000000.0) + (double)s;
-}
 
-void
-tally_frame_data(gpointer cf, gpointer st) {
-  double cur_time;
-  summary_tally * sum_tally = (summary_tally *)st;
-  frame_data *cur_frame = (frame_data *)cf;
+  if (cur_frame->flags.has_ts) {
+    /* This packet has a time stamp. */
+    cur_time = nstime_to_sec(&cur_frame->abs_ts);
 
-  cur_time = secs_usecs(cur_frame->abs_secs, cur_frame->abs_usecs);
+    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;
+      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;
+        }
+      }
+    }
   }
-  sum_tally->bytes += cur_frame->pkt_len;
-  if (cur_frame->passed_dfilter)
-         sum_tally->filtered_count++;
-}
-
-void
-add_string_to_box(gchar *str, GtkWidget *box) {
-  GtkWidget *lb;
-  lb = gtk_label_new(str);
-  gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
-  gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
-  gtk_widget_show(lb);
 }
 
 void
-summary_prep_cb(GtkWidget *w, gpointer d) {
+summary_fill_in(capture_file *cf, summary_tally *st)
+{
   frame_data    *first_frame, *cur_frame;
-  summary_tally *st;
-  GtkWidget     *sum_open_w,
-                *main_vb, *file_fr, *data_fr, *capture_fr, *file_box, 
-*data_box,
-                *capture_box;
-
- gchar          string_buff[SUM_STR_MAX];
-
- guint32        traffic_bytes, i;
- double         seconds;
- GList          *cur_glist;
-
- /* initialize the tally */
-  first_frame = (frame_data *)(cf.plist->data);
-  st = (summary_tally *)g_malloc(sizeof(summary_tally));
-  st->start_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs) 
-;
-  st->stop_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs) 
-;
+  guint32        framenum;
+  wtapng_section_t* shb_inf;
+  iface_options iface;
+  guint i;
+  wtapng_iface_descriptions_t* idb_info;
+  wtapng_if_descr_t wtapng_if_descr;
+  wtapng_if_stats_t *if_stats;
+
+  st->packet_count_ts = 0;
+  st->start_time = 0;
+  st->stop_time = 0;
   st->bytes = 0;
   st->filtered_count = 0;
-  cur_glist = cf.plist;
-
-  for (i = 0; i < cf.count; i++){
-    cur_frame = (frame_data *)cur_glist->data;
-    tally_frame_data(cur_frame, st);
-    cur_glist = cur_glist->next;
+  st->filtered_count_ts = 0;
+  st->filtered_start = 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->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);
+
+    for (framenum = 1; framenum <= cf->count; framenum++) {
+      cur_frame = frame_data_sequence_find(cf->frames, framenum);
+      tally_frame_data(cur_frame, st);
     }
-
-  /*  g_list_foreach(cf.plist_first, (GFunc)tally_frame_data, st); */
-
-  /* traffic_bytes will be computed here */
-  traffic_bytes = st->bytes;
-  seconds = st->stop_time - st->start_time;
-  sum_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  gtk_window_set_title(GTK_WINDOW(sum_open_w), "Ethereal: Summary");
-
-  /* Container for each row of widgets */
-  main_vb = gtk_vbox_new(FALSE, 3);
-  gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
-  gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
-  gtk_widget_show(main_vb);
-
-  /* File frame */
-  file_fr = gtk_frame_new("File");
-  gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
-  gtk_widget_show(file_fr);
-
-  file_box = gtk_vbox_new(FALSE, 3);
-  gtk_container_add(GTK_CONTAINER(file_fr), file_box);
-  gtk_widget_show(file_box);
-
-  /* filename */
-  snprintf(string_buff, SUM_STR_MAX, "Name: %s", cf.filename);
-  add_string_to_box(string_buff, file_box);
-
-  /* length */
-  snprintf(string_buff, SUM_STR_MAX, "Length: %lu", cf.f_len);
-  add_string_to_box(string_buff, file_box);
-
-  /* format */
-  snprintf(string_buff, SUM_STR_MAX, "Format: %s", 
-string_for_format(cf.cd_t));
-  add_string_to_box(string_buff, file_box);
-
-  /* Data frame */
-  data_fr = gtk_frame_new("Data");
-  gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
-  gtk_widget_show(data_fr);
-
-  data_box = gtk_vbox_new(FALSE, 3);
-  gtk_container_add(GTK_CONTAINER(data_fr), data_box);
-  gtk_widget_show(data_box);
-
-  /* seconds */
-  snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", 
-secs_usecs(cf.esec,cf.eusec));
-  add_string_to_box(string_buff, data_box);
-
-  snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
-  add_string_to_box(string_buff, data_box);
-
-  /* Packet count */
-  snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", cf.count);
-  add_string_to_box(string_buff, data_box);
-
-  /* Filtered Packet count */
-  snprintf(string_buff, SUM_STR_MAX, "Filtered packet count: %i", st->filtered_count);
-  add_string_to_box(string_buff, data_box);
-
-  /* Packets per second */
-  if (seconds > 0){
-    snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f", 
-cf.count/seconds);
-    add_string_to_box(string_buff, data_box);
   }
 
-  /* Dropped count */
-  snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %i", cf.drops);
-  add_string_to_box(string_buff, data_box);
-
-  /* Byte count */
-  snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d", 
-traffic_bytes);
-  add_string_to_box(string_buff, data_box);
-
-  /* Bytes per second */
-  if (seconds > 0){
-    snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f", 
-traffic_bytes/seconds);
-    add_string_to_box(string_buff, data_box);
+  st->filename = cf->filename;
+  st->file_length = cf->f_datalen;
+  st->file_type = cf->cd_t;
+  st->iscompressed = cf->iscompressed;
+  st->is_tempfile = cf->is_tempfile;
+  st->file_encap_type = cf->lnk_t;
+  st->packet_encap_types = cf->linktypes;
+  st->has_snap = cf->has_snap;
+  st->snap = cf->snap;
+  st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
+  st->packet_count = cf->count;
+  st->drops_known = cf->drops_known;
+  st->drops = cf->drops;
+  st->dfilter = cf->dfilter;
+
+  /* Get info from SHB */
+  shb_inf = wtap_file_get_shb_info(cf->wth);
+  if(shb_inf == NULL){
+    st->opt_comment    = NULL;
+    st->shb_hardware   = NULL;
+    st->shb_os         = NULL;
+    st->shb_user_appl  = NULL;
+  }else{
+    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);
   }
 
-  /* Capture frame */
-  capture_fr = gtk_frame_new("Capture");
-  gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
-  gtk_widget_show(capture_fr);
-
-  capture_box = gtk_vbox_new(FALSE, 3);
-  gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
-  gtk_widget_show(capture_box);
-
-
-  /* interface */
-  if (cf.iface) {
-    snprintf(string_buff, SUM_STR_MAX, "Interface: %s", cf.iface);
-  } else {
-    sprintf(string_buff, "Interface: unknown");
-  }
-  add_string_to_box(string_buff, capture_box);
-
-  /* Display filter. The situation where cf.dfilter="" and cf.dfcode=NULL can exist,
-       so I'll check for both */
-  if (cf.dfilter && cf.dfcode) {
-    snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", cf.dfilter);
-  } else {
-    sprintf(string_buff, "Display filter: none");
+  st->ifaces  = g_array_new(FALSE, FALSE, sizeof(iface_options));
+  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_str);
+    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.encap_type = wtapng_if_descr.wtap_encap;
+    if(wtapng_if_descr.num_stat_entries == 1){
+      /* dumpcap only writes one ISB, only handle that for now */
+      if_stats = &g_array_index(wtapng_if_descr.interface_statistics, wtapng_if_stats_t, 0);
+      iface.drops_known = TRUE;
+      iface.drops = if_stats->isb_ifdrop;
+      iface.isb_comment = if_stats->opt_comment;
+    }
+    g_array_append_val(st->ifaces, iface);
   }
-  add_string_to_box(string_buff, capture_box);
+  g_free(idb_info);
+}
 
 #ifdef HAVE_LIBPCAP
-  /* Capture filter */
-  if (cf.cfilter) {
-    snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", cf.cfilter);
-  } else {
-    sprintf(string_buff, "Capture filter: none");
+void
+summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
+{
+  iface_options iface;
+  interface_t device;
+  guint i;
+
+  if (st->ifaces->len == 0) {
+    /*
+     * XXX - do this only if we have a live capture.
+     */
+    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.encap_type = wtap_pcap_encap_to_wtap_encap(device.active_dlt);
+      g_array_append_val(st->ifaces, iface);
+    }
   }
-  add_string_to_box(string_buff, capture_box);
-#endif
-
-  gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
-  gtk_widget_show(sum_open_w);
 }
-
-/* this is never called 
-void
-summary_prep_close_cb(GtkWidget *w, gpointer win) {
-
-  gtk_grab_remove(GTK_WIDGET(win));
-  gtk_widget_destroy(GTK_WIDGET(win));
-} */
+#endif