/* capture_info_dlg.c
* Routines for packet capture info dialog
*
- * $Id: capture_info_dlg.c,v 1.8 2003/12/21 12:17:59 ulfl Exp $
+ * $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * 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
# include "config.h"
#endif
+#include <string.h>
+
#ifdef HAVE_LIBPCAP
-#include <pcap.h>
#include <gtk/gtk.h>
#include "gtk/compat_macros.h"
#include <time.h>
#include <epan/packet.h>
-#include "../capture.h"
+#include "capture.h"
+#include "capture_info.h"
#include "globals.h"
-#include "capture_combo_utils.h"
+#include "capture_ui_utils.h"
#include "dlg_utils.h"
+#include "gui_utils.h"
+#include "main.h"
+#include "capture-pcap-util.h"
+#include "help_dlg.h"
+
+#ifdef HAVE_AIRPCAP
+#include <airpcap.h>
+#include "airpcap_loader.h"
+#include "airpcap_gui_utils.h"
+#include "airpcap_dlg.h"
+#endif
+
/* a single capture counter value (with title, pointer to value and GtkWidgets) */
/* as the packet_counts is a struct, not an array, keep a pointer to the */
typedef struct {
GtkWidget *cap_w;
GtkWidget *running_time_lb;
- capture_info_counts_t counts[CAPTURE_PACKET_COUNTS];
+ capture_info_counts_t counts[PACKET_COUNTS_SIZE];
+ guint timer_id;
+ time_t start_time;
} capture_info_ui_t;
}
}
-/* stop button (or ESC key) was pressed */
-static void
-capture_info_stop_cb(GtkWidget *w _U_, gpointer data) {
- capture_ui_stop_callback(data);
+static gboolean
+capture_info_delete_cb(GtkWidget *w _U_, GdkEvent *event _U_, gpointer data _U_) {
+#ifdef HAVE_AIRPCAP
+ airpcap_set_toolbar_stop_capture(airpcap_if_active);
+#endif
+
+ capture_stop(capture_opts);
+ return TRUE;
}
+static gint
+capture_info_ui_update_cb(gpointer data)
+{
+ capture_info *cinfo = data;
+ capture_info_ui_t *info = cinfo->ui;
-static void
-capture_info_delete_cb(GtkWidget *w _U_, GdkEvent *event _U_, gpointer data) {
- capture_ui_stop_callback(data);
+ cinfo->running_time = time(NULL) - info->start_time;
+ capture_info_ui_update(cinfo);
+ return 1; /* call the timer again */
}
/* create the capture info dialog */
/* will keep pointers to the fields in the counts parameter */
-void capture_info_create(
-capture_info *cinfo)
+void capture_info_ui_create(
+capture_info *cinfo,
+const gchar *iface)
{
unsigned int i;
GtkWidget *main_vb, *stop_bt, *counts_tb;
- GtkWidget *counts_fr, *running_tb, *running_label;
+ GtkWidget *counts_fr, *running_tb, *running_label, *bbox, *ci_help;
capture_info_ui_t *info;
+ gchar *cap_w_title;
+ gchar *title_iface;
+ gchar *descr;
+ GtkTooltips *tooltips;
+
+ tooltips = gtk_tooltips_new ();
info = g_malloc0(sizeof(capture_info_ui_t));
info->counts[0].title = "Total";
info->counts[11].title = "Other";
info->counts[11].value_ptr = &(cinfo->counts->other);
- info->cap_w = dlg_window_new("Ethereal: Capture");
- gtk_window_set_modal(GTK_WINDOW(info->cap_w), TRUE);
+ /*
+ * Create the dialog window, with a title that includes the interface.
+ *
+ * If we have a descriptive name for the interface, show that,
+ * rather than its raw name. On NT 5.x (2K/XP/Server2K3), the
+ * interface name is something like "\Device\NPF_{242423..."
+ * which is pretty useless to the normal user. On other platforms,
+ * it might be less cryptic, but if a more descriptive name is
+ * available, we should still use that.
+ */
+ descr = get_interface_descriptive_name(iface);
+ title_iface = g_strdup_printf("Wireshark: Capture from %s", descr);
+ g_free(descr);
+ cap_w_title = create_user_window_title(title_iface);
+ g_free(title_iface);
+ info->cap_w = dlg_window_new(cap_w_title);
+ g_free(cap_w_title);
/* Container for capture display widgets */
main_vb = gtk_vbox_new(FALSE, 1);
gtk_widget_show(counts_fr);
/* Individual statistic elements */
- counts_tb = gtk_table_new(CAPTURE_PACKET_COUNTS, 4, TRUE);
+ counts_tb = gtk_table_new(PACKET_COUNTS_SIZE, 4, TRUE);
gtk_container_add(GTK_CONTAINER(counts_fr), counts_tb);
gtk_container_border_width(GTK_CONTAINER(counts_tb), 5);
gtk_widget_show(counts_tb);
gtk_table_set_row_spacings(GTK_TABLE(counts_tb), 0);
gtk_table_set_col_spacings(GTK_TABLE(counts_tb), 5);
- for (i = 0; i < CAPTURE_PACKET_COUNTS; i++) {
+ for (i = 0; i < PACKET_COUNTS_SIZE; i++) {
info->counts[i].label = gtk_label_new(info->counts[i].title);
gtk_misc_set_alignment(GTK_MISC(info->counts[i].label), 0.0f, 0.5f);
/* allow user to either click a stop button, or the close button on
the window to stop a capture in progress. */
-#if GTK_MAJOR_VERSION < 2
- stop_bt = gtk_button_new_with_label ("Stop");
-#else
- stop_bt = gtk_button_new_from_stock(GTK_STOCK_STOP);
-#endif
- SIGNAL_CONNECT(stop_bt, "clicked", capture_info_stop_cb,
- cinfo->callback_data);
+ if(topic_available(HELP_CAPTURE_INFO_DIALOG)) {
+ bbox = dlg_button_row_new(WIRESHARK_STOCK_CAPTURE_STOP, GTK_STOCK_HELP, NULL);
+ } else{
+ bbox = dlg_button_row_new(WIRESHARK_STOCK_CAPTURE_STOP, NULL);
+ }
+ gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
+ gtk_widget_show(bbox);
+
+ stop_bt = OBJECT_GET_DATA(bbox, WIRESHARK_STOCK_CAPTURE_STOP);
+ window_set_cancel_button(info->cap_w, stop_bt, NULL);
+ SIGNAL_CONNECT(stop_bt, "clicked", capture_info_delete_cb, capture_opts);
+
SIGNAL_CONNECT(info->cap_w, "delete_event", capture_info_delete_cb,
- cinfo->callback_data);
- gtk_box_pack_start(GTK_BOX(main_vb), stop_bt, FALSE, FALSE, 3);
- GTK_WIDGET_SET_FLAGS(stop_bt, GTK_CAN_DEFAULT);
- gtk_widget_grab_default(stop_bt);
- GTK_WIDGET_SET_FLAGS(stop_bt, GTK_CAN_DEFAULT);
- gtk_widget_grab_default(stop_bt);
- gtk_widget_show(stop_bt);
-
- /* Catch the "key_press_event" signal in the window, so that we can catch
- the ESC key being pressed and act as if the "Stop" button had
- been selected. */
- dlg_set_cancel(info->cap_w, stop_bt);
+ capture_opts);
+
+ if(topic_available(HELP_CAPTURE_INFO_DIALOG)) {
+ ci_help = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
+ gtk_tooltips_set_tip (tooltips, ci_help, ("Get help about this dialog"), NULL);
+ SIGNAL_CONNECT(ci_help, "clicked", topic_cb, HELP_CAPTURE_INFO_DIALOG);
+ }
gtk_widget_show(info->cap_w);
+ window_present(info->cap_w);
+
+ info->start_time = time(NULL);
cinfo->ui = info;
+
+ /* update the dialog once a second, even if no packets rushing in */
+ info->timer_id = gtk_timeout_add(1000, (GtkFunction)capture_info_ui_update_cb,(gpointer)cinfo);
}
/* update the capture info dialog */
/* As this function is a bit time critical while capturing, */
-/* prepare everything possible in the capture_info_create() function above! */
-void capture_info_update(
+/* prepare everything possible in the capture_info_ui_create() function above! */
+void capture_info_ui_update(
capture_info *cinfo)
{
unsigned int i;
capture_info_ui_t *info = cinfo->ui;
- /* calculate and display running time */
- snprintf(label_str, sizeof(label_str), "%02ld:%02ld:%02ld",
+ /* display running time */
+ g_snprintf(label_str, sizeof(label_str), "%02ld:%02ld:%02ld",
(long)(cinfo->running_time/3600), (long)((cinfo->running_time%3600)/60),
(long)(cinfo->running_time%60));
gtk_label_set(GTK_LABEL(info->running_time_lb), label_str);
+ /* if we have new packets, update all rows */
if (cinfo->new_packets) {
- for (i = 0; i < CAPTURE_PACKET_COUNTS; i++) {
- snprintf(label_str, sizeof(label_str), "%d",
+ for (i = 0; i < PACKET_COUNTS_SIZE; i++) {
+ g_snprintf(label_str, sizeof(label_str), "%d",
*info->counts[i].value_ptr);
gtk_label_set(GTK_LABEL(info->counts[i].value_lb), label_str);
/* don't try to update the "total" row progress bar */
if (i != 0) {
gtk_progress_bar_update(GTK_PROGRESS_BAR(info->counts[i].percent_pb),
- pct(*info->counts[i].value_ptr, *info->counts[0].value_ptr) / 100.0);
+ (gfloat) (pct(*info->counts[i].value_ptr, *info->counts[0].value_ptr) / 100.0));
}
g_snprintf(label_str, sizeof(label_str), "%.1f%%",
/* destroy the capture info dialog again */
-void capture_info_destroy(
+void capture_info_ui_destroy(
capture_info *cinfo)
{
capture_info_ui_t *info = cinfo->ui;
+ gtk_timeout_remove(info->timer_id);
+
+ /* called from capture engine, so it's ok to destroy the dialog here */
gtk_grab_remove(GTK_WIDGET(info->cap_w));
- gtk_widget_destroy(GTK_WIDGET(info->cap_w));
+ window_destroy(GTK_WIDGET(info->cap_w));
g_free(info);
}