Added a preference to capture in Pcap-NG from GUI.

svn path=/trunk/; revision=28740
This commit is contained in:
Stig Bjørlykke 2009-06-15 16:36:02 +00:00
parent bbc68754f6
commit a61e285004
6 changed files with 44 additions and 5 deletions

View File

@ -355,6 +355,8 @@ sync_pipe_start(capture_options *capture_opts) {
if (!capture_opts->promisc_mode)
argv = sync_pipe_add_arg(argv, &argc, "-p");
if (capture_opts->use_pcapng)
argv = sync_pipe_add_arg(argv, &argc, "-n");
#ifdef HAVE_PCAP_REMOTE
if (capture_opts->datatx_udp)
argv = sync_pipe_add_arg(argv, &argc, "-u");

View File

@ -1184,6 +1184,7 @@ init_prefs(void) {
prefs.capture_devices_descr = NULL;
prefs.capture_devices_hide = NULL;
prefs.capture_prom_mode = TRUE;
prefs.capture_pcap_ng = FALSE;
prefs.capture_real_time = TRUE;
prefs.capture_auto_scroll = TRUE;
prefs.capture_show_info = FALSE;
@ -1663,6 +1664,7 @@ prefs_is_capture_device_hidden(const char *name)
#define PRS_CAP_DEVICES_DESCR "capture.devices_descr"
#define PRS_CAP_DEVICES_HIDE "capture.devices_hide"
#define PRS_CAP_PROM_MODE "capture.prom_mode"
#define PRS_CAP_PCAP_NG "capture.pcap_ng"
#define PRS_CAP_REAL_TIME "capture.real_time_update"
#define PRS_CAP_AUTO_SCROLL "capture.auto_scroll"
#define PRS_CAP_SHOW_INFO "capture.show_info"
@ -2064,7 +2066,9 @@ set_pref(gchar *pref_name, gchar *value, void *private_data _U_)
prefs.capture_devices_hide = g_strdup(value);
} else if (strcmp(pref_name, PRS_CAP_PROM_MODE) == 0) {
prefs.capture_prom_mode = ((g_ascii_strcasecmp(value, "true") == 0)?TRUE:FALSE);
} else if (strcmp(pref_name, PRS_CAP_REAL_TIME) == 0) {
} else if (strcmp(pref_name, PRS_CAP_PCAP_NG) == 0) {
prefs.capture_pcap_ng = ((g_ascii_strcasecmp(value, "true") == 0)?TRUE:FALSE);
} else if (strcmp(pref_name, PRS_CAP_REAL_TIME) == 0) {
prefs.capture_real_time = ((g_ascii_strcasecmp(value, "true") == 0)?TRUE:FALSE);
} else if (strcmp(pref_name, PRS_CAP_AUTO_SCROLL) == 0) {
prefs.capture_auto_scroll = ((g_ascii_strcasecmp(value, "true") == 0)?TRUE:FALSE);
@ -2901,6 +2905,11 @@ write_prefs(char **pf_path_return)
fprintf(pf, PRS_CAP_PROM_MODE ": %s\n",
prefs.capture_prom_mode == TRUE ? "TRUE" : "FALSE");
fprintf(pf, "\n# Capture in Pcap-NG format?\n");
fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
fprintf(pf, PRS_CAP_PCAP_NG ": %s\n",
prefs.capture_pcap_ng == TRUE ? "TRUE" : "FALSE");
fprintf(pf, "\n# Update packet list in real time during capture?\n");
fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
fprintf(pf, PRS_CAP_REAL_TIME ": %s\n",
@ -3040,6 +3049,7 @@ copy_prefs(e_prefs *dest, e_prefs *src)
dest->capture_devices_descr = g_strdup(src->capture_devices_descr);
dest->capture_devices_hide = g_strdup(src->capture_devices_hide);
dest->capture_prom_mode = src->capture_prom_mode;
dest->capture_pcap_ng = src->capture_pcap_ng;
dest->capture_real_time = src->capture_real_time;
dest->capture_auto_scroll = src->capture_auto_scroll;
dest->capture_show_info = src->capture_show_info;

View File

@ -149,6 +149,7 @@ typedef struct _e_prefs {
gchar *capture_devices_descr;
gchar *capture_devices_hide;
gboolean capture_prom_mode;
gboolean capture_pcap_ng;
gboolean capture_real_time;
gboolean capture_auto_scroll;
gboolean capture_show_info;

View File

@ -94,6 +94,7 @@
#endif
#define E_CAP_SNAP_SB_KEY "cap_snap_sb"
#define E_CAP_PROMISC_KEY "cap_promisc"
#define E_CAP_PCAP_NG_KEY "cap_pcap_ng"
#define E_CAP_FILT_KEY "cap_filter_te"
#define E_CAP_FILE_TE_KEY "cap_file_te"
#define E_CAP_MULTI_FILES_ON_CB_KEY "cap_multi_files_on_cb"
@ -1441,7 +1442,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
*if_ip_hb, *if_ip_lb, *if_ip_eb,
*linktype_hb, *linktype_lb, *linktype_om,
*snap_hb, *snap_cb, *snap_sb, *snap_lb,
*promisc_cb,
*promisc_cb, *pcap_ng_cb,
*filter_hb, *filter_bt, *filter_te, *filter_cm,
*file_fr, *file_vb,
@ -1724,6 +1725,13 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
"See the FAQ for some more details of capturing packets from a switched network.", NULL);
gtk_container_add(GTK_CONTAINER(left_vb), promisc_cb);
/* Pcap-NG row */
pcap_ng_cb = gtk_check_button_new_with_mnemonic("Capture packets in pcap-ng format (experimental)");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcap_ng_cb), global_capture_opts.use_pcapng);
gtk_tooltips_set_tip(tooltips, pcap_ng_cb, "Capture packets in the next-generation capture file format. "
"This is still experimental.", NULL);
gtk_container_add(GTK_CONTAINER(left_vb), pcap_ng_cb);
/* Capture length row */
snap_hb = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(left_vb), snap_hb);
@ -2184,6 +2192,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb);
#endif
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PROMISC_KEY, promisc_cb);
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PCAP_NG_KEY, pcap_ng_cb);
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILT_KEY, filter_te);
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_TE_KEY, file_te);
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_MULTI_FILES_ON_CB_KEY, multi_files_on_cb);
@ -2533,7 +2542,7 @@ capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
/* convert dialog settings into capture_opts values */
static gboolean
capture_dlg_prep(gpointer parent_w) {
GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb, *filter_te, *filter_cm,
GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb, *pcap_ng_cb, *filter_te, *filter_cm,
*file_te, *multi_files_on_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_cb,
*linktype_om, *sync_cb, *auto_scroll_cb, *hide_info_cb,
*stop_packets_cb, *stop_packets_sb,
@ -2569,6 +2578,7 @@ capture_dlg_prep(gpointer parent_w) {
buffer_size_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_BUFFER_SIZE_SB_KEY);
#endif
promisc_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PROMISC_KEY);
pcap_ng_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PCAP_NG_KEY);
filter_cm = g_object_get_data(G_OBJECT(top_level), E_CFILTER_CM_KEY);
filter_te = GTK_COMBO(filter_cm)->entry;
file_te = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_TE_KEY);
@ -2643,6 +2653,8 @@ capture_dlg_prep(gpointer parent_w) {
global_capture_opts.promisc_mode =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
global_capture_opts.use_pcapng =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pcap_ng_cb));
/* XXX - don't try to get clever and set "cfile.filter" to NULL if the
filter string is empty, as an indication that we don't have a filter

View File

@ -3322,6 +3322,7 @@ prefs_to_capture_opts(void)
/* Set promiscuous mode from the preferences setting. */
/* the same applies to other preferences settings as well. */
global_capture_opts.promisc_mode = prefs.capture_prom_mode;
global_capture_opts.use_pcapng = prefs.capture_pcap_ng;
global_capture_opts.show_info = prefs.capture_show_info;
global_capture_opts.real_time_mode = prefs.capture_real_time;
auto_scroll_live = prefs.capture_auto_scroll;

View File

@ -52,6 +52,7 @@
#define DEVICE_KEY "device"
#define PROM_MODE_KEY "prom_mode"
#define PCAP_NG_KEY "pcap_ng"
#define CAPTURE_REAL_TIME_KEY "capture_real_time"
#define AUTO_SCROLL_KEY "auto_scroll"
#define SHOW_INFO_KEY "show_info"
@ -90,7 +91,7 @@ GtkWidget*
capture_prefs_show(void)
{
GtkWidget *main_tb, *main_vb;
GtkWidget *if_cb, *if_lb, *promisc_cb, *sync_cb, *auto_scroll_cb, *show_info_cb;
GtkWidget *if_cb, *if_lb, *promisc_cb, *pcap_ng_cb, *sync_cb, *auto_scroll_cb, *show_info_cb;
GtkWidget *ifopts_lb, *ifopts_bt;
GList *if_list, *combo_list;
int err;
@ -158,6 +159,15 @@ capture_prefs_show(void)
"See the FAQ for some more details of capturing packets from a switched network.", NULL);
g_object_set_data(G_OBJECT(main_vb), PROM_MODE_KEY, promisc_cb);
/* Pcap-NG format */
pcap_ng_cb = create_preference_check_button(main_tb, row++,
"Capture packets in pcap-ng format:", NULL,
prefs.capture_pcap_ng);
gtk_tooltips_set_tip(tooltips, pcap_ng_cb,
"Capture packets in the next-generation capture file format. "
"This is still experimental.", NULL);
g_object_set_data(G_OBJECT(main_vb), PCAP_NG_KEY, pcap_ng_cb);
/* Real-time capture */
sync_cb = create_preference_check_button(main_tb, row++,
"Update list of packets in real time:", NULL,
@ -192,11 +202,12 @@ capture_prefs_show(void)
void
capture_prefs_fetch(GtkWidget *w)
{
GtkWidget *if_cb, *promisc_cb, *sync_cb, *auto_scroll_cb, *show_info_cb;
GtkWidget *if_cb, *promisc_cb, *pcap_ng_cb, *sync_cb, *auto_scroll_cb, *show_info_cb;
gchar *if_text;
if_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), DEVICE_KEY);
promisc_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), PROM_MODE_KEY);
pcap_ng_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), PCAP_NG_KEY);
sync_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), CAPTURE_REAL_TIME_KEY);
auto_scroll_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), AUTO_SCROLL_KEY);
show_info_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), SHOW_INFO_KEY);
@ -219,6 +230,8 @@ capture_prefs_fetch(GtkWidget *w)
prefs.capture_prom_mode = GTK_TOGGLE_BUTTON (promisc_cb)->active;
prefs.capture_pcap_ng = GTK_TOGGLE_BUTTON (pcap_ng_cb)->active;
prefs.capture_real_time = GTK_TOGGLE_BUTTON (sync_cb)->active;
prefs.capture_auto_scroll = GTK_TOGGLE_BUTTON (auto_scroll_cb)->active;