2004-07-18 00:24:25 +00:00
|
|
|
/* capture_if_dlg.c
|
|
|
|
* Routines for the capture interface dialog
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2004-07-18 00:24:25 +00:00
|
|
|
* 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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
# include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "globals.h"
|
2005-12-06 00:07:13 +00:00
|
|
|
#include "capture-pcap-util.h"
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "capture-wpcap.h"
|
|
|
|
#endif
|
|
|
|
|
2008-04-12 00:49:20 +00:00
|
|
|
#include "stock_icons.h"
|
2004-07-18 00:24:25 +00:00
|
|
|
#include "simple_dialog.h"
|
2004-12-29 09:09:35 +00:00
|
|
|
#include "capture.h"
|
2004-07-18 00:24:25 +00:00
|
|
|
#include "capture_dlg.h"
|
2005-05-20 22:23:00 +00:00
|
|
|
#include "capture_if_details_dlg.h"
|
2005-10-04 06:25:01 +00:00
|
|
|
#include "capture_errs.h"
|
2007-08-22 16:30:16 +00:00
|
|
|
#include "capture_ui_utils.h"
|
2006-08-16 18:01:25 +00:00
|
|
|
#include "recent.h"
|
|
|
|
#include <epan/prefs.h>
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2005-08-20 12:09:48 +00:00
|
|
|
#include "gui_utils.h"
|
2004-07-18 00:24:25 +00:00
|
|
|
#include "dlg_utils.h"
|
|
|
|
|
2004-12-29 09:09:35 +00:00
|
|
|
#include "main.h"
|
2008-04-12 16:38:13 +00:00
|
|
|
#include "main_toolbar.h"
|
2006-08-16 18:01:25 +00:00
|
|
|
#include "wtap.h"
|
2005-01-20 23:17:23 +00:00
|
|
|
#include "help_dlg.h"
|
2006-08-16 18:01:25 +00:00
|
|
|
#include "keys.h"
|
|
|
|
|
|
|
|
#include "webbrowser.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_AIRPCAP
|
|
|
|
#include "../image/toolbar/capture_airpcap_16.xpm"
|
|
|
|
#endif
|
|
|
|
#include "../image/toolbar/capture_ethernet_16.xpm"
|
|
|
|
|
|
|
|
/* new buttons to be used instead of labels for 'Capture','Prepare',' */
|
|
|
|
#include "../image/toolbar/capture_capture_16.xpm"
|
|
|
|
#include "../image/toolbar/capture_prepare_16.xpm"
|
|
|
|
#include "../image/toolbar/capture_details_16.xpm"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_AIRPCAP
|
|
|
|
#include <airpcap.h>
|
|
|
|
#include "airpcap_loader.h"
|
|
|
|
#include "airpcap_gui_utils.h"
|
|
|
|
#include "airpcap_dlg.h"
|
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep a static pointer to the current "Capture Interfaces" window, if
|
|
|
|
* any, so that if somebody tries to do "Capture:Start" while there's
|
|
|
|
* already a "Capture Interfaces" window up, we just pop up the existing
|
|
|
|
* one, rather than creating a new one.
|
|
|
|
*/
|
2006-08-26 00:12:12 +00:00
|
|
|
static GtkWidget *cap_if_w;
|
|
|
|
#ifdef HAVE_AIRPCAP
|
|
|
|
static GtkWidget *cap_air_w;
|
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
GList *if_data = NULL;
|
|
|
|
|
|
|
|
guint timer_id;
|
|
|
|
|
|
|
|
GtkWidget *stop_bt;
|
|
|
|
|
|
|
|
GList *if_list;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timeout, in milliseconds, for reads from the stream of captured packets.
|
|
|
|
*/
|
|
|
|
#define CAP_READ_TIMEOUT 250
|
|
|
|
|
|
|
|
|
|
|
|
/* the "runtime" data of one interface */
|
|
|
|
typedef struct if_dlg_data_s {
|
|
|
|
GtkWidget *device_lb;
|
|
|
|
GtkWidget *descr_lb;
|
|
|
|
GtkWidget *ip_lb;
|
|
|
|
GtkWidget *curr_lb;
|
|
|
|
GtkWidget *last_lb;
|
|
|
|
GtkWidget *capture_bt;
|
|
|
|
GtkWidget *prepare_bt;
|
2005-05-20 22:23:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
GtkWidget *details_bt;
|
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
guint32 last_packets;
|
|
|
|
gchar *device;
|
2007-05-18 21:06:20 +00:00
|
|
|
if_info_t if_info;
|
2004-07-18 00:24:25 +00:00
|
|
|
} if_dlg_data_t;
|
|
|
|
|
|
|
|
|
|
|
|
/* start capture button was pressed */
|
|
|
|
static void
|
|
|
|
capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
|
|
|
|
{
|
2006-08-26 00:12:12 +00:00
|
|
|
if_dlg_data_t *if_dlg_data = if_data;
|
2006-08-16 18:01:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_AIRPCAP
|
2007-05-18 21:06:20 +00:00
|
|
|
airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, if_dlg_data->if_info.name);
|
2006-08-26 00:12:12 +00:00
|
|
|
airpcap_if_selected = airpcap_if_active;
|
2006-08-16 18:01:25 +00:00
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2005-02-06 21:20:35 +00:00
|
|
|
if (capture_opts->iface)
|
|
|
|
g_free(capture_opts->iface);
|
2007-08-22 16:30:16 +00:00
|
|
|
if (capture_opts->iface_descr)
|
|
|
|
g_free(capture_opts->iface_descr);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2005-02-06 21:20:35 +00:00
|
|
|
capture_opts->iface = g_strdup(if_dlg_data->device);
|
2007-08-22 16:30:16 +00:00
|
|
|
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2005-04-19 21:02:01 +00:00
|
|
|
/* XXX - remove this? */
|
2005-04-16 19:24:10 +00:00
|
|
|
if (capture_opts->save_file) {
|
2005-02-06 21:20:35 +00:00
|
|
|
g_free(capture_opts->save_file);
|
2005-04-16 19:24:10 +00:00
|
|
|
capture_opts->save_file = NULL;
|
|
|
|
}
|
2005-02-06 21:20:35 +00:00
|
|
|
|
2005-09-07 22:00:25 +00:00
|
|
|
/* stop capturing from all interfaces, we are going to do real work now ... */
|
|
|
|
window_destroy(cap_if_w);
|
|
|
|
|
2005-04-19 21:02:01 +00:00
|
|
|
capture_start_cb(NULL, NULL);
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* prepare capture button was pressed */
|
|
|
|
static void
|
|
|
|
capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data)
|
|
|
|
{
|
|
|
|
if_dlg_data_t *if_dlg_data = if_data;
|
|
|
|
|
2005-02-06 21:20:35 +00:00
|
|
|
if (capture_opts->iface)
|
|
|
|
g_free(capture_opts->iface);
|
2007-08-22 16:30:16 +00:00
|
|
|
if (capture_opts->iface_descr)
|
|
|
|
g_free(capture_opts->iface_descr);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2005-02-06 21:20:35 +00:00
|
|
|
capture_opts->iface = g_strdup(if_dlg_data->device);
|
2007-08-22 16:30:16 +00:00
|
|
|
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2005-09-07 22:00:25 +00:00
|
|
|
/* stop capturing from all interfaces, we are going to do real work now ... */
|
|
|
|
window_destroy(cap_if_w);
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
capture_prep_cb(NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-20 22:23:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* capture details button was pressed */
|
|
|
|
static void
|
|
|
|
capture_details_cb(GtkWidget *details_bt _U_, gpointer if_data)
|
|
|
|
{
|
|
|
|
if_dlg_data_t *if_dlg_data = if_data;
|
|
|
|
|
|
|
|
|
|
|
|
capture_if_details_open(if_dlg_data->device);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
/* update a single interface */
|
|
|
|
void
|
2007-08-02 21:45:27 +00:00
|
|
|
update_if(if_dlg_data_t *if_dlg_data, if_stat_cache_t *sc)
|
2004-07-18 00:24:25 +00:00
|
|
|
{
|
|
|
|
struct pcap_stat stats;
|
|
|
|
gchar *str;
|
|
|
|
guint diff;
|
|
|
|
|
|
|
|
|
2007-08-30 17:36:38 +00:00
|
|
|
/*
|
|
|
|
* Note that some versions of libpcap, on some versions of UN*X,
|
|
|
|
* pcap_stats() returns the number of packets since the last
|
|
|
|
* pcap_stats call.
|
|
|
|
*
|
|
|
|
* That's a bug, and should be fixed; "pcap_stats()" is supposed
|
|
|
|
* to work the same way on all platforms.
|
2004-07-18 00:24:25 +00:00
|
|
|
*/
|
2007-08-02 21:45:27 +00:00
|
|
|
if (sc) {
|
|
|
|
if(capture_stats(sc, if_dlg_data->device, &stats)) {
|
2004-07-18 02:56:29 +00:00
|
|
|
diff = stats.ps_recv - if_dlg_data->last_packets;
|
|
|
|
if_dlg_data->last_packets = stats.ps_recv;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2004-07-18 02:56:29 +00:00
|
|
|
str = g_strdup_printf("%u", if_dlg_data->last_packets);
|
|
|
|
gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), str);
|
|
|
|
g_free(str);
|
|
|
|
str = g_strdup_printf("%u", diff);
|
|
|
|
gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), str);
|
|
|
|
g_free(str);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive(if_dlg_data->curr_lb, diff);
|
|
|
|
gtk_widget_set_sensitive(if_dlg_data->last_lb, diff);
|
|
|
|
} else {
|
|
|
|
gtk_label_set_text(GTK_LABEL(if_dlg_data->curr_lb), "error");
|
|
|
|
gtk_label_set_text(GTK_LABEL(if_dlg_data->last_lb), "error");
|
|
|
|
}
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update all interfaces */
|
2005-08-02 04:47:15 +00:00
|
|
|
static gboolean
|
2004-07-18 00:24:25 +00:00
|
|
|
update_all(gpointer data)
|
|
|
|
{
|
|
|
|
GList *curr;
|
|
|
|
int ifs;
|
2007-08-02 21:45:27 +00:00
|
|
|
if_stat_cache_t *sc = data;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
if(!cap_if_w) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-02 21:45:27 +00:00
|
|
|
for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
|
|
|
|
update_if(curr->data, sc);
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:04:21 +00:00
|
|
|
gboolean g_capture_in_progress = FALSE;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
/* a live capture has started or stopped */
|
|
|
|
void
|
|
|
|
set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress)
|
|
|
|
{
|
|
|
|
GList *curr;
|
|
|
|
int ifs;
|
|
|
|
|
2008-04-12 17:04:21 +00:00
|
|
|
g_capture_in_progress = capture_in_progress;
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
if(cap_if_w) {
|
|
|
|
gtk_widget_set_sensitive(stop_bt, capture_in_progress);
|
2006-08-16 18:01:25 +00:00
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
|
|
|
|
if_dlg_data_t *if_dlg_data = curr->data;
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive(if_dlg_data->capture_bt, !capture_in_progress);
|
|
|
|
gtk_widget_set_sensitive(if_dlg_data->prepare_bt, !capture_in_progress);
|
2006-08-16 18:01:25 +00:00
|
|
|
}
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* the window was closed, cleanup things */
|
|
|
|
static void
|
2007-08-02 21:45:27 +00:00
|
|
|
capture_if_destroy_cb(GtkWidget *win _U_, gpointer user_data)
|
2004-07-18 00:24:25 +00:00
|
|
|
{
|
|
|
|
GList *curr;
|
|
|
|
int ifs;
|
2007-08-02 21:45:27 +00:00
|
|
|
if_stat_cache_t *sc = user_data;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
gtk_timeout_remove(timer_id);
|
|
|
|
|
|
|
|
for(ifs = 0; (curr = g_list_nth(if_data, ifs)); ifs++) {
|
|
|
|
g_free(curr->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if_data = NULL;
|
|
|
|
|
|
|
|
free_interface_list(if_list);
|
|
|
|
|
|
|
|
/* Note that we no longer have a "Capture Options" dialog box. */
|
|
|
|
cap_if_w = NULL;
|
2006-08-16 18:01:25 +00:00
|
|
|
|
2007-08-02 21:45:27 +00:00
|
|
|
capture_stat_stop(sc);
|
|
|
|
|
2006-08-16 18:01:25 +00:00
|
|
|
#ifdef HAVE_AIRPCAP
|
2007-08-02 21:45:27 +00:00
|
|
|
airpcap_set_toolbar_stop_capture(airpcap_if_active);
|
2006-08-16 18:01:25 +00:00
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 22:26:05 +00:00
|
|
|
#if 0
|
2006-08-16 18:01:25 +00:00
|
|
|
GtkWidget*
|
|
|
|
combo_channel_new(void)
|
|
|
|
{
|
|
|
|
GtkWidget* channel_cb;
|
|
|
|
GList* popdown;
|
|
|
|
|
|
|
|
|
|
|
|
channel_cb = gtk_combo_new();
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cb)->entry), "1");
|
|
|
|
|
|
|
|
popdown = NULL;
|
|
|
|
|
|
|
|
popdown = g_list_append(popdown, "1");
|
|
|
|
popdown = g_list_append(popdown, "2");
|
|
|
|
popdown = g_list_append(popdown, "3");
|
|
|
|
popdown = g_list_append(popdown, "4");
|
|
|
|
popdown = g_list_append(popdown, "5");
|
|
|
|
popdown = g_list_append(popdown, "6");
|
|
|
|
popdown = g_list_append(popdown, "7");
|
|
|
|
popdown = g_list_append(popdown, "8");
|
|
|
|
popdown = g_list_append(popdown, "9");
|
|
|
|
popdown = g_list_append(popdown, "10");
|
|
|
|
popdown = g_list_append(popdown, "11");
|
|
|
|
popdown = g_list_append(popdown, "12");
|
|
|
|
popdown = g_list_append(popdown, "13");
|
|
|
|
popdown = g_list_append(popdown, "14");
|
|
|
|
|
|
|
|
gtk_combo_set_popdown_strings( GTK_COMBO(channel_cb), popdown) ;
|
2008-01-24 22:26:05 +00:00
|
|
|
g_list_free(popdown);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_widget_set_size_request( GTK_WIDGET(channel_cb),
|
|
|
|
45,
|
|
|
|
10 );
|
|
|
|
|
|
|
|
return channel_cb;
|
|
|
|
}
|
2008-01-24 22:26:05 +00:00
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2007-05-18 21:06:20 +00:00
|
|
|
/*
|
|
|
|
* Sorts the Interface List in alphabetical order
|
|
|
|
*/
|
2007-05-19 22:00:09 +00:00
|
|
|
gint if_list_comparator_alph (const void *first_arg, const void *second_arg){
|
|
|
|
const if_info_t *first = first_arg, *second = second_arg;
|
|
|
|
|
2007-06-11 03:58:58 +00:00
|
|
|
if (first != NULL && first->description != NULL &&
|
2007-05-19 22:00:09 +00:00
|
|
|
second != NULL && second->description != NULL) {
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
return g_ascii_strcasecmp(first->description, second->description);
|
2007-05-18 21:06:20 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
/* start getting capture stats from all interfaces */
|
|
|
|
void
|
|
|
|
capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
|
|
|
|
{
|
2006-08-16 18:01:25 +00:00
|
|
|
GtkWidget *main_vb,
|
|
|
|
*main_sw,
|
|
|
|
*bbox,
|
|
|
|
*close_bt,
|
|
|
|
*help_bt,
|
|
|
|
*icon;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2006-12-11 19:43:19 +00:00
|
|
|
#ifdef HAVE_AIRPCAP
|
2006-12-05 19:24:25 +00:00
|
|
|
GtkWidget *decryption_cm;
|
2006-12-11 19:43:19 +00:00
|
|
|
#endif
|
2006-12-05 19:24:25 +00:00
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
GtkWidget *if_tb;
|
|
|
|
GtkWidget *if_lb;
|
|
|
|
GtkTooltips *tooltips;
|
|
|
|
int err;
|
2007-01-21 23:45:36 +00:00
|
|
|
gchar *err_str;
|
2006-04-08 20:19:40 +00:00
|
|
|
GtkRequisition requisition;
|
|
|
|
int row, height;
|
2004-07-18 00:24:25 +00:00
|
|
|
if_dlg_data_t *if_dlg_data;
|
2004-07-18 18:47:44 +00:00
|
|
|
int ifs;
|
|
|
|
GList *curr;
|
|
|
|
if_info_t *if_info;
|
|
|
|
GSList *curr_ip;
|
|
|
|
if_addr_t *ip_addr;
|
2004-07-18 00:24:25 +00:00
|
|
|
GString *if_tool_str = g_string_new("");
|
|
|
|
gchar *tmp_str;
|
2007-08-02 21:45:27 +00:00
|
|
|
if_stat_cache_t *sc;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
if (cap_if_w != NULL) {
|
|
|
|
/* There's already a "Capture Interfaces" dialog box; reactivate it. */
|
|
|
|
reactivate_window(cap_if_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* Is WPcap loaded? */
|
|
|
|
if (!has_wpcap) {
|
2005-10-04 06:25:01 +00:00
|
|
|
char *detailed_err;
|
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
detailed_err = cant_load_winpcap_err("Wireshark");
|
2005-10-04 06:25:01 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", detailed_err);
|
|
|
|
g_free(detailed_err);
|
|
|
|
return;
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-08-16 18:01:25 +00:00
|
|
|
/* LOAD THE INTERFACES */
|
2007-06-11 03:58:58 +00:00
|
|
|
if_list = capture_interface_list(&err, &err_str);
|
2007-05-18 21:06:20 +00:00
|
|
|
if_list = g_list_sort (if_list, if_list_comparator_alph);
|
2004-07-18 00:24:25 +00:00
|
|
|
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
|
2007-01-21 23:45:36 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
|
|
|
|
g_free(err_str);
|
2004-07-18 00:24:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-08-16 18:01:25 +00:00
|
|
|
#ifdef HAVE_AIRPCAP
|
|
|
|
/* LOAD AIRPCAP INTERFACES */
|
2007-01-23 20:12:09 +00:00
|
|
|
airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
|
2007-01-21 23:45:36 +00:00
|
|
|
if (airpcap_if_list == NULL)
|
|
|
|
airpcap_if_active = airpcap_if_selected = NULL;
|
|
|
|
|
2008-04-11 17:14:11 +00:00
|
|
|
decryption_cm = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
|
2007-01-21 23:45:36 +00:00
|
|
|
update_decryption_mode_list(decryption_cm);
|
|
|
|
|
|
|
|
if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
|
2007-05-19 22:00:09 +00:00
|
|
|
#if 0
|
|
|
|
/* XXX - Do we need to show an error here? */
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
|
|
|
|
#endif
|
2007-01-21 23:45:36 +00:00
|
|
|
g_free(err_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no airpcap interface is present, gray everything */
|
|
|
|
if (airpcap_if_active == NULL) {
|
|
|
|
if (airpcap_if_list == NULL) {
|
|
|
|
/*No airpcap device found */
|
|
|
|
airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
|
|
|
|
} else {
|
|
|
|
/* default adapter is not airpcap... or is airpcap but is not found*/
|
|
|
|
airpcap_set_toolbar_stop_capture(airpcap_if_active);
|
|
|
|
airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
|
|
|
|
}
|
|
|
|
}
|
2006-08-16 18:01:25 +00:00
|
|
|
|
|
|
|
airpcap_set_toolbar_start_capture(airpcap_if_active);
|
|
|
|
#endif
|
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
cap_if_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Capture Interfaces");
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
tooltips = gtk_tooltips_new();
|
|
|
|
|
2006-04-08 20:19:40 +00:00
|
|
|
main_sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_add(GTK_CONTAINER(cap_if_w), main_sw);
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
main_vb = gtk_vbox_new(FALSE, 0);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
2006-04-08 20:19:40 +00:00
|
|
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), main_vb);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
|
2006-08-16 18:01:25 +00:00
|
|
|
if_tb = gtk_table_new(1,9, FALSE);
|
2004-07-18 00:24:25 +00:00
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(if_tb), 3);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(if_tb), 3);
|
2006-04-08 20:19:40 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), if_tb, FALSE, FALSE, 0);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
row = 0;
|
2006-04-08 20:19:40 +00:00
|
|
|
height = 0;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2006-08-16 18:01:25 +00:00
|
|
|
/* This is the icon column, used to display which kind of interface we have */
|
|
|
|
if_lb = gtk_label_new("");
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 0, 1, row, row+1);
|
|
|
|
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
/*
|
|
|
|
* On Windows, device names are generally not meaningful - NT 5
|
|
|
|
* uses long blobs with GUIDs in them, for example - so we don't
|
|
|
|
* bother showing them.
|
|
|
|
*/
|
2004-07-18 00:24:25 +00:00
|
|
|
if_lb = gtk_label_new("Device");
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 1, 2, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if_lb = gtk_label_new("Description");
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 2, 3, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
if_lb = gtk_label_new(" IP ");
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 3, 4, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
if_lb = gtk_label_new("Packets");
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 4, 5, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
if_lb = gtk_label_new(" Packets/s ");
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_lb, 5, 6, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2008-04-11 18:58:19 +00:00
|
|
|
stop_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_STOP);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, stop_bt,
|
2004-07-18 00:24:25 +00:00
|
|
|
"Stop a running capture.", NULL);
|
2005-05-20 22:23:00 +00:00
|
|
|
#ifdef _WIN32
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), stop_bt, 6, 9, row, row+1);
|
2005-05-20 22:23:00 +00:00
|
|
|
#else
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), stop_bt, 6, 8, row, row+1);
|
2005-05-20 22:23:00 +00:00
|
|
|
#endif
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(stop_bt, "clicked", G_CALLBACK(capture_stop_cb), NULL);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
row++;
|
2006-04-08 20:19:40 +00:00
|
|
|
gtk_widget_size_request(stop_bt, &requisition);
|
|
|
|
height += requisition.height + 15;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2007-08-02 21:45:27 +00:00
|
|
|
/* Start gathering statistics (using dumpcap) */
|
|
|
|
sc = capture_stat_start(if_list);
|
|
|
|
|
|
|
|
/* List the interfaces */
|
2004-07-18 00:24:25 +00:00
|
|
|
for(ifs = 0; (curr = g_list_nth(if_list, ifs)); ifs++) {
|
|
|
|
g_string_assign(if_tool_str, "");
|
|
|
|
if_info = curr->data;
|
2008-01-31 16:47:05 +00:00
|
|
|
|
|
|
|
/* Continue if capture device is hidden */
|
|
|
|
if (prefs_is_capture_device_hidden(if_info->name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
if_dlg_data = g_malloc0(sizeof(if_dlg_data_t));
|
2007-05-18 21:06:20 +00:00
|
|
|
if_dlg_data->if_info = *if_info;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2006-08-26 00:12:12 +00:00
|
|
|
/* Kind of adaptor (icon) */
|
2006-08-16 18:01:25 +00:00
|
|
|
#ifdef HAVE_AIRPCAP
|
2007-05-18 21:06:20 +00:00
|
|
|
if(get_airpcap_if_from_name(airpcap_if_list,if_info->name) != NULL)
|
2006-08-26 00:12:12 +00:00
|
|
|
icon = xpm_to_widget(capture_airpcap_16_xpm);
|
2006-08-16 18:01:25 +00:00
|
|
|
else
|
2006-08-26 00:12:12 +00:00
|
|
|
icon = xpm_to_widget(capture_ethernet_16_xpm);
|
2006-08-16 18:01:25 +00:00
|
|
|
#else
|
2006-08-26 00:12:12 +00:00
|
|
|
icon = xpm_to_widget(capture_ethernet_16_xpm);
|
2006-08-16 18:01:25 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-26 00:12:12 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), icon, 0, 1, row, row+1);
|
2006-08-16 18:01:25 +00:00
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
/* device name */
|
|
|
|
if_dlg_data->device_lb = gtk_label_new(if_info->name);
|
|
|
|
if_dlg_data->device = if_info->name;
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifndef _WIN32
|
2004-07-18 00:24:25 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_dlg_data->device_lb), 0.0, 0.5);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->device_lb, 1, 2, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
#endif
|
|
|
|
g_string_append(if_tool_str, "Device: ");
|
|
|
|
g_string_append(if_tool_str, if_info->name);
|
|
|
|
g_string_append(if_tool_str, "\n");
|
|
|
|
|
|
|
|
/* description */
|
2004-07-18 02:43:18 +00:00
|
|
|
if (if_info->description != NULL)
|
|
|
|
if_dlg_data->descr_lb = gtk_label_new(if_info->description);
|
|
|
|
else
|
|
|
|
if_dlg_data->descr_lb = gtk_label_new("");
|
2004-07-18 00:24:25 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_dlg_data->descr_lb), 0.0, 0.5);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->descr_lb, 2, 3, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2004-07-18 02:43:18 +00:00
|
|
|
if (if_info->description) {
|
|
|
|
g_string_append(if_tool_str, "Description: ");
|
|
|
|
g_string_append(if_tool_str, if_info->description);
|
|
|
|
g_string_append(if_tool_str, "\n");
|
|
|
|
}
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
/* IP address */
|
2004-07-18 18:47:44 +00:00
|
|
|
/* only the first IP address will be shown */
|
2004-07-18 00:24:25 +00:00
|
|
|
g_string_append(if_tool_str, "IP: ");
|
|
|
|
curr_ip = g_slist_nth(if_info->ip_addr, 0);
|
|
|
|
if(curr_ip) {
|
2004-07-18 18:47:44 +00:00
|
|
|
ip_addr = (if_addr_t *)curr_ip->data;
|
2004-07-19 02:27:17 +00:00
|
|
|
switch (ip_addr->type) {
|
2004-07-18 18:47:44 +00:00
|
|
|
|
2004-07-19 02:27:17 +00:00
|
|
|
case AT_IPv4:
|
2004-07-18 18:47:44 +00:00
|
|
|
tmp_str = ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr);
|
|
|
|
break;
|
|
|
|
|
2004-07-19 02:27:17 +00:00
|
|
|
case AT_IPv6:
|
2004-07-18 18:47:44 +00:00
|
|
|
tmp_str = ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
tmp_str = NULL;
|
|
|
|
}
|
|
|
|
if_dlg_data->ip_lb = gtk_label_new(tmp_str);
|
|
|
|
gtk_widget_set_sensitive(if_dlg_data->ip_lb, TRUE);
|
|
|
|
g_string_append(if_tool_str, tmp_str);
|
2004-07-18 00:24:25 +00:00
|
|
|
} else {
|
|
|
|
if_dlg_data->ip_lb = gtk_label_new("unknown");
|
2004-07-18 18:47:44 +00:00
|
|
|
gtk_widget_set_sensitive(if_dlg_data->ip_lb, FALSE);
|
2004-07-18 00:24:25 +00:00
|
|
|
g_string_append(if_tool_str, "unknown");
|
|
|
|
}
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->ip_lb, 3, 4, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
g_string_append(if_tool_str, "\n");
|
|
|
|
|
|
|
|
/* packets */
|
|
|
|
if_dlg_data->curr_lb = gtk_label_new("-");
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->curr_lb, 4, 5, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
/* packets/s */
|
|
|
|
if_dlg_data->last_lb = gtk_label_new("-");
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->last_lb, 5, 6, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
/* capture button */
|
2008-04-11 18:58:19 +00:00
|
|
|
if_dlg_data->capture_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_START);
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(if_dlg_data->capture_bt, "clicked", G_CALLBACK(capture_do_cb), if_dlg_data);
|
2004-07-18 00:24:25 +00:00
|
|
|
tmp_str = g_strdup_printf("Immediately start a capture from this interface:\n\n%s", if_tool_str->str);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, if_dlg_data->capture_bt,
|
2004-07-18 00:24:25 +00:00
|
|
|
tmp_str, NULL);
|
|
|
|
g_free(tmp_str);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->capture_bt, 6, 7, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
/* prepare button */
|
2008-04-11 18:58:19 +00:00
|
|
|
if_dlg_data->prepare_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_OPTIONS);
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(if_dlg_data->prepare_bt, "clicked", G_CALLBACK(capture_prepare_cb), if_dlg_data);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, if_dlg_data->prepare_bt,
|
2004-07-18 00:24:25 +00:00
|
|
|
"Open the capture options dialog with this interface selected.", NULL);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->prepare_bt, 7, 8, row, row+1);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2005-05-20 22:23:00 +00:00
|
|
|
/* details button */
|
|
|
|
#ifdef _WIN32
|
2008-04-11 18:58:19 +00:00
|
|
|
if_dlg_data->details_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_DETAILS);
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(if_dlg_data->details_bt, "clicked", G_CALLBACK(capture_details_cb), if_dlg_data);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, if_dlg_data->details_bt,
|
2005-05-20 22:23:00 +00:00
|
|
|
"Open the capture details dialog of this interface.", NULL);
|
2006-08-16 18:01:25 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->details_bt, 8, 9, row, row+1);
|
2005-05-20 22:23:00 +00:00
|
|
|
#endif
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
if_data = g_list_append(if_data, if_dlg_data);
|
|
|
|
|
|
|
|
row++;
|
2006-04-08 20:19:40 +00:00
|
|
|
if (row <= 10) {
|
|
|
|
/* Lets add up 10 rows of interfaces, otherwise the window may become too high */
|
|
|
|
gtk_widget_size_request(GTK_WIDGET(if_dlg_data->prepare_bt), &requisition);
|
|
|
|
height += requisition.height;
|
|
|
|
}
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free(if_tool_str, TRUE);
|
|
|
|
|
|
|
|
/* Button row: close button */
|
2005-01-20 23:17:23 +00:00
|
|
|
if(topic_available(HELP_CAPTURE_INTERFACES_DIALOG)) {
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
|
|
|
|
} else {
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
|
|
|
|
}
|
2004-07-18 00:24:25 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
|
|
|
|
|
2008-04-11 17:14:11 +00:00
|
|
|
close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
|
2004-07-18 00:24:25 +00:00
|
|
|
window_set_cancel_button(cap_if_w, close_bt, window_cancel_button_cb);
|
|
|
|
gtk_tooltips_set_tip(tooltips, close_bt, "Close this window.", NULL);
|
|
|
|
|
2005-01-20 23:17:23 +00:00
|
|
|
if(topic_available(HELP_CAPTURE_INTERFACES_DIALOG)) {
|
2008-04-11 17:14:11 +00:00
|
|
|
help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)(HELP_CAPTURE_INTERFACES_DIALOG));
|
2005-01-20 23:17:23 +00:00
|
|
|
}
|
|
|
|
|
2006-04-08 20:19:40 +00:00
|
|
|
gtk_widget_size_request(GTK_WIDGET(close_bt), &requisition);
|
2006-04-22 20:16:47 +00:00
|
|
|
/* height + static offset + what GTK-Wimp needs in addition per interface */
|
2006-08-30 20:24:49 +00:00
|
|
|
height += requisition.height + 20 + ifs;
|
2006-04-08 20:19:40 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(cap_if_w), -1, height);
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
gtk_widget_grab_default(close_bt);
|
|
|
|
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(cap_if_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
|
|
|
|
g_signal_connect(cap_if_w, "destroy", G_CALLBACK(capture_if_destroy_cb), sc);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all(cap_if_w);
|
|
|
|
window_present(cap_if_w);
|
|
|
|
|
2008-04-12 17:04:21 +00:00
|
|
|
set_capture_if_dialog_for_capture_in_progress(g_capture_in_progress);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
/* update the interface list every 1000ms */
|
2007-08-02 21:45:27 +00:00
|
|
|
timer_id = gtk_timeout_add(1000, update_all, sc);
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HAVE_LIBPCAP */
|