2002-01-10 07:43:39 +00:00
|
|
|
/* capture_prefs.c
|
|
|
|
* Dialog box for capture preferences
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2002-01-10 07:43:39 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2002-01-10 07:43:39 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2002-01-10 07:43:39 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2002-01-10 07:43:39 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2002-01-10 07:43:39 +00:00
|
|
|
* 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
|
|
|
|
|
2002-07-17 00:22:30 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
#include <string.h>
|
2002-01-10 07:43:39 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
#include "capture_prefs.h"
|
|
|
|
#include "gtkglobals.h"
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2002-01-13 20:35:12 +00:00
|
|
|
#include "prefs_dlg.h"
|
2005-08-20 12:09:48 +00:00
|
|
|
#include "gui_utils.h"
|
2003-09-09 04:44:57 +00:00
|
|
|
#include "dlg_utils.h"
|
2003-09-08 21:44:42 +00:00
|
|
|
#include "simple_dialog.h"
|
2005-12-06 00:07:13 +00:00
|
|
|
#include "capture-pcap-util.h"
|
2005-01-16 02:56:28 +00:00
|
|
|
#include "capture_ui_utils.h"
|
2002-01-10 07:43:39 +00:00
|
|
|
#include "main.h"
|
2002-11-11 18:57:00 +00:00
|
|
|
#include "compat_macros.h"
|
2002-01-10 07:43:39 +00:00
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
#define DEVICE_KEY "device"
|
|
|
|
#define PROM_MODE_KEY "prom_mode"
|
2002-01-10 07:43:39 +00:00
|
|
|
#define CAPTURE_REAL_TIME_KEY "capture_real_time"
|
2003-09-08 21:44:42 +00:00
|
|
|
#define AUTO_SCROLL_KEY "auto_scroll"
|
2004-06-20 14:48:24 +00:00
|
|
|
#define SHOW_INFO_KEY "show_info"
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2004-06-20 14:48:24 +00:00
|
|
|
#define CAPTURE_TABLE_ROWS 6
|
2003-09-26 23:11:17 +00:00
|
|
|
|
|
|
|
#define IFOPTS_CALLER_PTR_KEY "ifopts_caller_ptr"
|
|
|
|
#define IFOPTS_DIALOG_PTR_KEY "ifopts_dialog_ptr"
|
|
|
|
#define IFOPTS_TABLE_ROWS 2
|
|
|
|
#define IFOPTS_CLIST_COLS 4
|
|
|
|
#define IFOPTS_MAX_DESCR_LEN 128
|
|
|
|
#define IFOPTS_IF_NOSEL -1
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* interface options dialog */
|
2004-05-31 11:22:58 +00:00
|
|
|
static GtkWidget *cur_clist, *if_dev_lb, *if_name_lb, *if_descr_te, *if_hide_cb;
|
2003-09-26 23:11:17 +00:00
|
|
|
static gint ifrow; /* current interface row selected */
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
static void ifopts_edit_cb(GtkWidget *w, gpointer data);
|
|
|
|
static void ifopts_edit_ok_cb(GtkWidget *w, gpointer parent_w);
|
|
|
|
static void ifopts_edit_destroy_cb(GtkWidget *win, gpointer data);
|
|
|
|
static void ifopts_edit_ifsel_cb(GtkWidget *clist, gint row, gint column,
|
|
|
|
GdkEventButton *event, gpointer data);
|
2003-09-26 23:11:17 +00:00
|
|
|
static void ifopts_edit_descr_changed_cb(GtkEditable *ed, gpointer udata);
|
|
|
|
static void ifopts_edit_hide_changed_cb(GtkToggleButton *tbt, gpointer udata);
|
|
|
|
static void ifopts_options_add(GtkCList *clist, if_info_t *if_info);
|
2003-09-08 21:44:42 +00:00
|
|
|
static void ifopts_options_free(gchar *text[]);
|
2004-05-31 09:23:14 +00:00
|
|
|
static void ifopts_if_clist_add(void);
|
2003-09-08 21:44:42 +00:00
|
|
|
static void ifopts_write_new_descr(void);
|
|
|
|
static void ifopts_write_new_hide(void);
|
2002-01-10 07:43:39 +00:00
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
capture_prefs_show(void)
|
|
|
|
{
|
|
|
|
GtkWidget *main_tb, *main_vb;
|
2004-06-20 14:48:24 +00:00
|
|
|
GtkWidget *if_cb, *if_lb, *promisc_cb, *sync_cb, *auto_scroll_cb, *show_info_cb;
|
2003-09-08 21:44:42 +00:00
|
|
|
GtkWidget *ifopts_lb, *ifopts_bt;
|
2003-09-10 05:35:26 +00:00
|
|
|
GList *if_list, *combo_list;
|
2002-01-10 07:43:39 +00:00
|
|
|
int err;
|
2006-02-17 02:18:48 +00:00
|
|
|
char err_str[CAPTURE_PCAP_ERRBUF_SIZE];
|
2004-06-20 14:48:24 +00:00
|
|
|
int row = 0;
|
|
|
|
GtkTooltips *tooltips = gtk_tooltips_new();
|
2002-01-10 07:43:39 +00:00
|
|
|
|
|
|
|
/* Main vertical box */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 7);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
|
|
|
|
|
|
|
/* Main table */
|
2002-01-12 11:02:47 +00:00
|
|
|
main_tb = gtk_table_new(CAPTURE_TABLE_ROWS, 2, FALSE);
|
2002-01-10 07:43:39 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
|
|
|
|
gtk_widget_show(main_tb);
|
|
|
|
|
|
|
|
/* Default device */
|
2003-09-08 21:44:42 +00:00
|
|
|
if_lb = gtk_label_new("Default interface:");
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_lb, 0, 1, row, row+1);
|
2002-01-12 11:02:47 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_lb), 1.0, 0.5);
|
2002-01-10 07:43:39 +00:00
|
|
|
gtk_widget_show(if_lb);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2002-01-10 07:43:39 +00:00
|
|
|
if_cb = gtk_combo_new();
|
|
|
|
/*
|
|
|
|
* XXX - what if we can't get the list?
|
|
|
|
*/
|
|
|
|
if_list = get_interface_list(&err, err_str);
|
2003-09-10 05:35:26 +00:00
|
|
|
combo_list = build_capture_combo_list(if_list, FALSE);
|
|
|
|
free_interface_list(if_list);
|
2003-09-10 06:55:28 +00:00
|
|
|
if (combo_list != NULL) {
|
|
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
|
|
|
|
free_capture_combo_list(combo_list);
|
|
|
|
}
|
2002-01-10 07:43:39 +00:00
|
|
|
if (prefs.capture_device)
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry),
|
|
|
|
prefs.capture_device);
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_cb, 1, 2, row, row+1);
|
|
|
|
gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry,
|
|
|
|
"The default interface to be captured from.", NULL);
|
2002-01-10 07:43:39 +00:00
|
|
|
gtk_widget_show(if_cb);
|
2002-11-11 18:57:00 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, DEVICE_KEY, if_cb);
|
2004-06-20 14:48:24 +00:00
|
|
|
row++;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2004-01-21 03:54:32 +00:00
|
|
|
/* Interface properties */
|
2004-05-31 11:22:58 +00:00
|
|
|
ifopts_lb = gtk_label_new("Interfaces:");
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), ifopts_lb, 0, 1, row, row+1);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(ifopts_lb), 1.0, 0.5);
|
|
|
|
gtk_widget_show(ifopts_lb);
|
|
|
|
|
2006-05-28 17:19:08 +00:00
|
|
|
ifopts_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_EDIT);
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, ifopts_bt,
|
|
|
|
"Open a dialog box to set various interface options.", NULL);
|
2003-09-08 21:44:42 +00:00
|
|
|
SIGNAL_CONNECT(ifopts_bt, "clicked", ifopts_edit_cb, NULL);
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), ifopts_bt, 1, 2, row, row+1);
|
|
|
|
row++;
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2002-01-10 07:43:39 +00:00
|
|
|
/* Promiscuous mode */
|
2004-06-20 14:48:24 +00:00
|
|
|
promisc_cb = create_preference_check_button(main_tb, row++,
|
2002-01-20 20:05:18 +00:00
|
|
|
"Capture packets in promiscuous mode:", NULL,
|
|
|
|
prefs.capture_prom_mode);
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, promisc_cb,
|
|
|
|
"Usually a network card will only capture the traffic sent to its own network address. "
|
|
|
|
"If you want to capture all traffic that the network card can \"see\", mark this option. "
|
|
|
|
"See the FAQ for some more details of capturing packets from a switched network.", NULL);
|
2002-11-11 18:57:00 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, PROM_MODE_KEY, promisc_cb);
|
2002-01-10 07:43:39 +00:00
|
|
|
|
|
|
|
/* Real-time capture */
|
2004-06-20 14:48:24 +00:00
|
|
|
sync_cb = create_preference_check_button(main_tb, row++,
|
2002-01-20 20:05:18 +00:00
|
|
|
"Update list of packets in real time:", NULL,
|
|
|
|
prefs.capture_real_time);
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, sync_cb,
|
|
|
|
"Update the list of packets while capture is in progress. "
|
|
|
|
"Don't use this option if you notice packet drops.", NULL);
|
2002-11-11 18:57:00 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, CAPTURE_REAL_TIME_KEY, sync_cb);
|
2002-01-10 07:43:39 +00:00
|
|
|
|
|
|
|
/* Auto-scroll real-time capture */
|
2004-06-20 14:48:24 +00:00
|
|
|
auto_scroll_cb = create_preference_check_button(main_tb, row++,
|
2002-01-20 20:05:18 +00:00
|
|
|
"Automatic scrolling in live capture:", NULL,
|
|
|
|
prefs.capture_auto_scroll);
|
2004-06-20 14:48:24 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, auto_scroll_cb,
|
|
|
|
"Automatic scrolling of the packet list while live capture is in progress. ", NULL);
|
2002-11-11 18:57:00 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, AUTO_SCROLL_KEY, auto_scroll_cb);
|
2002-01-10 07:43:39 +00:00
|
|
|
|
2004-06-20 14:48:24 +00:00
|
|
|
/* Show capture info dialog */
|
|
|
|
show_info_cb = create_preference_check_button(main_tb, row++,
|
|
|
|
"Hide capture info dialog:", NULL,
|
|
|
|
!prefs.capture_show_info);
|
|
|
|
gtk_tooltips_set_tip(tooltips, show_info_cb,
|
2006-05-06 12:57:54 +00:00
|
|
|
"Hide the capture info dialog while capturing. ", NULL);
|
2004-06-20 14:48:24 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, SHOW_INFO_KEY, show_info_cb);
|
|
|
|
|
2002-01-10 07:43:39 +00:00
|
|
|
/* Show 'em what we got */
|
|
|
|
gtk_widget_show_all(main_vb);
|
|
|
|
|
|
|
|
return(main_vb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
capture_prefs_fetch(GtkWidget *w)
|
|
|
|
{
|
2004-06-20 14:48:24 +00:00
|
|
|
GtkWidget *if_cb, *promisc_cb, *sync_cb, *auto_scroll_cb, *show_info_cb;
|
2002-01-10 07:43:39 +00:00
|
|
|
gchar *if_text;
|
|
|
|
|
2002-11-11 18:57:00 +00:00
|
|
|
if_cb = (GtkWidget *)OBJECT_GET_DATA(w, DEVICE_KEY);
|
|
|
|
promisc_cb = (GtkWidget *)OBJECT_GET_DATA(w, PROM_MODE_KEY);
|
|
|
|
sync_cb = (GtkWidget *)OBJECT_GET_DATA(w, CAPTURE_REAL_TIME_KEY);
|
|
|
|
auto_scroll_cb = (GtkWidget *)OBJECT_GET_DATA(w, AUTO_SCROLL_KEY);
|
2004-06-20 14:48:24 +00:00
|
|
|
show_info_cb = (GtkWidget *)OBJECT_GET_DATA(w, SHOW_INFO_KEY);
|
2002-01-10 07:43:39 +00:00
|
|
|
|
|
|
|
if (prefs.capture_device != NULL) {
|
|
|
|
g_free(prefs.capture_device);
|
|
|
|
prefs.capture_device = NULL;
|
|
|
|
}
|
2002-06-28 01:59:46 +00:00
|
|
|
if_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
|
|
|
|
/* Strip out white space */
|
|
|
|
g_strstrip(if_text);
|
|
|
|
/* If there was nothing but white space, treat that as an
|
|
|
|
indication that the user doesn't want to wire in a default
|
|
|
|
device, and just wants the first device in the list chosen. */
|
|
|
|
if (*if_text == '\0') {
|
|
|
|
g_free(if_text);
|
|
|
|
if_text = NULL;
|
|
|
|
}
|
|
|
|
prefs.capture_device = if_text;
|
2002-01-10 07:43:39 +00:00
|
|
|
|
|
|
|
prefs.capture_prom_mode = GTK_TOGGLE_BUTTON (promisc_cb)->active;
|
|
|
|
|
|
|
|
prefs.capture_real_time = GTK_TOGGLE_BUTTON (sync_cb)->active;
|
|
|
|
|
|
|
|
prefs.capture_auto_scroll = GTK_TOGGLE_BUTTON (auto_scroll_cb)->active;
|
2004-06-20 14:48:24 +00:00
|
|
|
|
|
|
|
prefs.capture_show_info = !(GTK_TOGGLE_BUTTON (show_info_cb)->active);
|
2002-01-10 07:43:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-05 11:56:00 +00:00
|
|
|
capture_prefs_apply(GtkWidget *w _U_)
|
2002-01-10 07:43:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-09-08 21:44:42 +00:00
|
|
|
capture_prefs_destroy(GtkWidget *w)
|
|
|
|
{
|
|
|
|
GtkWidget *caller = gtk_widget_get_toplevel(w);
|
|
|
|
GtkWidget *dlg;
|
|
|
|
|
|
|
|
/* Is there an interface descriptions dialog associated with this
|
|
|
|
Preferences dialog? */
|
2003-09-26 23:11:17 +00:00
|
|
|
dlg = OBJECT_GET_DATA(caller, IFOPTS_DIALOG_PTR_KEY);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
if (dlg != NULL) {
|
|
|
|
/* Yes. Destroy it. */
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(dlg);
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/*
|
|
|
|
* Create an edit interface options dialog.
|
|
|
|
*/
|
2003-09-08 21:44:42 +00:00
|
|
|
static void
|
|
|
|
ifopts_edit_cb(GtkWidget *w, gpointer data _U_)
|
|
|
|
{
|
2004-05-31 09:23:14 +00:00
|
|
|
GtkWidget *ifopts_edit_dlg, *cur_scr_win, *main_hb, *main_tb,
|
2004-01-21 21:19:34 +00:00
|
|
|
*cur_opts_fr, *ed_opts_fr, *main_vb,
|
2004-05-31 11:22:58 +00:00
|
|
|
*if_descr_lb, *if_hide_lb,
|
2003-09-08 21:44:42 +00:00
|
|
|
*bbox, *ok_bt, *cancel_bt;
|
2005-08-05 20:59:08 +00:00
|
|
|
const gchar *cur_titles[] = { "Device", "Description", "Comment", "Hide?" };
|
|
|
|
int row = 0;
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
GtkWidget *caller = gtk_widget_get_toplevel(w);
|
|
|
|
|
|
|
|
/* Has an edit dialog box already been opened for that top-level
|
|
|
|
widget? */
|
2003-09-26 23:11:17 +00:00
|
|
|
ifopts_edit_dlg = OBJECT_GET_DATA(caller, IFOPTS_DIALOG_PTR_KEY);
|
2003-09-08 21:44:42 +00:00
|
|
|
if (ifopts_edit_dlg != NULL) {
|
|
|
|
/* Yes. Just re-activate that dialog box. */
|
|
|
|
reactivate_window(ifopts_edit_dlg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new dialog */
|
2006-05-22 07:29:40 +00:00
|
|
|
ifopts_edit_dlg = dlg_window_new("Wireshark: Preferences: Interface Options");
|
2004-05-31 11:22:58 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(ifopts_edit_dlg), DEF_WIDTH, 300);
|
2004-05-26 03:49:24 +00:00
|
|
|
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 1);
|
2004-02-13 00:53:37 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(ifopts_edit_dlg), main_vb);
|
|
|
|
gtk_widget_show(main_vb);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* create current options frame */
|
2004-05-31 11:22:58 +00:00
|
|
|
cur_opts_fr = gtk_frame_new("Interfaces");
|
2004-01-21 21:19:34 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), cur_opts_fr);
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_widget_show(cur_opts_fr);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* create a scrolled window to pack the current options CList widget into */
|
2004-02-06 19:19:12 +00:00
|
|
|
cur_scr_win = scrolled_window_new(NULL, NULL);
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(cur_scr_win), 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(cur_opts_fr), cur_scr_win);
|
|
|
|
gtk_widget_show(cur_scr_win);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/*
|
2004-05-31 11:22:58 +00:00
|
|
|
* Create current options CList.
|
2003-09-26 23:11:17 +00:00
|
|
|
*/
|
2005-08-10 19:49:45 +00:00
|
|
|
cur_clist = gtk_clist_new_with_titles(IFOPTS_CLIST_COLS, (gchar **) cur_titles);
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_clist_set_column_width(GTK_CLIST(cur_clist), 1, 230);
|
|
|
|
gtk_clist_set_column_width(GTK_CLIST(cur_clist), 2, 260);
|
|
|
|
gtk_clist_set_column_width(GTK_CLIST(cur_clist), 3, 40);
|
|
|
|
gtk_clist_column_titles_passive(GTK_CLIST(cur_clist));
|
|
|
|
gtk_container_add(GTK_CONTAINER(cur_scr_win), cur_clist);
|
2004-05-31 09:23:14 +00:00
|
|
|
SIGNAL_CONNECT(cur_clist, "select_row", ifopts_edit_ifsel_cb, NULL);
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_widget_show(cur_clist);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2004-05-31 09:23:14 +00:00
|
|
|
/* add interface names to cell */
|
|
|
|
ifopts_if_clist_add();
|
2004-05-31 11:22:58 +00:00
|
|
|
gtk_clist_columns_autosize(GTK_CLIST(cur_clist));
|
2004-05-31 09:23:14 +00:00
|
|
|
|
|
|
|
/* initialize variable that saves currently selected row in "if_clist" */
|
|
|
|
ifrow = IFOPTS_IF_NOSEL;
|
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
/* create edit options frame */
|
2004-05-31 11:22:58 +00:00
|
|
|
ed_opts_fr = gtk_frame_new("Properties");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), ed_opts_fr, FALSE, FALSE, 0);
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_widget_show(ed_opts_fr);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
main_hb = gtk_hbox_new(TRUE, 5);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_hb), 3);
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(ed_opts_fr), main_hb);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_widget_show(main_hb);
|
2004-05-31 09:23:14 +00:00
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
/* table to hold description text entry and hide button */
|
2004-05-31 11:22:58 +00:00
|
|
|
main_tb = gtk_table_new(IFOPTS_TABLE_ROWS, 4, FALSE);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), main_tb, TRUE, FALSE, 10);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 10);
|
|
|
|
gtk_widget_show(main_tb);
|
2004-05-31 09:23:14 +00:00
|
|
|
|
2004-05-31 11:22:58 +00:00
|
|
|
if_dev_lb = gtk_label_new("Device:");
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_dev_lb, 0, 1, row, row+1);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_dev_lb), 1.0, 0.5);
|
|
|
|
gtk_widget_show(if_dev_lb);
|
|
|
|
|
|
|
|
if_dev_lb = gtk_label_new("");
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_dev_lb, 1, 2, row, row+1);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_dev_lb), 0.0, 0.5);
|
|
|
|
gtk_widget_show(if_dev_lb);
|
|
|
|
row++;
|
|
|
|
|
|
|
|
if_name_lb = gtk_label_new("Description:");
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_name_lb, 0, 1, row, row+1);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_name_lb), 1.0, 0.5);
|
|
|
|
gtk_widget_show(if_name_lb);
|
2004-05-31 09:23:14 +00:00
|
|
|
|
|
|
|
if_name_lb = gtk_label_new("");
|
2004-05-31 11:22:58 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_name_lb, 1, 2, row, row+1);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_name_lb), 0.0, 0.5);
|
2004-05-31 09:23:14 +00:00
|
|
|
gtk_widget_show(if_name_lb);
|
2004-05-31 11:22:58 +00:00
|
|
|
row++;
|
2004-05-31 09:23:14 +00:00
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
/* create interface description label and text entry */
|
2004-05-31 11:22:58 +00:00
|
|
|
if_descr_lb = gtk_label_new("Comment:");
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_descr_lb, 0, 1, row, row+1);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_descr_lb), 1.0, 0.5);
|
|
|
|
gtk_widget_show(if_descr_lb);
|
|
|
|
|
|
|
|
if_descr_te = gtk_entry_new();
|
2003-09-26 23:11:17 +00:00
|
|
|
SIGNAL_CONNECT(if_descr_te, "changed", ifopts_edit_descr_changed_cb,
|
|
|
|
cur_clist);
|
|
|
|
gtk_entry_set_max_length(GTK_ENTRY(if_descr_te), IFOPTS_MAX_DESCR_LEN);
|
2004-05-31 11:22:58 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_descr_te, 1, 2, row, row+1);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_widget_show(if_descr_te);
|
2004-05-31 11:22:58 +00:00
|
|
|
row++;
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* create hide interface label and button */
|
|
|
|
if_hide_lb = gtk_label_new("Hide interface?:");
|
2004-05-31 11:22:58 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_hide_lb, 0, 1, row, row+1);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(if_hide_lb), 1.0, 0.5);
|
|
|
|
gtk_widget_show(if_hide_lb);
|
|
|
|
|
|
|
|
if_hide_cb = gtk_check_button_new();
|
2003-09-26 23:11:17 +00:00
|
|
|
SIGNAL_CONNECT(if_hide_cb, "toggled", ifopts_edit_hide_changed_cb,
|
|
|
|
cur_clist);
|
2004-05-31 11:22:58 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), if_hide_cb, 1, 2, row, row+1);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_widget_show(if_hide_cb);
|
2004-05-31 11:22:58 +00:00
|
|
|
row++;
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* button row: OK and Cancel buttons */
|
2004-02-13 00:53:37 +00:00
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
|
2004-01-21 21:19:34 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
|
2004-02-13 00:53:37 +00:00
|
|
|
gtk_widget_show(bbox);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2004-02-13 00:53:37 +00:00
|
|
|
ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
|
2003-09-08 21:44:42 +00:00
|
|
|
SIGNAL_CONNECT(ok_bt, "clicked", ifopts_edit_ok_cb, ifopts_edit_dlg);
|
2003-09-26 23:11:17 +00:00
|
|
|
|
2004-02-13 00:53:37 +00:00
|
|
|
cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
|
2004-05-26 03:49:24 +00:00
|
|
|
window_set_cancel_button(ifopts_edit_dlg, cancel_bt, window_cancel_button_cb);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2004-05-26 03:49:24 +00:00
|
|
|
gtk_widget_grab_default(ok_bt);
|
|
|
|
|
|
|
|
SIGNAL_CONNECT(ifopts_edit_dlg, "delete_event", window_delete_event_cb,
|
|
|
|
NULL);
|
2003-09-08 21:44:42 +00:00
|
|
|
/* Call a handler when we're destroyed, so we can inform
|
|
|
|
our caller, if any, that we've been destroyed. */
|
|
|
|
SIGNAL_CONNECT(ifopts_edit_dlg, "destroy", ifopts_edit_destroy_cb, NULL);
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* Set the key for the new dialog to point to our caller. */
|
|
|
|
OBJECT_SET_DATA(ifopts_edit_dlg, IFOPTS_CALLER_PTR_KEY, caller);
|
|
|
|
/* Set the key for the caller to point to us */
|
|
|
|
OBJECT_SET_DATA(caller, IFOPTS_DIALOG_PTR_KEY, ifopts_edit_dlg);
|
2004-05-31 09:23:14 +00:00
|
|
|
|
|
|
|
/* select the first row in if list, all option fields must exist for this */
|
|
|
|
gtk_clist_select_row(GTK_CLIST(cur_clist), 0, -1);
|
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_widget_show(ifopts_edit_dlg);
|
2004-05-26 03:49:24 +00:00
|
|
|
window_present(ifopts_edit_dlg);
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User selected "OK". Create/write preferences strings.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ifopts_edit_ok_cb(GtkWidget *w _U_, gpointer parent_w)
|
|
|
|
{
|
2003-09-26 23:11:17 +00:00
|
|
|
if (ifrow != IFOPTS_IF_NOSEL) {
|
|
|
|
/* create/write new interfaces description string */
|
|
|
|
ifopts_write_new_descr();
|
|
|
|
|
|
|
|
/* create/write new "hidden" interfaces string */
|
|
|
|
ifopts_write_new_hide();
|
|
|
|
}
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* Now nuke this window. */
|
|
|
|
gtk_grab_remove(GTK_WIDGET(parent_w));
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(GTK_WIDGET(parent_w));
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ifopts_edit_destroy_cb(GtkWidget *win, gpointer data _U_)
|
|
|
|
{
|
|
|
|
GtkWidget *caller;
|
|
|
|
|
|
|
|
/* Get the widget that requested that we be popped up, if any.
|
|
|
|
(It should arrange to destroy us if it's destroyed, so
|
|
|
|
that we don't get a pointer to a non-existent window here.) */
|
2003-09-26 23:11:17 +00:00
|
|
|
caller = OBJECT_GET_DATA(win, IFOPTS_CALLER_PTR_KEY);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
if (caller != NULL) {
|
|
|
|
/* Tell it we no longer exist. */
|
2003-09-26 23:11:17 +00:00
|
|
|
OBJECT_SET_DATA(caller, IFOPTS_DIALOG_PTR_KEY, NULL);
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface selected callback; update displayed widgets.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ifopts_edit_ifsel_cb(GtkWidget *clist _U_,
|
|
|
|
gint row,
|
|
|
|
gint column _U_,
|
|
|
|
GdkEventButton *event _U_,
|
|
|
|
gpointer data _U_)
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* save currently selected row */
|
|
|
|
ifrow = row;
|
|
|
|
|
2004-05-31 11:22:58 +00:00
|
|
|
/* get/display the interface device from current CList */
|
|
|
|
gtk_clist_get_text(GTK_CLIST(cur_clist), row, 0, &text);
|
|
|
|
/* is needed, as gtk_entry_set_text() will change text again (bug in GTK?) */
|
|
|
|
text = strdup(text);
|
|
|
|
gtk_label_set_text(GTK_LABEL(if_dev_lb), text);
|
|
|
|
g_free(text);
|
|
|
|
|
2004-05-31 09:23:14 +00:00
|
|
|
/* get/display the interface name from current CList */
|
|
|
|
gtk_clist_get_text(GTK_CLIST(cur_clist), row, 1, &text);
|
|
|
|
/* is needed, as gtk_entry_set_text() will change text again (bug in GTK?) */
|
|
|
|
text = strdup(text);
|
|
|
|
gtk_label_set_text(GTK_LABEL(if_name_lb), text);
|
|
|
|
g_free(text);
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* get/display the interface description from current CList */
|
|
|
|
gtk_clist_get_text(GTK_CLIST(cur_clist), row, 2, &text);
|
2004-05-31 09:23:14 +00:00
|
|
|
/* is needed, as gtk_entry_set_text() will change text again (bug in GTK?) */
|
|
|
|
text = strdup(text);
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(if_descr_te), text);
|
2004-05-31 09:23:14 +00:00
|
|
|
g_free(text);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* get/display the "hidden" button state from current CList */
|
|
|
|
gtk_clist_get_text(GTK_CLIST(cur_clist), row, 3, &text);
|
|
|
|
if (strcmp("Yes", text) == 0)
|
2003-09-08 21:44:42 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(if_hide_cb), TRUE);
|
|
|
|
else
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(if_hide_cb), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-31 11:22:58 +00:00
|
|
|
* Comment text entry changed callback; update current CList.
|
2003-09-08 21:44:42 +00:00
|
|
|
*/
|
|
|
|
static void
|
2003-09-26 23:11:17 +00:00
|
|
|
ifopts_edit_descr_changed_cb(GtkEditable *ed, gpointer udata)
|
2003-09-08 21:44:42 +00:00
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
if (ifrow == IFOPTS_IF_NOSEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* get current description text and set value in current CList */
|
|
|
|
text = gtk_editable_get_chars(GTK_EDITABLE(ed), 0, -1);
|
2003-09-08 21:44:42 +00:00
|
|
|
/* replace any reserved formatting characters "()," with spaces */
|
|
|
|
g_strdelimit(text, "(),", ' ');
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_clist_set_text(GTK_CLIST(udata), ifrow, 2, text);
|
2003-09-08 21:44:42 +00:00
|
|
|
g_free(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-09-26 23:11:17 +00:00
|
|
|
* Hide toggle button changed callback; update current CList.
|
2003-09-08 21:44:42 +00:00
|
|
|
*/
|
|
|
|
static void
|
2003-09-26 23:11:17 +00:00
|
|
|
ifopts_edit_hide_changed_cb(GtkToggleButton *tbt, gpointer udata)
|
2003-09-08 21:44:42 +00:00
|
|
|
{
|
2003-09-26 23:11:17 +00:00
|
|
|
if (ifrow == IFOPTS_IF_NOSEL)
|
|
|
|
return;
|
2003-09-08 21:44:42 +00:00
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* get "hidden" button state and set text in current CList */
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tbt)) == TRUE)
|
|
|
|
gtk_clist_set_text(GTK_CLIST(udata), ifrow, 3, "Yes");
|
|
|
|
else
|
|
|
|
gtk_clist_set_text(GTK_CLIST(udata), ifrow, 3, "No");
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-09-26 23:11:17 +00:00
|
|
|
* Add any saved options that apply to cells in current CList.
|
2003-09-08 21:44:42 +00:00
|
|
|
*
|
2003-09-26 23:11:17 +00:00
|
|
|
* NOTE:
|
|
|
|
* Interfaces that have been removed from the machine or disabled and
|
|
|
|
* no longer apply are ignored. Therefore, if the user subsequently
|
|
|
|
* selects "OK", the options for these interfaces are lost (they're
|
|
|
|
* lost permanently if "Save" is selected).
|
2003-09-08 21:44:42 +00:00
|
|
|
*/
|
|
|
|
static void
|
2003-09-26 23:11:17 +00:00
|
|
|
ifopts_options_add(GtkCList *clist, if_info_t *if_info)
|
2003-09-08 21:44:42 +00:00
|
|
|
{
|
2003-09-26 23:11:17 +00:00
|
|
|
gint row;
|
2003-09-08 21:44:42 +00:00
|
|
|
gchar *p;
|
|
|
|
gchar *ifnm;
|
|
|
|
gchar *desc;
|
|
|
|
gchar *pr_descr;
|
2004-05-31 11:22:58 +00:00
|
|
|
gchar *text[] = { NULL, NULL, NULL, NULL };
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* add interface descriptions and "hidden" flag */
|
|
|
|
if (prefs.capture_devices_descr != NULL) {
|
|
|
|
/* create working copy of device descriptions */
|
|
|
|
pr_descr = g_strdup(prefs.capture_devices_descr);
|
|
|
|
|
|
|
|
/* if we find a description for this interface */
|
2003-09-10 05:35:26 +00:00
|
|
|
if ((ifnm = strstr(pr_descr, if_info->name)) != NULL) {
|
2003-09-08 21:44:42 +00:00
|
|
|
p = ifnm;
|
|
|
|
while (*p != '\0') {
|
|
|
|
/* found left parenthesis, start of description */
|
|
|
|
if (*p == '(') {
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set device name text */
|
2003-09-10 05:35:26 +00:00
|
|
|
text[0] = g_strdup(if_info->name);
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set OS description + device name text */
|
|
|
|
if (if_info->description != NULL)
|
2004-05-31 11:22:58 +00:00
|
|
|
text[1] = g_strdup(if_info->description);
|
2003-09-26 23:11:17 +00:00
|
|
|
else
|
2005-02-10 07:23:01 +00:00
|
|
|
text[1] = g_strdup("");
|
2003-09-08 21:44:42 +00:00
|
|
|
/* check if interface is "hidden" */
|
|
|
|
if (prefs.capture_devices_hide != NULL) {
|
2003-09-10 05:35:26 +00:00
|
|
|
if (strstr(prefs.capture_devices_hide, if_info->name) != NULL)
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("Yes");
|
2003-09-08 21:44:42 +00:00
|
|
|
else
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("No");
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
else
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("No");
|
2003-09-08 21:44:42 +00:00
|
|
|
p++;
|
|
|
|
/* if syntax error */
|
|
|
|
if ((*p == '\0') || (*p == ',') || (*p == '(') || (*p == ')')) {
|
|
|
|
ifopts_options_free(text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* save pointer to beginning of description */
|
|
|
|
desc = p;
|
|
|
|
p++;
|
|
|
|
/* if syntax error */
|
|
|
|
if ((*p == '\0') || (*p == ',') || (*p == '(') || (*p == ')')) {
|
|
|
|
ifopts_options_free(text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* skip to end of description */
|
|
|
|
while (*p != '\0') {
|
|
|
|
/* end of description */
|
|
|
|
if (*p == ')') {
|
|
|
|
/* terminate and set description text */
|
|
|
|
*p = '\0';
|
2003-09-26 23:11:17 +00:00
|
|
|
text[2] = g_strdup(desc);
|
2003-09-08 21:44:42 +00:00
|
|
|
/* add row to CList */
|
2003-09-26 23:11:17 +00:00
|
|
|
row = gtk_clist_append(GTK_CLIST(clist), text);
|
|
|
|
gtk_clist_set_selectable(GTK_CLIST(clist), row,
|
|
|
|
FALSE);
|
2003-09-08 21:44:42 +00:00
|
|
|
ifopts_options_free(text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
/* get out */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if there's no description for this interface */
|
|
|
|
else {
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set device name text */
|
2003-09-10 05:35:26 +00:00
|
|
|
text[0] = g_strdup(if_info->name);
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set OS description + device name text */
|
|
|
|
if (if_info->description != NULL)
|
2004-05-31 11:22:58 +00:00
|
|
|
text[1] = g_strdup(if_info->description);
|
2003-09-26 23:11:17 +00:00
|
|
|
else
|
2005-02-10 07:23:01 +00:00
|
|
|
text[1] = g_strdup("");
|
2003-09-08 21:44:42 +00:00
|
|
|
/* set empty description */
|
2003-09-26 23:11:17 +00:00
|
|
|
text[2] = g_strdup("");
|
2003-09-08 21:44:42 +00:00
|
|
|
/* check if interface is "hidden" */
|
|
|
|
if (prefs.capture_devices_hide != NULL) {
|
2003-09-10 05:35:26 +00:00
|
|
|
if (strstr(prefs.capture_devices_hide, if_info->name) != NULL)
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("Yes");
|
2003-09-08 21:44:42 +00:00
|
|
|
else
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("No");
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
else
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("No");
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* add row to CList */
|
2003-09-26 23:11:17 +00:00
|
|
|
row = gtk_clist_append(GTK_CLIST(clist), text);
|
|
|
|
gtk_clist_set_selectable(GTK_CLIST(clist), row, FALSE);
|
2003-09-08 21:44:42 +00:00
|
|
|
ifopts_options_free(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(pr_descr);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we do not have any descriptions, but have "hidden" interfaces.
|
|
|
|
*/
|
|
|
|
else if (prefs.capture_devices_hide != NULL) {
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set device name text */
|
2003-09-10 05:35:26 +00:00
|
|
|
text[0] = g_strdup(if_info->name);
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set OS description + device name text */
|
|
|
|
if (if_info->description != NULL)
|
2004-05-31 11:22:58 +00:00
|
|
|
text[1] = g_strdup(if_info->description);
|
2003-09-26 23:11:17 +00:00
|
|
|
else
|
2004-07-13 05:43:59 +00:00
|
|
|
text[1] = g_strdup("");
|
2003-09-08 21:44:42 +00:00
|
|
|
/* set empty description */
|
2003-09-26 23:11:17 +00:00
|
|
|
text[2] = g_strdup("");
|
2003-09-08 21:44:42 +00:00
|
|
|
/* check if interface is "hidden" */
|
2003-09-10 05:35:26 +00:00
|
|
|
if (strstr(prefs.capture_devices_hide, if_info->name) != NULL)
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("Yes");
|
2003-09-08 21:44:42 +00:00
|
|
|
else
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("No");
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* add row to CList */
|
2003-09-26 23:11:17 +00:00
|
|
|
row = gtk_clist_append(GTK_CLIST(clist), text);
|
|
|
|
gtk_clist_set_selectable(GTK_CLIST(clist), row, FALSE);
|
2003-09-08 21:44:42 +00:00
|
|
|
ifopts_options_free(text);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we have no descriptions and no "hidden" interfaces.
|
|
|
|
*/
|
|
|
|
else {
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set device name text */
|
2003-09-10 05:35:26 +00:00
|
|
|
text[0] = g_strdup(if_info->name);
|
2003-09-26 23:11:17 +00:00
|
|
|
/* set OS description + device name text */
|
|
|
|
if (if_info->description != NULL)
|
2004-05-31 11:22:58 +00:00
|
|
|
text[1] = g_strdup(if_info->description);
|
2003-09-26 23:11:17 +00:00
|
|
|
else
|
2004-07-13 05:43:59 +00:00
|
|
|
text[1] = g_strdup("");
|
2003-09-08 21:44:42 +00:00
|
|
|
/* set empty description */
|
2003-09-26 23:11:17 +00:00
|
|
|
text[2] = g_strdup("");
|
2003-09-08 21:44:42 +00:00
|
|
|
/* interface is not "hidden" */
|
2003-09-26 23:11:17 +00:00
|
|
|
text[3] = g_strdup("No");
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/* add row to CList */
|
2003-09-26 23:11:17 +00:00
|
|
|
row = gtk_clist_append(GTK_CLIST(clist), text);
|
|
|
|
gtk_clist_set_selectable(GTK_CLIST(clist), row, FALSE);
|
2003-09-08 21:44:42 +00:00
|
|
|
ifopts_options_free(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ifopts_options_free(gchar *text[])
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
for (i=0; i < IFOPTS_CLIST_COLS; i++) {
|
2003-09-08 21:44:42 +00:00
|
|
|
if (text[i] != NULL) {
|
|
|
|
g_free(text[i]);
|
|
|
|
text[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-31 09:23:14 +00:00
|
|
|
* Add all interfaces to interfaces CList.
|
2003-09-08 21:44:42 +00:00
|
|
|
*/
|
|
|
|
static void
|
2004-05-31 09:23:14 +00:00
|
|
|
ifopts_if_clist_add(void)
|
2003-09-08 21:44:42 +00:00
|
|
|
{
|
2003-09-10 05:35:26 +00:00
|
|
|
GList *if_list;
|
2004-06-12 07:47:14 +00:00
|
|
|
int err;
|
2006-02-17 02:18:48 +00:00
|
|
|
char err_str[CAPTURE_PCAP_ERRBUF_SIZE];
|
2004-06-12 07:47:14 +00:00
|
|
|
gchar *cant_get_if_list_errstr;
|
2003-09-10 05:35:26 +00:00
|
|
|
if_info_t *if_info;
|
|
|
|
guint i;
|
|
|
|
guint nitems;
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
if_list = get_interface_list(&err, err_str);
|
|
|
|
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
|
2004-06-12 07:47:14 +00:00
|
|
|
cant_get_if_list_errstr =
|
|
|
|
cant_get_if_list_error_message(err_str);
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s",
|
|
|
|
cant_get_if_list_errstr);
|
|
|
|
g_free(cant_get_if_list_errstr);
|
2003-09-08 21:44:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Seems we need to be at list head for g_list_length()? */
|
|
|
|
if_list = g_list_first(if_list);
|
|
|
|
nitems = g_list_length(if_list);
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* add OS description + interface name text to CList */
|
2003-09-08 21:44:42 +00:00
|
|
|
for (i=0; i < nitems; i++) {
|
2003-09-10 05:35:26 +00:00
|
|
|
if_info = g_list_nth_data(if_list, i);
|
2003-09-08 21:44:42 +00:00
|
|
|
/* should never happen, but just in case */
|
2003-09-10 05:35:26 +00:00
|
|
|
if (if_info == NULL)
|
2003-09-08 21:44:42 +00:00
|
|
|
continue;
|
2004-05-31 09:23:14 +00:00
|
|
|
|
|
|
|
/* fill current options CList with current preference values */
|
2003-09-26 23:11:17 +00:00
|
|
|
ifopts_options_add(GTK_CLIST(cur_clist), if_info);
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free_interface_list(if_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-09-26 23:11:17 +00:00
|
|
|
* Create/write new interfaces description string based on current CList.
|
2004-05-31 09:23:14 +00:00
|
|
|
* Put it into the preferences value.
|
2003-09-08 21:44:42 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ifopts_write_new_descr(void)
|
|
|
|
{
|
|
|
|
gint i;
|
2004-05-31 09:23:14 +00:00
|
|
|
gboolean first_if = TRUE; /* flag to check if first in list */
|
2003-09-08 21:44:42 +00:00
|
|
|
gchar *ifnm;
|
|
|
|
gchar *desc;
|
|
|
|
gchar *tmp_descr;
|
|
|
|
gchar *new_descr;
|
|
|
|
|
|
|
|
/* new preferences interfaces description string */
|
|
|
|
new_descr = g_malloc0(MAX_VAL_LEN);
|
|
|
|
|
|
|
|
/* get description for each row (interface) */
|
|
|
|
for (i = 0; ;i++) {
|
|
|
|
/* get description */
|
2003-09-26 23:11:17 +00:00
|
|
|
if (gtk_clist_get_text(GTK_CLIST(cur_clist), i, 2, &desc) != 1)
|
2003-09-08 21:44:42 +00:00
|
|
|
break;
|
|
|
|
/* if no description, skip this interface */
|
|
|
|
if (strlen(desc) == 0)
|
|
|
|
continue;
|
2004-05-31 09:23:14 +00:00
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
/* get interface name */
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_clist_get_text(GTK_CLIST(cur_clist), i, 0, &ifnm);
|
2004-05-31 09:23:14 +00:00
|
|
|
|
2003-09-08 21:44:42 +00:00
|
|
|
/*
|
|
|
|
* create/cat interface description to new string
|
|
|
|
* (leave space for parens, comma and terminator)
|
|
|
|
*/
|
2004-05-31 09:23:14 +00:00
|
|
|
if (first_if == TRUE)
|
|
|
|
tmp_descr = g_strdup_printf("%s(%s)", ifnm, desc);
|
|
|
|
else
|
|
|
|
tmp_descr = g_strdup_printf(",%s(%s)", ifnm, desc);
|
|
|
|
strcat(new_descr, tmp_descr);
|
|
|
|
g_free(tmp_descr);
|
|
|
|
/* set first-in-list flag to false */
|
|
|
|
first_if = FALSE;
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write new description string to preferences */
|
|
|
|
if (strlen(new_descr) > 0) {
|
|
|
|
g_free(prefs.capture_devices_descr);
|
|
|
|
prefs.capture_devices_descr = new_descr;
|
|
|
|
}
|
|
|
|
/* no descriptions */
|
|
|
|
else {
|
|
|
|
g_free(prefs.capture_devices_descr);
|
|
|
|
g_free(new_descr);
|
|
|
|
prefs.capture_devices_descr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-09-26 23:11:17 +00:00
|
|
|
* Create/write new "hidden" interfaces string based on current CList.
|
2004-05-31 09:23:14 +00:00
|
|
|
* Put it into the preferences value.
|
2003-09-08 21:44:42 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ifopts_write_new_hide(void)
|
|
|
|
{
|
|
|
|
gint i;
|
2004-05-31 09:23:14 +00:00
|
|
|
gint first_if = TRUE; /* flag to check if first in list */
|
2003-09-08 21:44:42 +00:00
|
|
|
gchar *ifnm;
|
|
|
|
gchar *hide;
|
|
|
|
gchar *tmp_hide;
|
|
|
|
gchar *new_hide;
|
|
|
|
|
|
|
|
/* new preferences "hidden" interfaces string */
|
|
|
|
new_hide = g_malloc0(MAX_VAL_LEN);
|
|
|
|
|
2003-09-26 23:11:17 +00:00
|
|
|
/* get "hidden" flag text for each row (interface) */
|
2003-09-08 21:44:42 +00:00
|
|
|
for (i = 0; ;i++) {
|
|
|
|
/* get flag */
|
2003-09-26 23:11:17 +00:00
|
|
|
if (gtk_clist_get_text(GTK_CLIST(cur_clist), i, 3, &hide) != 1)
|
2003-09-08 21:44:42 +00:00
|
|
|
break;
|
2003-09-26 23:11:17 +00:00
|
|
|
/* if flag text is "No", skip this interface */
|
|
|
|
if (strcmp("No", hide) == 0)
|
2003-09-08 21:44:42 +00:00
|
|
|
continue;
|
2004-05-31 09:23:14 +00:00
|
|
|
|
|
|
|
/* get interface name */
|
2003-09-26 23:11:17 +00:00
|
|
|
gtk_clist_get_text(GTK_CLIST(cur_clist), i, 0, &ifnm);
|
2003-09-08 21:44:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* create/cat interface to new string
|
|
|
|
*/
|
2004-05-31 09:23:14 +00:00
|
|
|
if (first_if == TRUE)
|
|
|
|
tmp_hide = g_strdup_printf("%s", ifnm);
|
|
|
|
else
|
|
|
|
tmp_hide = g_strdup_printf(",%s", ifnm);
|
|
|
|
|
|
|
|
strcat(new_hide, tmp_hide);
|
|
|
|
g_free(tmp_hide);
|
|
|
|
/* set first-in-list flag to false */
|
|
|
|
first_if = FALSE;
|
2003-09-08 21:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write new "hidden" string to preferences */
|
|
|
|
if (strlen(new_hide) > 0) {
|
|
|
|
g_free(prefs.capture_devices_hide);
|
|
|
|
prefs.capture_devices_hide = new_hide;
|
|
|
|
}
|
|
|
|
/* no "hidden" interfaces */
|
|
|
|
else {
|
|
|
|
g_free(prefs.capture_devices_hide);
|
|
|
|
g_free(new_hide);
|
|
|
|
prefs.capture_devices_hide = NULL;
|
|
|
|
}
|
2002-01-10 07:43:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LIBPCAP */
|