aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Tüxen <tuexen@fh-muenster.de>2011-07-05 20:34:03 +0000
committerMichael Tüxen <tuexen@fh-muenster.de>2011-07-05 20:34:03 +0000
commitcb90aa79043d162d3a2955cc0c66fd714948f19f (patch)
tree8ff2ea83f9ec58cab18c991d440b80a01de4cfc7
parent4b8f5a1865053f7318467389df23fefa43d14148 (diff)
Add initial support for multiple interfaces. More to come after
the capture options dialog box supports also multiple interfaces. This patch has been developed by Irene Ruengeler. svn path=/trunk/; revision=37904
-rw-r--r--gtk/summary_dlg.c112
-rw-r--r--summary.c34
-rw-r--r--summary.h16
3 files changed, 120 insertions, 42 deletions
diff --git a/gtk/summary_dlg.c b/gtk/summary_dlg.c
index 192ef3e..c57936c 100644
--- a/gtk/summary_dlg.c
+++ b/gtk/summary_dlg.c
@@ -41,6 +41,7 @@
#include "../globals.h"
#include "../file.h"
#include "../summary.h"
+#include "../capture-pcap-util.h"
#ifdef HAVE_LIBPCAP
#include "../capture.h"
#include "gtk/main.h"
@@ -52,7 +53,6 @@
#include "gtk/gui_utils.h"
#include "gtk/help_dlg.h"
-
#define SUM_STR_MAX 1024
#define FILTER_SNIP_LEN 50
@@ -106,13 +106,19 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
summary_tally summary;
GtkWidget *sum_open_w,
*main_vb, *bbox, *close_bt, *help_bt;
- GtkWidget *table;
- GtkWidget *list;
+ GtkWidget *table, *scrolled_window;
+ GtkWidget *list, *treeview;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
static const char *titles[] = { "Traffic", "Captured", "Displayed", "Marked" };
gchar string_buff[SUM_STR_MAX];
gchar string_buff2[SUM_STR_MAX];
gchar string_buff3[SUM_STR_MAX];
+ gchar string_buff4[SUM_STR_MAX];
+ gchar string_buff5[SUM_STR_MAX];
double seconds;
double disp_seconds;
@@ -126,6 +132,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
time_t ti_time;
struct tm *ti_tm;
unsigned int elapsed_time;
+ iface_options iface;
+ unsigned int i;
/* initial computations */
summary_fill_in(&cfile, &summary);
@@ -221,37 +229,81 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
/* Capture */
add_string_to_table(table, &row, "", "");
- add_string_to_table_sensitive(table, &row, "Capture", "", (summary.iface != NULL));
-
- /* interface */
- if (summary.iface) {
- g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.iface_descr);
- } else {
- g_snprintf(string_buff, SUM_STR_MAX, "unknown");
- }
- add_string_to_table_sensitive(table, &row, "Interface:", string_buff, (summary.iface) != NULL);
-
- /* Dropped count */
- if (summary.drops_known) {
- g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.drops);
- } else {
- g_snprintf(string_buff, SUM_STR_MAX, "unknown");
- }
- add_string_to_table_sensitive(table, &row, "Dropped packets:", string_buff, (summary.iface != NULL));
-
-#ifdef HAVE_LIBPCAP
- /* Capture filter */
- if (summary.cfilter && summary.cfilter[0] != '\0') {
- g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.cfilter);
- } else {
- if(summary.iface) {
- g_snprintf(string_buff, SUM_STR_MAX, "none");
+ add_string_to_table_sensitive(table, &row, "Capture", "", (global_capture_opts.ifaces->len>0));
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 5);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_widget_set_size_request(scrolled_window, -1, 120);
+
+ treeview = gtk_tree_view_new();
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes("Interface", renderer, "text", 0, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes("Dropped Packets", renderer, "text", 1, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes("Capture Filter", renderer, "text", 2, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes("Link type", renderer, "text", 3, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes("Packet size limit", renderer, "text", 4, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ for (i = 0; i < summary.ifaces->len; i++) {
+ iface = g_array_index(summary.ifaces, iface_options, i);
+ /* interface */
+ if (iface.descr) {
+ g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.descr);
+ } else if (iface.name) {
+ g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.name);
} else {
g_snprintf(string_buff, SUM_STR_MAX, "unknown");
}
- }
- add_string_to_table_sensitive(table, &row, "Capture filter:", string_buff, (summary.iface != NULL));
+ /* Dropped count */
+ if (iface.drops_known) {
+ g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", iface.drops);
+ } else {
+ g_snprintf(string_buff2, SUM_STR_MAX, "unknown");
+ }
+#ifdef HAVE_LIBPCAP
+ /* Capture filter */
+ if (iface.cfilter && iface.cfilter[0] != '\0') {
+ g_snprintf(string_buff3, SUM_STR_MAX, "%s", iface.cfilter);
+ } else {
+ if(iface.name) {
+ g_snprintf(string_buff3, SUM_STR_MAX, "none");
+ } else {
+ g_snprintf(string_buff3, SUM_STR_MAX, "unknown");
+ }
+ }
#endif
+ g_snprintf(string_buff4, SUM_STR_MAX, "%s", pcap_datalink_val_to_description(iface.linktype));
+ if (strcmp(string_buff4, "(null)") == 0) {
+ strcpy(string_buff4, "unknown");
+ }
+ if (iface.has_snap) {
+ g_snprintf(string_buff5, SUM_STR_MAX, "%u bytes", iface.snap);
+ } else {
+ g_snprintf(string_buff5, SUM_STR_MAX, "unknown");
+ }
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter, 0, string_buff, 1, string_buff2, 2, string_buff3, 3, string_buff4, 4, string_buff5,-1);
+ }
+ gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
+ g_object_unref (store);
+ gtk_container_add(GTK_CONTAINER(scrolled_window), treeview);
+ gtk_container_add(GTK_CONTAINER(main_vb),scrolled_window);
+ gtk_widget_show_all (scrolled_window);
+ table = gtk_table_new(1, 2, FALSE);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 6);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 3);
+ gtk_container_add(GTK_CONTAINER(main_vb), table);
+ row = 0;
/* Data */
diff --git a/summary.c b/summary.c
index 6e30bab..8f419f8 100644
--- a/summary.c
+++ b/summary.c
@@ -131,22 +131,38 @@ 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;
+ st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options));
}
#ifdef HAVE_LIBPCAP
-/* FIXME: This needs additional functionality to support multiple interfaces */
void
summary_fill_in_capture(capture_options *capture_opts, summary_tally *st)
{
+ iface_options iface;
+ interface_options interface_opts;
+ guint i;
+
if (capture_opts->ifaces->len > 0) {
- st->cfilter = g_array_index(capture_opts->ifaces, interface_options, 0).cfilter;
- st->iface = g_array_index(capture_opts->ifaces, interface_options, 0).name;
- st->iface_descr = get_iface_description_for_interface(capture_opts, 0);
- }
+ 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);
+ }
+ for (i = 0; i < capture_opts->ifaces->len; i++) {
+ interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
+ iface.cfilter = g_strdup(interface_opts.cfilter);
+ iface.name = g_strdup(interface_opts.name);
+ iface.descr = g_strdup(interface_opts.descr);
+ iface.drops_known = FALSE;
+ iface.drops = 0;
+ iface.has_snap = interface_opts.has_snaplen;
+ iface.snap = interface_opts.snaplen;
+ iface.linktype = interface_opts.linktype;
+ g_array_append_val(st->ifaces, iface);
+ }
+ }
}
#endif
diff --git a/summary.h b/summary.h
index ef32e7b..a21de3a 100644
--- a/summary.h
+++ b/summary.h
@@ -29,6 +29,17 @@
#include "capture.h"
#endif
+typedef struct iface_options_tag {
+ char *name;
+ char *descr;
+ char *cfilter;
+ guint64 drops; /* number of packet drops */
+ gboolean drops_known; /* TRUE if number of packet drops is known */
+ gboolean has_snap; /* TRUE if maximum capture packet length is known */
+ int snap; /* Maximum captured packet length */
+ int linktype; /* wiretap encapsulation type */
+} iface_options;
+
typedef struct _summary_tally {
guint64 bytes; /* total bytes */
double start_time; /* seconds, with msec resolution */
@@ -57,9 +68,8 @@ typedef struct _summary_tally {
const char *dfilter; /* display filter */
/* capture related, use summary_fill_in_capture() to get values */
- const char *cfilter; /* capture filter */
- const char *iface; /* interface name */
- const char *iface_descr;/* descriptive interface name */
+ GArray *ifaces;
+ gboolean legacy;
} summary_tally;
extern void