2 * Routines for packet capture windows
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
41 #include <epan/packet.h>
42 #include <epan/addr_resolv.h>
43 #include <epan/prefs.h>
44 #include <epan/filesystem.h>
46 #include "../capture.h"
47 #include "../globals.h"
48 #include "../capture_errs.h"
49 #include "../capture_ifinfo.h"
50 #include "../simple_dialog.h"
51 #include "../capture-pcap-util.h"
52 #include "../capture_ui_utils.h"
53 #include "../ringbuffer.h"
56 #include "gtk/menus.h"
57 #include "gtk/gui_utils.h"
58 #include "gtk/capture_dlg.h"
59 #include "gtk/filter_dlg.h"
60 #include "gtk/dlg_utils.h"
61 #include "gtk/file_dlg.h"
62 #include "gtk/stock_icons.h"
63 #include "gtk/capture_file_dlg.h"
64 #include "gtk/help_dlg.h"
65 #include "gtk/gtkglobals.h"
66 #include "gtk/capture_globals.h"
67 #include "gtk/cfilter_combo_utils.h"
70 #include "../capture-wpcap.h"
77 #include "airpcap_loader.h"
78 #include "airpcap_gui_utils.h"
79 #include "airpcap_dlg.h"
82 /* Capture callback data keys */
83 #define E_CAP_IFACE_KEY "cap_iface"
84 #define E_CAP_IFACE_IP_KEY "cap_iface_ip"
85 #define E_CAP_SNAP_CB_KEY "cap_snap_cb"
86 #define E_CAP_LT_OM_KEY "cap_lt_om"
87 #define E_CAP_LT_OM_LABEL_KEY "cap_lt_om_label"
88 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
89 #define E_CAP_BUFFER_SIZE_SB_KEY "cap_buffer_size_sb"
91 #define E_CAP_SNAP_SB_KEY "cap_snap_sb"
92 #define E_CAP_PROMISC_KEY "cap_promisc"
93 #define E_CAP_MONITOR_KEY "cap_monitor"
94 #define E_CAP_PCAP_NG_KEY "cap_pcap_ng"
95 #define E_CAP_FILT_KEY "cap_filter_te"
96 #define E_CAP_FILE_TE_KEY "cap_file_te"
97 #define E_CAP_MULTI_FILES_ON_CB_KEY "cap_multi_files_on_cb"
98 #define E_CAP_RING_FILESIZE_CB_KEY "cap_ring_filesize_cb"
99 #define E_CAP_RING_FILESIZE_SB_KEY "cap_ring_filesize_sb"
100 #define E_CAP_RING_FILESIZE_CBX_KEY "cap_ring_filesize_cbx"
101 #define E_CAP_FILE_DURATION_CB_KEY "cap_file_duration_cb"
102 #define E_CAP_FILE_DURATION_SB_KEY "cap_file_duration_sb"
103 #define E_CAP_FILE_DURATION_CBX_KEY "cap_file_duration_cbx"
104 #define E_CAP_RING_NBF_CB_KEY "cap_ring_nbf_cb"
105 #define E_CAP_RING_NBF_SB_KEY "cap_ring_nbf_sb"
106 #define E_CAP_RING_NBF_LB_KEY "cap_ring_nbf_lb"
107 #define E_CAP_STOP_FILES_CB_KEY "cap_stop_files_cb"
108 #define E_CAP_STOP_FILES_SB_KEY "cap_stop_files_sb"
109 #define E_CAP_STOP_FILES_LB_KEY "cap_stop_files_lb"
110 #define E_CAP_SYNC_KEY "cap_sync"
111 #define E_CAP_AUTO_SCROLL_KEY "cap_auto_scroll"
112 #define E_CAP_HIDE_INFO_KEY "cap_hide_info"
113 #define E_CAP_STOP_PACKETS_CB_KEY "cap_stop_packets_cb"
114 #define E_CAP_STOP_PACKETS_SB_KEY "cap_stop_packets_sb"
115 #define E_CAP_STOP_PACKETS_LB_KEY "cap_stop_packets_lb"
116 #define E_CAP_STOP_FILESIZE_CB_KEY "cap_stop_filesize_cb"
117 #define E_CAP_STOP_FILESIZE_SB_KEY "cap_stop_filesize_sb"
118 #define E_CAP_STOP_FILESIZE_CBX_KEY "cap_stop_filesize_cbx"
119 #define E_CAP_STOP_DURATION_CB_KEY "cap_stop_duration_cb"
120 #define E_CAP_STOP_DURATION_SB_KEY "cap_stop_duration_sb"
121 #define E_CAP_STOP_DURATION_CBX_KEY "cap_stop_duration_cbx"
122 #define E_CAP_M_RESOLVE_KEY "cap_m_resolve"
123 #define E_CAP_N_RESOLVE_KEY "cap_n_resolve"
124 #define E_CAP_T_RESOLVE_KEY "cap_t_resolve"
126 #ifdef HAVE_PCAP_REMOTE
127 #define E_CAP_IFTYPE_CBX_KEY "cap_iftype_cbx"
128 #define E_CAP_IF_LIST_KEY "cap_if_list"
129 #define E_CAP_DATATX_UDP_CB_KEY "cap_datatx_udp_cb"
130 #define E_CAP_NOCAP_RPCAP_CB_KEY "cap_nocap_rpcap_cb"
131 #define E_CAP_REMOTE_DIALOG_PTR_KEY "cap_remote_dialog"
132 #define E_CAP_REMOTE_CALLER_PTR_KEY "cap_remote_caller"
133 #define E_REMOTE_HOST_TE_KEY "cap_remote_host"
134 #define E_REMOTE_PORT_TE_KEY "cap_remote_port"
135 #define E_REMOTE_AUTH_NULL_KEY "cap_remote_auth_null"
136 #define E_REMOTE_AUTH_PASSWD_KEY "cap_remote_auth_passwd"
137 #define E_REMOTE_USERNAME_LB_KEY "cap_remote_username_lb"
138 #define E_REMOTE_USERNAME_TE_KEY "cap_remote_username_te"
139 #define E_REMOTE_PASSWD_LB_KEY "cap_remote_passwd_lb"
140 #define E_REMOTE_PASSWD_TE_KEY "cap_remote_passwd_te"
141 #define E_CAP_CBX_IFTYPE_VALUE_KEY "cap_cbx_iftype_value"
142 #define E_CAP_CBX_PREV_IFTYPE_VALUE_KEY "cap_cbx_prev_iftype_value"
143 #define E_CAP_CBX_IFTYPE_NOUPDATE_KEY "cap_cbx_iftype_noupdate"
144 #define E_OPT_REMOTE_BT_KEY "cap_remote_opt_bt"
145 #define E_OPT_REMOTE_DIALOG_PTR_KEY "cap_remote_opt_dialog"
146 #define E_OPT_REMOTE_CALLER_PTR_KEY "cap_remote_opt_caller"
148 #ifdef HAVE_PCAP_SETSAMPLING
149 #define E_CAP_SAMP_NONE_RB_KEY "cap_samp_none_rb"
150 #define E_CAP_SAMP_COUNT_RB_KEY "cap_samp_count_rb"
151 #define E_CAP_SAMP_COUNT_SB_KEY "cap_samp_count_sb"
152 #define E_CAP_SAMP_TIMER_RB_KEY "cap_samp_timer_rb"
153 #define E_CAP_SAMP_TIMER_SB_KEY "cap_samp_timer_sb"
156 #define E_CAP_OM_LT_VALUE_KEY "cap_om_lt_value"
160 * Keep a static pointer to the current "Capture Options" window, if
161 * any, so that if somebody tries to do "Capture:Start" while there's
162 * already a "Capture Options" window up, we just pop up the existing
163 * one, rather than creating a new one.
165 static GtkWidget *cap_open_w;
166 static GtkWidget * dl_hdr_menu=NULL;
167 static GHashTable *cap_settings_history=NULL;
169 #ifdef HAVE_PCAP_REMOTE
170 static GHashTable *remote_host_list=NULL;
174 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
177 select_link_type_cb(GtkWidget *w, gpointer data);
179 #ifdef HAVE_PCAP_REMOTE
181 select_if_type_cb(GtkComboBox *iftype_cbx, gpointer data);
184 capture_remote_cb(GtkWidget *w, gboolean focus_username);
188 capture_cancel_cb(GtkWidget *win, gpointer data);
191 capture_prep_adjust_sensitivity(GtkWidget *tb, gpointer parent_w);
194 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data);
197 capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp);
199 #ifdef HAVE_PCAP_CREATE
201 capture_prep_monitor_changed_cb(GtkWidget *monitor_cb, gpointer argp);
205 capture_dlg_prep(gpointer parent_w);
208 /* stop the currently running capture */
210 capture_stop_cb(GtkWidget *w _U_, gpointer d _U_)
213 airpcap_set_toolbar_stop_capture(airpcap_if_active);
216 capture_stop(&global_capture_opts);
219 /* restart (stop - delete old file - start) running capture */
221 capture_restart_cb(GtkWidget *w _U_, gpointer d _U_)
224 airpcap_set_toolbar_start_capture(airpcap_if_active);
227 capture_restart(&global_capture_opts);
231 capture_get_cap_settings (gchar *if_name)
233 cap_settings_t cap_settings, *cap_settings_p;
235 if (cap_settings_history) {
236 cap_settings_p = g_hash_table_lookup(cap_settings_history, if_name);
238 cap_settings_p = NULL;
241 if (cap_settings_p) {
242 cap_settings = *cap_settings_p;
244 cap_settings.monitor_mode = prefs_capture_device_monitor_mode(if_name);
245 cap_settings.linktype = capture_dev_user_linktype_find(if_name);;
252 * Set the sensitivity of the monitor mode button, and set the
253 * link-layer header type list, based on the interface's capabilities.
255 * The link-layer header type list often has only one entry; in that case,
256 * it will be disabled.
259 set_if_capabilities(gboolean monitor_mode_changed)
267 if_capabilities_t *caps;
269 GtkWidget *lt_menu, *lt_menu_item;
271 cap_settings_t cap_settings;
272 gint linktype_select, linktype_count;
273 data_link_info_t *data_link_info;
274 gchar *linktype_menu_label;
275 guint num_supported_link_types;
276 GtkWidget *linktype_om = (GtkWidget *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_LT_OM_KEY);
277 GtkWidget *linktype_lb = g_object_get_data(G_OBJECT(linktype_om), E_CAP_LT_OM_LABEL_KEY);
279 GString *ip_str = g_string_new("IP address: ");
283 GtkWidget *if_cb = (GtkWidget *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY);
284 GtkWidget *entry = GTK_COMBO(if_cb)->entry;
285 #ifdef HAVE_PCAP_REMOTE
286 GtkWidget *iftype_cbx;
289 #ifdef HAVE_PCAP_CREATE
290 GtkWidget *monitor_cb = (GtkWidget *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_MONITOR_KEY);
293 GtkWidget *advanced_bt;
296 /* Deallocate the existing menu for Datalink header type */
297 if (dl_hdr_menu != NULL)
298 gtk_widget_destroy(dl_hdr_menu);
300 lt_menu = gtk_menu_new();
301 dl_hdr_menu= lt_menu;
302 entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
303 if_text = g_strstrip(entry_text);
304 if_name = g_strdup(get_if_name(if_text));
305 cap_settings = capture_get_cap_settings(if_name);
306 if (monitor_mode_changed) {
307 #ifdef HAVE_PCAP_CREATE
308 /* Get the new setting of the monitor mode button. */
309 cap_settings.monitor_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(monitor_cb));
311 /* No monitor-mode support. */
312 cap_settings.monitor_mode = FALSE;
317 /* is it an airpcap interface??? */
318 /* retrieve the advanced button pointer */
319 advanced_bt = g_object_get_data(G_OBJECT(entry),AIRPCAP_OPTIONS_ADVANCED_KEY);
320 airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,if_name);
321 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
322 if (airpcap_if_selected != NULL) {
323 gtk_widget_set_sensitive(advanced_bt,TRUE);
325 gtk_widget_set_sensitive(advanced_bt,FALSE);
330 * If the interface name is in the list of known interfaces, get
331 * its list of link-layer types and set the option menu to display it.
333 * If it's not, don't bother - the user might be in the middle of
334 * editing the list, or it might be a remote device in which case
335 * getting the list could take an arbitrarily-long period of time.
336 * The list currently won't contain any remote devices (as
337 * "pcap_findalldevs()" doesn't know about remote devices, and neither
338 * does the code we use if "pcap_findalldevs()" isn't available), but
339 * should contain all the local devices on which you can capture.
342 if (*if_name != '\0') {
344 * Try to get the list of known interfaces.
346 #ifdef HAVE_PCAP_REMOTE
347 iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
348 iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
349 E_CAP_CBX_IFTYPE_VALUE_KEY));
350 if (iftype >= CAPTURE_IFREMOTE)
351 if_list = (GList *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY);
353 if_list = capture_interface_list(&err, NULL);
355 if_list = capture_interface_list(&err, NULL);
357 if (if_list != NULL) {
359 * We have the list - check it.
361 for (if_entry = if_list; if_entry != NULL;
362 if_entry = g_list_next(if_entry)) {
363 if_info = if_entry->data;
364 if (strcmp(if_info->name, if_name) == 0) {
367 * Get the interface capabilities for it.
369 #ifdef HAVE_PCAP_REMOTE
370 if (iftype == CAPTURE_IFREMOTE) {
371 /* Not able to get interface capabilities for remote interfaces */
375 caps = capture_get_if_capabilities(if_name, cap_settings.monitor_mode,
378 /* create string of list of IP addresses of this interface */
379 for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
381 g_string_append(ip_str, ", ");
383 addr = (if_addr_t *)curr_addr->data;
384 switch (addr->ifat_type) {
387 g_string_append(ip_str,
388 ip_to_str((guint8 *)&addr->addr.ip4_addr));
392 g_string_append(ip_str,
393 ip6_to_str((struct e_in6_addr *)&addr->addr.ip6_addr));
397 /* In case we add non-IP addresses */
402 if (if_info->loopback)
403 g_string_append(ip_str, " (loopback)");
406 #ifdef HAVE_PCAP_REMOTE
407 /* Only delete if fetched local */
408 if (iftype == CAPTURE_IFLOCAL)
410 free_interface_list(if_list);
416 num_supported_link_types = 0;
420 #ifdef HAVE_PCAP_CREATE
421 gtk_widget_set_sensitive(monitor_cb, caps->can_set_rfmon);
423 for (lt_entry = caps->data_link_types; lt_entry != NULL;
424 lt_entry = g_list_next(lt_entry)) {
425 data_link_info = lt_entry->data;
426 if (data_link_info->description != NULL) {
427 lt_menu_item = gtk_menu_item_new_with_label(data_link_info->description);
428 g_object_set_data(G_OBJECT(lt_menu_item), E_CAP_LT_OM_KEY, linktype_om);
429 g_signal_connect(lt_menu_item, "activate", G_CALLBACK(select_link_type_cb),
430 GINT_TO_POINTER(data_link_info->dlt));
431 num_supported_link_types++;
433 /* Not supported - tell them about it but don't let them select it. */
434 linktype_menu_label = g_strdup_printf("%s (not supported)",
435 data_link_info->name);
436 lt_menu_item = gtk_menu_item_new_with_label(linktype_menu_label);
437 g_free(linktype_menu_label);
439 if (data_link_info->dlt == cap_settings.linktype) {
440 /* Found a matching dlt, select this */
441 linktype_select = linktype_count;
443 gtk_menu_shell_append(GTK_MENU_SHELL(lt_menu), lt_menu_item);
444 gtk_widget_show(lt_menu_item);
447 free_if_capabilities(caps);
449 #ifdef HAVE_PCAP_CREATE
451 /* We don't know whether this supports monitor mode or not;
452 don't ask for monitor mode. */
453 gtk_widget_set_sensitive(monitor_cb, FALSE);
454 cap_settings.monitor_mode = FALSE;
457 if (linktype_count == 0) {
458 lt_menu_item = gtk_menu_item_new_with_label("(not supported)");
459 gtk_menu_shell_append(GTK_MENU_SHELL(lt_menu), lt_menu_item);
460 gtk_widget_show(lt_menu_item);
462 gtk_option_menu_set_menu(GTK_OPTION_MENU(linktype_om), lt_menu);
463 gtk_widget_set_sensitive(linktype_lb, num_supported_link_types >= 2);
464 gtk_widget_set_sensitive(linktype_om, num_supported_link_types >= 2);
466 g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(cap_settings.linktype));
467 global_capture_opts.linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
469 #ifdef HAVE_PCAP_CREATE
470 /* Set the monitor-mode checkbox to the appropriate value */
471 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(monitor_cb),
472 cap_settings.monitor_mode);
475 /* Restore the menu to the last index used */
476 gtk_option_menu_set_history(GTK_OPTION_MENU(linktype_om),linktype_select);
477 if_ip_lb = g_object_get_data(G_OBJECT(linktype_om), E_CAP_IFACE_KEY);
479 g_string_append(ip_str, "unknown");
481 gtk_label_set_text(GTK_LABEL(if_ip_lb), ip_str->str);
482 #if GTK_CHECK_VERSION(2,6,0)
483 gtk_label_set_ellipsize(GTK_LABEL(if_ip_lb), PANGO_ELLIPSIZE_MIDDLE);
485 g_string_free(ip_str, TRUE);
489 #define TIME_UNIT_SECOND 0
490 #define TIME_UNIT_MINUTE 1
491 #define TIME_UNIT_HOUR 2
492 #define TIME_UNIT_DAY 3
493 #define MAX_TIME_UNITS 4
494 static const char *time_unit_name[MAX_TIME_UNITS] = {
501 /* create one of the duration options */
502 /* (and select the matching unit depending on the given value) */
503 static GtkWidget *time_unit_combo_box_new(guint32 value) {
504 GtkWidget *unit_combo_box;
507 unit_combo_box = gtk_combo_box_new_text ();
508 for(i = 0; i < MAX_TIME_UNITS; i++) {
509 gtk_combo_box_append_text (GTK_COMBO_BOX (unit_combo_box), time_unit_name[i]);
511 /* the selected combo_box item can't be changed, once the combo_box
512 is created, so set the matching combo_box item now */
514 if(value >= 60 * 60 * 24) {
515 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_DAY);
518 if(value >= 60 * 60) {
519 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_HOUR);
523 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_MINUTE);
526 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), TIME_UNIT_SECOND);
531 return unit_combo_box;
534 /* convert time value from raw to displayed (e.g. 60s -> 1min) */
535 static guint32 time_unit_combo_box_convert_value(
539 if(value >= 60 * 60 * 24) {
540 return value / (60 * 60 * 24);
544 if(value >= 60 * 60) {
545 return value / (60 * 60);
557 /* get raw value from unit and value fields */
558 static guint32 time_unit_combo_box_get_value(
559 GtkWidget *unit_combo_box,
564 unit = gtk_combo_box_get_active (GTK_COMBO_BOX(unit_combo_box));
567 case(TIME_UNIT_SECOND):
569 case(TIME_UNIT_MINUTE):
571 case(TIME_UNIT_HOUR):
572 return value * 60 * 60;
574 return value * 60 * 60 * 24;
576 g_assert_not_reached();
582 #define SIZE_UNIT_KILOBYTES 0
583 #define SIZE_UNIT_MEGABYTES 1
584 #define SIZE_UNIT_GIGABYTES 2
585 #define MAX_SIZE_UNITS 3
586 static const char *size_unit_name[MAX_SIZE_UNITS] = {
592 /* create one of the size options */
593 /* (and select the matching unit depending on the given value) */
594 static GtkWidget *size_unit_combo_box_new(guint32 value) {
595 GtkWidget *unit_combo_box;
598 unit_combo_box=gtk_combo_box_new_text();
599 for(i=0;i<MAX_SIZE_UNITS;i++){
600 gtk_combo_box_append_text (GTK_COMBO_BOX (unit_combo_box), size_unit_name[i]);
603 /* the selected combo_box item can't be changed, once the combo_box
604 is created, so set the matching combo_box item now */
606 if(value >= 1024 * 1024) {
607 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), SIZE_UNIT_GIGABYTES);
611 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), SIZE_UNIT_MEGABYTES);
614 gtk_combo_box_set_active(GTK_COMBO_BOX(unit_combo_box), SIZE_UNIT_KILOBYTES);
618 return unit_combo_box;
621 /* convert size value from raw to displayed (e.g. 1024 Bytes -> 1 KB) */
622 static guint32 size_unit_combo_box_set_value(
626 if(value >= 1024 * 1024) {
627 return value / (1024 * 1024);
632 return value / (1024);
639 /* get raw value from unit and value fields */
640 static guint32 size_unit_combo_box_convert_value(
641 GtkWidget *unit_combo_box,
646 unit = gtk_combo_box_get_active (GTK_COMBO_BOX(unit_combo_box));
649 case(SIZE_UNIT_KILOBYTES):
651 case(SIZE_UNIT_MEGABYTES):
652 if(value > G_MAXINT / 1024) {
657 case(SIZE_UNIT_GIGABYTES):
658 if(value > G_MAXINT / (1024 * 1024)) {
661 return value * 1024 * 1024;
664 g_assert_not_reached();
671 * Sets the toolbar before calling the advanced dialog with for the right interface
674 options_airpcap_advanced_cb(GtkWidget *w _U_, gpointer d _U_)
678 from_widget = (gint*)g_malloc(sizeof(gint));
679 *from_widget = AIRPCAP_ADVANCED_FROM_OPTIONS;
680 g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_ADVANCED_FROM_KEY,from_widget);
682 airpcap_if_active = airpcap_if_selected;
683 airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
684 display_airpcap_advanced_cb(w,d);
688 #ifdef HAVE_PCAP_REMOTE
689 /* PCAP interface type menu item */
695 /* List of available types of PCAP interface */
696 static struct iftype_info iftype[] = {
697 { CAPTURE_IFLOCAL, "Local" },
698 { CAPTURE_IFREMOTE, "Remote..." }
701 #if GTK_CHECK_VERSION(2,6,0)
702 #define REMOTE_HOST_START ((sizeof(iftype) / sizeof(iftype[0])) + 1)
703 #define REMOTE_HOST_SEPARATOR "---"
705 #define REMOTE_HOST_START ((sizeof(iftype) / sizeof(iftype[0])))
709 iftype_combo_box_add_remote_separators (GtkWidget *iftype_cbx)
711 #if GTK_CHECK_VERSION(2,6,0)
712 gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), REMOTE_HOST_SEPARATOR);
713 gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), REMOTE_HOST_SEPARATOR);
715 gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), "Clear list");
719 iftype_combo_box_add (GtkWidget *iftype_cbx)
723 struct remote_host *rh;
724 gboolean create_new = FALSE;
726 guint i, pos = REMOTE_HOST_START;
728 rh = g_hash_table_lookup (remote_host_list, global_capture_opts.remote_host);
730 rh = g_malloc0 (sizeof (*rh));
731 if (g_hash_table_size (remote_host_list) == 0) {
732 iftype_combo_box_add_remote_separators (iftype_cbx);
734 gtk_combo_box_insert_text(GTK_COMBO_BOX(iftype_cbx), pos, global_capture_opts.remote_host);
735 rh->remote_host = g_strdup (global_capture_opts.remote_host);
738 model = gtk_combo_box_get_model(GTK_COMBO_BOX(iftype_cbx));
739 if (gtk_tree_model_get_iter_first(model, &iter)) {
740 /* Skip the first entries */
741 for (i = 0; i < REMOTE_HOST_START; i++)
742 gtk_tree_model_iter_next(model, &iter);
744 gtk_tree_model_get(model, &iter, 0, &string, -1);
746 if (strcmp (global_capture_opts.remote_host, string) == 0) {
747 /* Found match, show this position in combo box */
754 } while (gtk_tree_model_iter_next(model, &iter));
757 g_free (rh->remote_port);
758 g_free (rh->auth_username);
759 g_free (rh->auth_password);
762 rh->remote_port = g_strdup (global_capture_opts.remote_port);
763 rh->auth_type = global_capture_opts.auth_type;
764 rh->auth_username = g_strdup (global_capture_opts.auth_username);
765 rh->auth_password = g_strdup (global_capture_opts.auth_password);
768 g_hash_table_insert (remote_host_list, g_strdup (global_capture_opts.remote_host), rh);
771 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY, GINT_TO_POINTER(pos));
772 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_NOUPDATE_KEY, GINT_TO_POINTER(1));
773 gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), pos);
774 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_NOUPDATE_KEY, GINT_TO_POINTER(0));
778 iftype_combo_box_add_remote_host (gpointer key, gpointer value _U_, gpointer user_data)
780 gtk_combo_box_insert_text(GTK_COMBO_BOX(user_data), REMOTE_HOST_START, key);
782 if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
783 /* Ensure we select the correct entry */
784 if (strcmp ((char *)key, global_capture_opts.remote_host) == 0) {
785 gtk_combo_box_set_active(GTK_COMBO_BOX(user_data), REMOTE_HOST_START);
790 /* Fill the menu of available types of interfaces */
792 iftype_combo_box_new(void)
794 GtkWidget *iftype_cbx;
797 iftype_cbx = gtk_combo_box_new_text();
799 for (i = 0; i < sizeof(iftype) / sizeof(iftype[0]); i++) {
800 gtk_combo_box_append_text(GTK_COMBO_BOX(iftype_cbx), iftype[i].name);
803 if (g_hash_table_size (remote_host_list) > 0) {
804 /* Add remote hosts */
805 iftype_combo_box_add_remote_separators (iftype_cbx);
806 g_hash_table_foreach (remote_host_list, iftype_combo_box_add_remote_host, iftype_cbx);
809 if (global_capture_opts.src_type == CAPTURE_IFLOCAL) {
810 gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), CAPTURE_IFLOCAL);
812 int iftype = gtk_combo_box_get_active(GTK_COMBO_BOX(iftype_cbx));
813 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY, GINT_TO_POINTER(iftype));
815 g_signal_connect(iftype_cbx, "changed", G_CALLBACK(select_if_type_cb), NULL);
820 #if GTK_CHECK_VERSION(2,6,0)
822 iftype_combo_is_separator (GtkTreeModel *model, GtkTreeIter *iter, gpointer data _U_)
824 gboolean result = FALSE;
827 gtk_tree_model_get(model, iter, 0, &string, -1);
829 result = !strcmp (string, REMOTE_HOST_SEPARATOR);
839 error_list_remote_interface_cb (gpointer dialog _U_, gint btn _U_, gpointer data)
841 capture_remote_cb(GTK_WIDGET(data), FALSE);
844 /* Retrieve the list of local or remote interfaces according to selected
845 * options and re-fill inteface name combobox */
847 update_interface_list()
849 GtkWidget *if_cb, *iftype_cbx, *remote_bt;
850 GList *if_list, *combo_list;
851 int iftype, prev_iftype, err;
854 if (cap_open_w == NULL)
857 if_cb = (GtkWidget *)g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY);
858 iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
859 remote_bt = g_object_get_data(G_OBJECT(iftype_cbx), E_OPT_REMOTE_BT_KEY);
860 iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
861 E_CAP_CBX_IFTYPE_VALUE_KEY));
863 if_list = (GList *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY);
865 free_interface_list(if_list);
867 if (iftype >= CAPTURE_IFREMOTE) {
868 if_list = get_remote_interface_list(global_capture_opts.remote_host,
869 global_capture_opts.remote_port,
870 global_capture_opts.auth_type,
871 global_capture_opts.auth_username,
872 global_capture_opts.auth_password,
874 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, if_list);
876 if_list = capture_interface_list(&err, &err_str);
877 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
880 if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
881 gpointer dialog = simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
884 if (iftype >= CAPTURE_IFREMOTE) {
885 /* Fall back to previous interface list */
886 simple_dialog_set_cb(dialog, error_list_remote_interface_cb, iftype_cbx);
887 prev_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
888 E_CAP_CBX_PREV_IFTYPE_VALUE_KEY));
889 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY, GINT_TO_POINTER(prev_iftype));
893 gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), NULL);
894 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "");
895 } else if (iftype == CAPTURE_IFREMOTE) {
896 /* New remote interface */
897 iftype_combo_box_add (iftype_cbx);
899 combo_list = build_capture_combo_list(if_list, TRUE);
900 gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
901 if (combo_list == NULL)
902 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "");
904 free_capture_combo_list(combo_list);
906 if (iftype == CAPTURE_IFLOCAL) {
907 /* Only delete if fetched local */
908 free_interface_list(if_list);
909 gtk_widget_set_sensitive(remote_bt, FALSE);
911 gtk_widget_set_sensitive(remote_bt, TRUE);
915 /* User changed an interface entry of "Remote interface" dialog */
917 capture_remote_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
919 GtkWidget *auth_passwd_rb,
920 *username_lb, *username_te,
921 *passwd_lb, *passwd_te;
924 auth_passwd_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
925 E_REMOTE_AUTH_PASSWD_KEY);
926 username_lb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
927 E_REMOTE_USERNAME_LB_KEY);
928 username_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
929 E_REMOTE_USERNAME_TE_KEY);
930 passwd_lb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_REMOTE_PASSWD_LB_KEY);
931 passwd_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_REMOTE_PASSWD_TE_KEY);
933 state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auth_passwd_rb));
934 gtk_widget_set_sensitive(GTK_WIDGET(username_lb), state);
935 gtk_widget_set_sensitive(GTK_WIDGET(username_te), state);
936 gtk_widget_set_sensitive(GTK_WIDGET(passwd_lb), state);
937 gtk_widget_set_sensitive(GTK_WIDGET(passwd_te), state);
940 /* user requested to destroy the dialog */
942 capture_remote_destroy_cb(GtkWidget *win, gpointer user_data _U_)
946 caller = g_object_get_data(G_OBJECT(win), E_CAP_REMOTE_CALLER_PTR_KEY);
947 g_object_set_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY, NULL);
950 /* user requested to accept remote interface options */
952 capture_remote_ok_cb(GtkWidget *win _U_, GtkWidget *remote_w)
954 GtkWidget *host_te, *port_te, *auth_pwd_rb, *username_te, *passwd_te,
955 *auth_null_rb, *auth_passwd_rb, *iftype_cbx;
958 if (remote_w == NULL)
961 host_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_HOST_TE_KEY);
962 port_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_PORT_TE_KEY);
963 auth_pwd_rb = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w),
964 E_REMOTE_AUTH_PASSWD_KEY);
965 username_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w),
966 E_REMOTE_USERNAME_TE_KEY);
967 passwd_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_TE_KEY);
968 auth_null_rb = (GtkWidget *) g_object_get_data(G_OBJECT(remote_w), E_REMOTE_AUTH_NULL_KEY);
969 auth_passwd_rb = (GtkWidget *) g_object_get_data(G_OBJECT(remote_w), E_REMOTE_AUTH_PASSWD_KEY);
970 iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
971 prev_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
972 E_CAP_CBX_IFTYPE_VALUE_KEY));
974 g_free(global_capture_opts.remote_host);
975 global_capture_opts.remote_host = g_strdup(gtk_entry_get_text(GTK_ENTRY(host_te)));
976 g_free(global_capture_opts.remote_port);
977 global_capture_opts.remote_port = g_strdup(gtk_entry_get_text(GTK_ENTRY(port_te)));
978 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auth_passwd_rb)))
979 global_capture_opts.auth_type = CAPTURE_AUTH_PWD;
981 global_capture_opts.auth_type = CAPTURE_AUTH_NULL;
983 g_free(global_capture_opts.auth_username);
984 global_capture_opts.auth_username =
985 g_strdup(gtk_entry_get_text(GTK_ENTRY(username_te)));
987 g_free(global_capture_opts.auth_password);
988 global_capture_opts.auth_password =
989 g_strdup(gtk_entry_get_text(GTK_ENTRY(passwd_te)));
991 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
992 GINT_TO_POINTER(prev_iftype));
993 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY,
994 GINT_TO_POINTER(CAPTURE_IFREMOTE));
996 window_destroy(GTK_WIDGET(remote_w));
997 update_interface_list();
1001 capture_remote_cancel_cb(GtkWidget *win, gpointer data)
1003 GtkWidget *iftype_cbx;
1006 iftype_cbx = g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY);
1007 old_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
1008 E_CAP_CBX_PREV_IFTYPE_VALUE_KEY));
1009 gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), old_iftype);
1011 window_cancel_button_cb (win, data);
1014 /* Show remote capture interface parameters dialog */
1016 capture_remote_cb(GtkWidget *w, gboolean focus_username)
1018 GtkWidget *caller, *remote_w,
1020 *host_lb, *host_te, *port_lb, *port_te,
1022 *auth_null_rb, *auth_passwd_rb, *auth_passwd_tb,
1023 *user_lb, *user_te, *passwd_lb, *passwd_te,
1024 *bbox, *ok_bt, *cancel_bt;
1026 GtkTooltips *tooltips;
1029 caller = gtk_widget_get_toplevel(w);
1030 remote_w = g_object_get_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY);
1031 if (remote_w != NULL) {
1032 reactivate_window(remote_w);
1036 title = create_user_window_title("Wireshark: Remote Interface");
1037 remote_w = dlg_window_new(title);
1038 g_object_set_data(G_OBJECT(remote_w), E_CAP_REMOTE_CALLER_PTR_KEY, caller);
1039 g_object_set_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY, remote_w);
1042 tooltips = gtk_tooltips_new();
1044 main_vb = gtk_vbox_new(FALSE, 0);
1045 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
1046 gtk_container_add(GTK_CONTAINER(remote_w), main_vb);
1048 /* Host/port table */
1049 host_tb = gtk_table_new(2, 2, FALSE);
1050 gtk_table_set_row_spacings(GTK_TABLE(host_tb), 3);
1051 gtk_table_set_col_spacings(GTK_TABLE(host_tb), 3);
1052 gtk_box_pack_start(GTK_BOX(main_vb), host_tb, FALSE, FALSE, 0);
1055 host_lb = gtk_label_new("Host:");
1056 gtk_table_attach_defaults(GTK_TABLE(host_tb), host_lb, 0, 1, 0, 1);
1058 host_te = gtk_entry_new();
1059 gtk_tooltips_set_tip(tooltips, host_te,
1060 "Enter the hostname or host IP address to be used as a source "
1061 "for remote capture.", NULL);
1062 gtk_table_attach_defaults(GTK_TABLE(host_tb), host_te, 1, 2, 0, 1);
1063 if (global_capture_opts.remote_host != NULL)
1064 gtk_entry_set_text(GTK_ENTRY(host_te), global_capture_opts.remote_host);
1067 port_lb = gtk_label_new("Port:");
1068 gtk_table_attach_defaults(GTK_TABLE(host_tb), port_lb, 0, 1, 1, 2);
1070 port_te = gtk_entry_new();
1071 gtk_tooltips_set_tip(tooltips, port_te,
1072 "Enter the TCP port number used by RPCAP server at remote host "
1073 "(leave it empty for default port number).", NULL);
1074 gtk_table_attach_defaults(GTK_TABLE(host_tb), port_te, 1, 2, 1, 2);
1075 if (global_capture_opts.remote_port != NULL)
1076 gtk_entry_set_text(GTK_ENTRY(port_te), global_capture_opts.remote_port);
1078 /* Authentication options frame */
1079 auth_fr = gtk_frame_new("Authentication");
1080 gtk_container_add(GTK_CONTAINER(main_vb), auth_fr);
1082 auth_vb = gtk_vbox_new(FALSE, 3);
1083 gtk_container_set_border_width(GTK_CONTAINER(auth_vb), 5);
1084 gtk_container_add(GTK_CONTAINER(auth_fr), auth_vb);
1086 auth_null_rb = gtk_radio_button_new_with_label(NULL,
1087 "Null authentication");
1088 gtk_box_pack_start(GTK_BOX(auth_vb), auth_null_rb, TRUE, TRUE, 0);
1090 auth_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(auth_null_rb));
1091 auth_passwd_rb = gtk_radio_button_new_with_label(auth_group,
1092 "Password authentication");
1093 gtk_box_pack_start(GTK_BOX(auth_vb), auth_passwd_rb, TRUE, TRUE, 0);
1094 g_signal_connect(auth_passwd_rb, "toggled",
1095 G_CALLBACK(capture_remote_adjust_sensitivity), remote_w);
1097 auth_passwd_tb = gtk_table_new(2, 2, FALSE);
1098 gtk_table_set_row_spacings(GTK_TABLE(auth_passwd_tb), 3);
1099 gtk_table_set_col_spacings(GTK_TABLE(auth_passwd_tb), 3);
1100 gtk_box_pack_start(GTK_BOX(auth_vb), auth_passwd_tb, FALSE, FALSE, 0);
1102 user_lb = gtk_label_new("Username:");
1103 gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), user_lb, 0, 1, 0, 1);
1105 user_te = gtk_entry_new();
1106 gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), user_te, 1, 2, 0, 1);
1107 if (global_capture_opts.auth_username != NULL)
1108 gtk_entry_set_text(GTK_ENTRY(user_te), global_capture_opts.auth_username);
1110 passwd_lb = gtk_label_new("Password:");
1111 gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_lb, 0, 1, 1, 2);
1113 passwd_te = gtk_entry_new();
1114 gtk_entry_set_visibility(GTK_ENTRY(passwd_te), FALSE);
1115 gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_te, 1, 2, 1, 2);
1116 if (global_capture_opts.auth_password != NULL)
1117 gtk_entry_set_text(GTK_ENTRY(passwd_te), global_capture_opts.auth_password);
1119 /* Button row: "Start" and "Cancel" buttons */
1120 bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1121 gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
1123 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1124 g_signal_connect(ok_bt, "clicked", G_CALLBACK(capture_remote_ok_cb), remote_w);
1125 gtk_tooltips_set_tip(tooltips, ok_bt,
1126 "Accept remote host parameters and lookup "
1127 "remote interfaces.", NULL);
1129 cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1130 gtk_tooltips_set_tip(tooltips, cancel_bt,
1131 "Cancel and exit dialog.", NULL);
1132 window_set_cancel_button(remote_w, cancel_bt, capture_remote_cancel_cb);
1134 if (focus_username) {
1135 /* Give the initial focus to the "Username" entry box. */
1136 gtk_widget_grab_focus(user_te);
1139 gtk_widget_grab_default(ok_bt);
1141 /* Catch the "activate" signal on the text
1142 entries, so that if the user types Return there, we act as if the
1143 "OK" button had been selected, as happens if Return is typed if some
1144 widget that *doesn't* handle the Return key has the input focus. */
1145 dlg_set_activate(host_te, ok_bt);
1146 dlg_set_activate(port_te, ok_bt);
1147 dlg_set_activate(user_te, ok_bt);
1148 dlg_set_activate(passwd_te, ok_bt);
1150 g_signal_connect(remote_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1151 g_signal_connect(remote_w, "destroy", G_CALLBACK(capture_remote_destroy_cb), NULL);
1153 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_HOST_TE_KEY, host_te);
1154 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PORT_TE_KEY, port_te);
1155 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_AUTH_NULL_KEY, auth_null_rb);
1156 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_AUTH_PASSWD_KEY, auth_passwd_rb);
1157 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_USERNAME_LB_KEY, user_lb);
1158 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_USERNAME_TE_KEY, user_te);
1159 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_LB_KEY, passwd_lb);
1160 g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_TE_KEY, passwd_te);
1162 if (global_capture_opts.auth_type == CAPTURE_AUTH_PWD)
1163 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_passwd_rb), TRUE);
1165 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_null_rb), TRUE);
1166 capture_remote_adjust_sensitivity(NULL, remote_w);
1168 gtk_widget_show_all(remote_w);
1169 window_present(remote_w);
1172 /* user requested to destroy the dialog */
1174 options_remote_destroy_cb(GtkWidget *win, gpointer user_data _U_)
1178 caller = g_object_get_data(G_OBJECT(win), E_OPT_REMOTE_CALLER_PTR_KEY);
1179 g_object_set_data(G_OBJECT(caller), E_OPT_REMOTE_DIALOG_PTR_KEY, NULL);
1182 /* user requested to accept remote interface options */
1184 options_remote_ok_cb(GtkWidget *win _U_, GtkWidget *parent_w)
1186 GtkWidget *datatx_udp_cb, *nocap_rpcap_cb;
1187 #ifdef HAVE_PCAP_SETSAMPLING
1188 GtkWidget *samp_none_rb, *samp_count_rb, *samp_timer_rb,
1189 *samp_count_sb, *samp_timer_sb;
1192 if (parent_w == NULL)
1195 datatx_udp_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_DATATX_UDP_CB_KEY);
1196 nocap_rpcap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_NOCAP_RPCAP_CB_KEY);
1198 global_capture_opts.datatx_udp =
1199 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(datatx_udp_cb));
1200 global_capture_opts.nocap_rpcap =
1201 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb));
1203 #ifdef HAVE_PCAP_SETSAMPLING
1204 samp_none_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_NONE_RB_KEY);
1205 samp_count_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_RB_KEY);
1206 samp_timer_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_RB_KEY);
1207 samp_count_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_SB_KEY);
1208 samp_timer_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_SB_KEY);
1210 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_none_rb)))
1211 global_capture_opts.sampling_method = CAPTURE_SAMP_NONE;
1212 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_count_rb))) {
1213 global_capture_opts.sampling_method = CAPTURE_SAMP_BY_COUNT;
1214 global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_count_sb));
1215 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_timer_rb))) {
1216 global_capture_opts.sampling_method = CAPTURE_SAMP_BY_TIMER;
1217 global_capture_opts.sampling_param = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(samp_timer_sb));
1221 window_destroy(GTK_WIDGET(parent_w));
1224 #ifdef HAVE_PCAP_SETSAMPLING
1226 options_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
1228 GtkWidget *samp_count_rb, *samp_timer_rb,
1229 *samp_count_sb, *samp_timer_sb;
1231 samp_count_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_RB_KEY);
1232 samp_timer_rb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_RB_KEY);
1233 samp_count_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_COUNT_SB_KEY);
1234 samp_timer_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SAMP_TIMER_SB_KEY);
1236 if (samp_count_sb && samp_count_rb)
1237 gtk_widget_set_sensitive(GTK_WIDGET(samp_count_sb),
1238 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_count_rb)));
1240 if (samp_timer_sb && samp_timer_rb)
1241 gtk_widget_set_sensitive(GTK_WIDGET(samp_timer_sb),
1242 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(samp_timer_rb)));
1247 options_remote_cb(GtkWidget *w _U_, gpointer d _U_)
1249 GtkWidget *opt_remote_w, *main_vb;
1250 GtkWidget *caller, *bbox, *ok_bt, *cancel_bt;
1251 GtkTooltips *tooltips;
1252 GtkWidget *capture_fr, *capture_vb;
1253 GtkWidget *nocap_rpcap_cb, *datatx_udp_cb;
1254 #ifdef HAVE_PCAP_SETSAMPLING
1255 GtkWidget *sampling_fr, *sampling_vb, *sampling_tb, *sampling_lb,
1256 *samp_none_rb, *samp_count_rb, *samp_timer_rb,
1257 *samp_count_sb, *samp_timer_sb;
1258 GtkAdjustment *samp_count_adj, *samp_timer_adj;
1262 caller = gtk_widget_get_toplevel(w);
1263 opt_remote_w = g_object_get_data(G_OBJECT(caller), E_OPT_REMOTE_DIALOG_PTR_KEY);
1264 if (opt_remote_w != NULL) {
1265 reactivate_window(opt_remote_w);
1269 opt_remote_w = dlg_window_new("Remote Capture Settings");
1270 g_object_set_data(G_OBJECT(opt_remote_w), E_OPT_REMOTE_CALLER_PTR_KEY, caller);
1271 g_object_set_data(G_OBJECT(caller), E_OPT_REMOTE_DIALOG_PTR_KEY, opt_remote_w);
1273 tooltips = gtk_tooltips_new();
1275 main_vb = gtk_vbox_new(FALSE, 0);
1276 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
1277 gtk_container_add(GTK_CONTAINER(opt_remote_w), main_vb);
1279 /* Remote capture options */
1280 capture_fr = gtk_frame_new("Capture Options");
1281 gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
1283 capture_vb = gtk_vbox_new(FALSE, 0);
1284 gtk_container_set_border_width(GTK_CONTAINER(capture_vb), 5);
1285 gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb);
1287 nocap_rpcap_cb = gtk_check_button_new_with_mnemonic("Do not capture own RPCAP traffic");
1288 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(nocap_rpcap_cb),
1289 global_capture_opts.nocap_rpcap);
1290 gtk_container_add(GTK_CONTAINER(capture_vb), nocap_rpcap_cb);
1292 datatx_udp_cb = gtk_check_button_new_with_mnemonic("Use UDP for data transfer");
1293 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(datatx_udp_cb),
1294 global_capture_opts.datatx_udp);
1295 gtk_container_add(GTK_CONTAINER(capture_vb), datatx_udp_cb);
1297 #ifdef HAVE_PCAP_SETSAMPLING
1298 /* Sampling options */
1299 sampling_fr = gtk_frame_new("Sampling Options");
1300 gtk_container_add(GTK_CONTAINER(main_vb), sampling_fr);
1302 sampling_vb = gtk_vbox_new(FALSE, 0);
1303 gtk_container_set_border_width(GTK_CONTAINER(sampling_vb), 5);
1304 gtk_container_add(GTK_CONTAINER(sampling_fr), sampling_vb);
1306 sampling_tb = gtk_table_new(3, 3, FALSE);
1307 gtk_table_set_row_spacings(GTK_TABLE(sampling_tb), 1);
1308 gtk_table_set_col_spacings(GTK_TABLE(sampling_tb), 3);
1309 gtk_box_pack_start(GTK_BOX(sampling_vb), sampling_tb, FALSE, FALSE, 0);
1311 /* "No sampling" row */
1312 samp_none_rb = gtk_radio_button_new_with_label(NULL, "None");
1313 if (global_capture_opts.sampling_method == CAPTURE_SAMP_NONE)
1314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_none_rb), TRUE);
1315 g_signal_connect(samp_none_rb, "toggled",
1316 G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
1317 gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_none_rb, 0, 1, 0, 1);
1319 /* "Sampling by counter" row */
1320 samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_none_rb));
1321 samp_count_rb = gtk_radio_button_new_with_label(samp_group, "1 of");
1322 if (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_COUNT)
1323 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_count_rb), TRUE);
1324 g_signal_connect(samp_count_rb, "toggled",
1325 G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
1326 gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_count_rb, 0, 1, 1, 2);
1328 samp_count_adj = (GtkAdjustment *) gtk_adjustment_new(
1329 (gfloat)global_capture_opts.sampling_param,
1330 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1331 samp_count_sb = gtk_spin_button_new(samp_count_adj, 0, 0);
1332 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_count_sb), TRUE);
1333 gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_count_sb, 1, 2, 1, 2);
1335 sampling_lb = gtk_label_new("packets");
1336 gtk_misc_set_alignment(GTK_MISC(sampling_lb), 0, 0.5);
1337 gtk_table_attach_defaults(GTK_TABLE(sampling_tb), sampling_lb, 2, 3, 1, 2);
1339 /* "Sampling by timer" row */
1340 samp_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(samp_count_rb));
1341 samp_timer_rb = gtk_radio_button_new_with_label(samp_group, "1 every");
1342 if (global_capture_opts.sampling_method == CAPTURE_SAMP_BY_TIMER)
1343 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(samp_timer_rb), TRUE);
1344 g_signal_connect(samp_timer_rb, "toggled",
1345 G_CALLBACK(options_prep_adjust_sensitivity), opt_remote_w);
1346 gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_timer_rb, 0, 1, 2, 3);
1348 samp_timer_adj = (GtkAdjustment *) gtk_adjustment_new(
1349 (gfloat)global_capture_opts.sampling_param,
1350 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
1351 samp_timer_sb = gtk_spin_button_new(samp_timer_adj, 0, 0);
1352 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(samp_timer_sb), TRUE);
1353 gtk_table_attach_defaults(GTK_TABLE(sampling_tb), samp_timer_sb, 1, 2, 2, 3);
1355 sampling_lb = gtk_label_new("milliseconds");
1356 gtk_misc_set_alignment(GTK_MISC(sampling_lb), 0, 0.5);
1357 gtk_table_attach_defaults(GTK_TABLE(sampling_tb), sampling_lb, 2, 3, 2, 3);
1360 /* Button row: "Start" and "Cancel" buttons */
1361 bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1362 gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
1364 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1365 g_signal_connect(ok_bt, "clicked", G_CALLBACK(options_remote_ok_cb), opt_remote_w);
1366 gtk_tooltips_set_tip(tooltips, ok_bt,
1367 "Accept parameters and close dialog.", NULL);
1369 cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1370 gtk_tooltips_set_tip(tooltips, cancel_bt,
1371 "Cancel and exit dialog.", NULL);
1372 window_set_cancel_button(opt_remote_w, cancel_bt, window_cancel_button_cb);
1374 gtk_widget_grab_default(ok_bt);
1376 g_signal_connect(opt_remote_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1377 g_signal_connect(opt_remote_w, "destroy", G_CALLBACK(options_remote_destroy_cb), NULL);
1379 g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_NOCAP_RPCAP_CB_KEY, nocap_rpcap_cb);
1380 g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_DATATX_UDP_CB_KEY, datatx_udp_cb);
1382 #ifdef HAVE_PCAP_SETSAMPLING
1383 g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_NONE_RB_KEY, samp_none_rb);
1384 g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_COUNT_RB_KEY, samp_count_rb);
1385 g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_COUNT_SB_KEY, samp_count_sb);
1386 g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_TIMER_RB_KEY, samp_timer_rb);
1387 g_object_set_data(G_OBJECT(opt_remote_w), E_CAP_SAMP_TIMER_SB_KEY, samp_timer_sb);
1390 #ifdef HAVE_PCAP_SETSAMPLING
1391 /* Set the sensitivity of various widgets as per the settings of other
1393 options_prep_adjust_sensitivity(NULL, opt_remote_w);
1396 gtk_widget_show_all(opt_remote_w);
1397 window_present(opt_remote_w);
1401 recent_print_remote_host (gpointer key _U_, gpointer value, gpointer user)
1404 struct remote_host *ri = value;
1406 fprintf (rf, RECENT_KEY_REMOTE_HOST ": %s,%s,%d\n", ri->remote_host, ri->remote_port, ri->auth_type);
1410 capture_remote_combo_recent_write_all(FILE *rf)
1412 if (remote_host_list && g_hash_table_size (remote_host_list) > 0) {
1413 /* Write all remote interfaces to the recent file */
1414 g_hash_table_foreach (remote_host_list, recent_print_remote_host, rf);
1419 capture_remote_combo_add_recent(gchar *s)
1421 GList *vals = prefs_get_string_list (s);
1423 struct remote_host *rh;
1430 if (remote_host_list == NULL) {
1431 remote_host_list = g_hash_table_new (g_str_hash, g_str_equal);
1434 rh = g_malloc (sizeof (*rh));
1436 /* First value is the host */
1437 rh->remote_host = g_strdup (valp->data);
1438 if (strlen(rh->remote_host) == 0)
1439 /* Empty remote host */
1441 rh->auth_type = CAPTURE_AUTH_NULL;
1445 /* Found value 2, this is the port number */
1446 rh->remote_port = g_strdup (valp->data);
1449 /* Did not find a port number */
1450 rh->remote_port = g_strdup ("");
1454 /* Found value 3, this is the authentication type */
1455 auth_type = strtol(valp->data, &p, 0);
1456 if (p != valp->data && *p == '\0') {
1457 rh->auth_type = auth_type;
1461 /* Do not store username and password */
1462 rh->auth_username = g_strdup ("");
1463 rh->auth_password = g_strdup ("");
1465 prefs_clear_string_list(vals);
1467 g_hash_table_insert (remote_host_list, g_strdup(rh->remote_host), rh);
1474 #ifdef HAVE_PCAP_CREATE
1476 capture_filter_compile_cb(GtkWidget *w _U_, gpointer user_data _U_)
1481 const gchar *if_name;
1484 struct bpf_program fcode;
1485 char errbuf[PCAP_ERRBUF_SIZE];
1487 GtkWidget *filter_cm, *filter_te;
1488 const gchar *filter_text;
1490 if_cb = (GtkWidget *)g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY);
1491 entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
1492 if_text = g_strstrip(entry_text);
1493 if_name = get_if_name(if_text);
1494 if (*if_name == '\0') {
1495 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1496 "You didn't specify an interface on which to capture packets.");
1501 if (!(pd = pcap_create(if_name, errbuf))) {
1502 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", errbuf);
1507 filter_cm = g_object_get_data(G_OBJECT(top_level), E_CFILTER_CM_KEY);
1508 filter_te = GTK_COMBO(filter_cm)->entry;
1509 filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
1511 if (pcap_compile(pd, &fcode, filter_text, 1 /* Do optimize */, PCAP_NETMASK_UNKNOWN) < 0) {
1512 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", pcap_geterr(pd));
1514 GString *bpf_code_dump = g_string_new("");
1515 struct bpf_insn *insn = fcode.bf_insns;
1516 int i, n = fcode.bf_len;
1518 gchar *bpf_code_str;
1519 gchar *bpf_code_markup;
1521 for (i = 0; i < n; ++insn, ++i) {
1522 g_string_append(bpf_code_dump, bpf_image(insn, i));
1523 g_string_append(bpf_code_dump, "\n");
1526 bpf_code_str = g_string_free(bpf_code_dump, FALSE);
1527 bpf_code_markup = g_markup_escape_text(bpf_code_str, -1);
1529 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "<markup><tt>%s</tt></markup>", bpf_code_markup);
1531 g_free(bpf_code_str);
1532 g_free(bpf_code_markup);
1541 /* show capture prepare (options) dialog */
1543 capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
1546 *main_hb, *left_vb, *right_vb,
1548 *capture_fr, *capture_vb,
1549 *if_hb, *if_cb, *if_lb,
1550 *if_ip_hb, *if_ip_lb, *if_ip_eb,
1551 *linktype_hb, *linktype_lb, *linktype_om,
1552 *snap_hb, *snap_cb, *snap_sb, *snap_lb,
1554 #ifdef HAVE_PCAP_CREATE
1558 *filter_hb, *filter_bt, *filter_te, *filter_cm,
1559 #ifdef HAVE_PCAP_CREATE
1563 *file_hb, *file_bt, *file_lb, *file_te,
1564 *multi_tb, *multi_files_on_cb,
1565 *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_cbx,
1566 *file_duration_cb, *file_duration_sb, *file_duration_cbx,
1567 *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
1568 *stop_files_cb, *stop_files_sb, *stop_files_lb,
1570 *limit_fr, *limit_vb, *limit_tb,
1571 *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
1572 *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_cbx,
1573 *stop_duration_cb, *stop_duration_sb, *stop_duration_cbx,
1575 *display_fr, *display_vb,
1576 *sync_cb, *auto_scroll_cb, *hide_info_cb,
1578 *resolv_fr, *resolv_vb,
1579 *m_resolv_cb, *n_resolv_cb, *t_resolv_cb,
1580 *bbox, *ok_bt, *cancel_bt,
1583 GtkWidget *advanced_bt;
1584 GtkWidget *decryption_cb;
1586 #ifdef HAVE_PCAP_REMOTE
1587 GtkWidget *iftype_cbx;
1588 GtkWidget *remote_bt;
1590 GtkTooltips *tooltips;
1591 GtkAdjustment *snap_adj, *ringbuffer_nbf_adj,
1592 *stop_packets_adj, *stop_filesize_adj, *stop_duration_adj, *stop_files_adj, *ring_filesize_adj, *file_duration_adj;
1593 GList *if_list, *combo_list, *cfilter_list;
1597 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
1598 GtkAdjustment *buffer_size_adj;
1599 GtkWidget *buffer_size_lb, *buffer_size_sb, *buffer_size_hb;
1605 if (cap_open_w != NULL) {
1606 /* There's already a "Capture Options" dialog box; reactivate it. */
1607 reactivate_window(cap_open_w);
1612 /* Is WPcap loaded? */
1616 detailed_err = cant_load_winpcap_err("Wireshark");
1617 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", detailed_err);
1618 g_free(detailed_err);
1623 /* use user-defined title if preference is set */
1624 cap_title = create_user_window_title("Wireshark: Capture Options");
1626 cap_open_w = dlg_window_new(cap_title);
1629 tooltips = gtk_tooltips_new();
1631 #ifdef HAVE_PCAP_REMOTE
1632 if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
1633 if_list = get_remote_interface_list(global_capture_opts.remote_host,
1634 global_capture_opts.remote_port,
1635 global_capture_opts.auth_type,
1636 global_capture_opts.auth_username,
1637 global_capture_opts.auth_password,
1639 if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
1640 /* Silently fall back to local interface list */
1641 if (global_capture_opts.iface) {
1642 g_free (global_capture_opts.iface);
1643 global_capture_opts.iface = NULL;
1645 if (global_capture_opts.iface_descr) {
1646 g_free (global_capture_opts.iface_descr);
1647 global_capture_opts.iface_descr = NULL;
1649 if_list = capture_interface_list(&err, &err_str);
1650 global_capture_opts.src_type = CAPTURE_IFLOCAL;
1651 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
1653 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, if_list);
1656 if_list = capture_interface_list(&err, &err_str);
1657 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
1660 if_list = capture_interface_list(&err, &err_str);
1662 if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
1663 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
1668 /* update airpcap interface list */
1670 /* load the airpcap interfaces */
1671 airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
1673 decryption_cb = g_object_get_data(G_OBJECT(airpcap_tb),AIRPCAP_TOOLBAR_DECRYPTION_KEY);
1674 update_decryption_mode_list(decryption_cb);
1676 if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) {
1677 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
1681 /* select the first ad default (THIS SHOULD BE CHANGED) */
1682 airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
1685 main_vb = gtk_vbox_new(FALSE, 0);
1686 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
1687 gtk_container_add(GTK_CONTAINER(cap_open_w), main_vb);
1689 /* Capture-related options frame */
1690 capture_fr = gtk_frame_new("Capture");
1691 gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
1693 capture_vb = gtk_vbox_new(FALSE, 3);
1694 gtk_container_set_border_width(GTK_CONTAINER(capture_vb), 5);
1695 gtk_container_add(GTK_CONTAINER(capture_fr), capture_vb);
1698 if_hb = gtk_hbox_new(FALSE, 3);
1699 gtk_container_add(GTK_CONTAINER(capture_vb), if_hb);
1701 if_lb = gtk_label_new("Interface:");
1702 gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 3);
1704 #ifdef HAVE_PCAP_REMOTE
1705 if (remote_host_list == NULL) {
1706 remote_host_list = g_hash_table_new (g_str_hash, g_str_equal);
1709 iftype_cbx = iftype_combo_box_new();
1710 #if GTK_CHECK_VERSION(2,6,0)
1711 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (iftype_cbx),
1712 iftype_combo_is_separator, NULL, NULL);
1714 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IFTYPE_CBX_KEY, iftype_cbx);
1715 gtk_tooltips_set_tip(tooltips, iftype_cbx,
1716 "Choose to capture from local or remote interfaces.", NULL);
1717 gtk_box_pack_start(GTK_BOX(if_hb), iftype_cbx, FALSE, FALSE, 0);
1720 if_cb = gtk_combo_new();
1721 combo_list = build_capture_combo_list(if_list, TRUE);
1722 if (combo_list != NULL)
1723 gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
1724 if (global_capture_opts.iface == NULL && prefs.capture_device != NULL) {
1725 /* No interface was specified on the command line or in a previous
1726 capture, but there is one specified in the preferences file;
1727 make the one from the preferences file the default */
1728 if_device = g_strdup(prefs.capture_device);
1729 global_capture_opts.iface = g_strdup(get_if_name(if_device));
1730 global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
1733 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY, if_cb);
1736 /* get the airpcap interface (if it IS an airpcap interface, and update the
1737 toolbar... and of course enable the advanced button...)*/
1738 airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,global_capture_opts.iface);
1741 if (global_capture_opts.iface != NULL) {
1742 if_device = build_capture_combo_name(if_list, global_capture_opts.iface);
1743 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), if_device);
1745 } else if (combo_list != NULL) {
1746 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry),
1747 (char *)combo_list->data);
1749 free_capture_combo_list(combo_list);
1750 #ifdef HAVE_PCAP_REMOTE
1751 /* Only delete if fetched local */
1752 if (global_capture_opts.src_type == CAPTURE_IFLOCAL)
1754 free_interface_list(if_list);
1755 gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry,
1756 "Choose which interface (network adapter) will be used to capture packets from. "
1757 "Be sure to select the correct one, as it's a common mistake to select the wrong interface.", NULL);
1758 gtk_box_pack_start(GTK_BOX(if_hb), if_cb, TRUE, TRUE, 3);
1760 if_ip_hb = gtk_hbox_new(FALSE, 3);
1761 gtk_box_pack_start(GTK_BOX(capture_vb), if_ip_hb, FALSE, FALSE, 0);
1763 if_ip_eb = gtk_event_box_new();
1764 gtk_event_box_set_visible_window (GTK_EVENT_BOX(if_ip_eb), FALSE);
1765 gtk_box_pack_start(GTK_BOX(if_ip_hb), if_ip_eb, TRUE, TRUE, 3);
1766 gtk_tooltips_set_tip(tooltips, if_ip_eb, "Lists the IP address(es) "
1767 "assigned to the selected interface. If there are "
1768 "more addresses than will fit in the window, the "
1769 "first few and the last few will be shown with \"...\" "
1773 if_ip_lb = gtk_label_new("");
1774 gtk_misc_set_alignment(GTK_MISC(if_ip_lb), 0, 0); /* Left justified */
1775 gtk_container_add(GTK_CONTAINER(if_ip_eb), if_ip_lb);
1777 main_hb = gtk_hbox_new(FALSE, 5);
1778 gtk_container_set_border_width(GTK_CONTAINER(main_hb), 0);
1779 gtk_container_add(GTK_CONTAINER(capture_vb), main_hb);
1781 left_vb = gtk_vbox_new(FALSE, 0);
1782 gtk_container_set_border_width(GTK_CONTAINER(left_vb), 0);
1783 gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0);
1785 #if defined (HAVE_AIRPCAP) || defined (HAVE_PCAP_REMOTE) || defined (HAVE_PCAP_CREATE)
1786 /* Avoid adding the right vbox if not needed, because it steals 3 pixels */
1787 right_vb = gtk_vbox_new(FALSE, 3);
1788 gtk_container_set_border_width(GTK_CONTAINER(right_vb), 0);
1789 gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 3);
1793 linktype_hb = gtk_hbox_new(FALSE, 3);
1794 gtk_box_pack_start(GTK_BOX(left_vb), linktype_hb, FALSE, FALSE, 0);
1796 linktype_lb = gtk_label_new("Link-layer header type:");
1797 gtk_box_pack_start(GTK_BOX(linktype_hb), linktype_lb, FALSE, FALSE, 3);
1799 linktype_om = gtk_option_menu_new();
1800 g_object_set_data(G_OBJECT(linktype_om), E_CAP_LT_OM_LABEL_KEY, linktype_lb);
1801 /* Default to "use the default" */
1802 /* Datalink menu index is not resetted, it will be restored with last used value */
1803 /* g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(-1)); */
1804 g_object_set_data(G_OBJECT(linktype_om), E_CAP_IFACE_KEY, if_ip_lb);
1806 if (cap_settings_history == NULL) {
1807 cap_settings_history = g_hash_table_new(g_str_hash, g_str_equal);
1810 * XXX - in some cases, this is "multiple link-layer header types", e.g.
1811 * some 802.11 interfaces on FreeBSD 5.2 and later, where you can request
1812 * fake Ethernet, 802.11, or 802.11-plus-radio-information headers.
1814 * In other cases, it's "multiple link-layer types", e.g., with recent
1815 * versions of libpcap, a DAG card on an "HDLC" WAN, where you can
1816 * request Cisco HDLC or PPP depending on what type of traffic is going
1817 * over the WAN, or an Ethernet interface, where you can request Ethernet
1818 * or DOCSIS, the latter being for some Cisco cable modem equipment that
1819 * can be configured to send raw DOCSIS frames over an Ethernet inside
1820 * Ethernet low-level framing, for traffic capture purposes.
1822 * We leave it as "multiple link-layer types" for now.
1824 gtk_tooltips_set_tip(tooltips, linktype_om,
1825 "The selected interface supports multiple link-layer types; select the desired one.", NULL);
1826 gtk_box_pack_start (GTK_BOX(linktype_hb), linktype_om, FALSE, FALSE, 0);
1827 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_LT_OM_KEY, linktype_om);
1828 g_signal_connect(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "changed",
1829 G_CALLBACK(capture_prep_interface_changed_cb), NULL);
1831 /* Promiscuous mode row */
1832 promisc_cb = gtk_check_button_new_with_mnemonic(
1833 "Capture packets in _promiscuous mode");
1834 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(promisc_cb),
1835 global_capture_opts.promisc_mode);
1836 gtk_tooltips_set_tip(tooltips, promisc_cb,
1837 "Usually a network adapter will only capture the traffic sent to its own network address. "
1838 "If you want to capture all traffic that the network adapter can \"see\", mark this option. "
1839 "See the FAQ for some more details of capturing packets from a switched network.", NULL);
1840 gtk_container_add(GTK_CONTAINER(left_vb), promisc_cb);
1842 #ifdef HAVE_PCAP_CREATE
1843 /* Monitor mode row */
1844 monitor_cb = gtk_check_button_new_with_mnemonic(
1845 "Capture packets in monitor mode");
1846 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(monitor_cb),
1847 global_capture_opts.monitor_mode);
1848 g_signal_connect(monitor_cb, "toggled",
1849 G_CALLBACK(capture_prep_monitor_changed_cb), NULL);
1850 gtk_tooltips_set_tip(tooltips, monitor_cb,
1851 "Usually a Wi-Fi adapter will, even in promiscuous mode, only capture the traffic on the BSS to which it's associated. "
1852 "If you want to capture all traffic that the Wi-Fi adapter can \"receive\", mark this option. "
1853 "In order to see IEEE 802.11 headers or to see radio information for captured packets,"
1854 "it might be necessary to turn this option on.\n\n"
1855 "Note that, in monitor mode, the adapter might disassociate from the network to which it's associated.", NULL);
1856 gtk_container_add(GTK_CONTAINER(left_vb), monitor_cb);
1859 * Attach this now, so that set_if_capabilities() can change its
1862 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_MONITOR_KEY, monitor_cb);
1866 * This controls the sensitivity of both the link-type list and, if
1867 * you have it, the monitor mode checkbox. That's why we do this
1870 set_if_capabilities(FALSE);
1873 pcap_ng_cb = gtk_check_button_new_with_mnemonic("Capture packets in pcap-ng format (experimental)");
1874 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcap_ng_cb), global_capture_opts.use_pcapng);
1875 gtk_tooltips_set_tip(tooltips, pcap_ng_cb, "Capture packets in the next-generation capture file format. "
1876 "This is still experimental.", NULL);
1877 gtk_container_add(GTK_CONTAINER(left_vb), pcap_ng_cb);
1879 /* Capture length row */
1880 snap_hb = gtk_hbox_new(FALSE, 3);
1881 gtk_container_add(GTK_CONTAINER(left_vb), snap_hb);
1883 snap_cb = gtk_check_button_new_with_mnemonic("_Limit each packet to");
1884 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(snap_cb),
1885 global_capture_opts.has_snaplen);
1886 g_signal_connect(snap_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
1887 gtk_tooltips_set_tip(tooltips, snap_cb,
1888 "Limit the maximum number of bytes to be captured from each packet. This size includes the "
1889 "link-layer header and all subsequent headers. ", NULL);
1890 gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0);
1892 snap_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.snaplen,
1893 MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0);
1894 snap_sb = gtk_spin_button_new (snap_adj, 0, 0);
1895 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE);
1896 gtk_widget_set_size_request(snap_sb, 80, -1);
1897 gtk_box_pack_start (GTK_BOX(snap_hb), snap_sb, FALSE, FALSE, 0);
1899 snap_lb = gtk_label_new("bytes");
1900 gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5f);
1901 gtk_box_pack_start(GTK_BOX(snap_hb), snap_lb, FALSE, FALSE, 0);
1904 filter_hb = gtk_hbox_new(FALSE, 3);
1905 gtk_box_pack_start(GTK_BOX(capture_vb), filter_hb, FALSE, FALSE, 0);
1907 filter_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY);
1908 g_signal_connect(filter_bt, "clicked", G_CALLBACK(capture_filter_construct_cb), NULL);
1909 g_signal_connect(filter_bt, "destroy", G_CALLBACK(filter_button_destroy_cb), NULL);
1910 gtk_tooltips_set_tip(tooltips, filter_bt,
1911 "Select a capture filter to reduce the amount of packets to be captured. "
1912 "See \"Capture Filters\" in the online help for further information how to use it.",
1914 gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, FALSE, 3);
1916 /* Create the capture filter combo */
1917 filter_cm = gtk_combo_new();
1919 cfilter_list = g_object_get_data(G_OBJECT(top_level), E_CFILTER_FL_KEY);
1920 gtk_combo_disable_activate(GTK_COMBO(filter_cm));
1921 gtk_combo_set_case_sensitive(GTK_COMBO(filter_cm), TRUE);
1922 g_object_set_data(G_OBJECT(top_level), E_CFILTER_FL_KEY, cfilter_list);
1923 g_object_set_data(G_OBJECT(top_level), E_CFILTER_CM_KEY, filter_cm);
1924 filter_te = GTK_COMBO(filter_cm)->entry;
1926 if (cfilter_list != NULL)
1927 gtk_combo_set_popdown_strings(GTK_COMBO(filter_cm), cfilter_list);
1928 if (global_capture_opts.cfilter)
1929 gtk_entry_set_text(GTK_ENTRY(filter_te), global_capture_opts.cfilter);
1930 gtk_tooltips_set_tip(tooltips, filter_te,
1931 "Enter a capture filter to reduce the amount of packets to be captured. "
1932 "See \"Capture Filters\" in the online help for further information how to use it.",
1934 gtk_box_pack_start(GTK_BOX(filter_hb), filter_cm, TRUE, TRUE, 3);
1936 /* let an eventually capture filters dialog know the text entry to fill in */
1937 g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
1939 #ifdef HAVE_PCAP_CREATE
1940 compile_bt = gtk_button_new_with_label("Compile BPF");
1941 g_signal_connect(compile_bt, "clicked", G_CALLBACK(capture_filter_compile_cb), NULL);
1942 gtk_tooltips_set_tip(tooltips, compile_bt,
1943 "Compile the capture filter expression and show the BPF code.",
1945 gtk_box_pack_start(GTK_BOX(filter_hb), compile_bt, FALSE, FALSE, 3);
1950 advanced_bt = gtk_button_new_with_label("Wireless Settings");
1952 /* Both the callback and the data are global */
1953 g_signal_connect(advanced_bt,"clicked", G_CALLBACK(options_airpcap_advanced_cb),airpcap_tb);
1954 g_object_set_data(G_OBJECT(GTK_ENTRY(GTK_COMBO(if_cb)->entry)),AIRPCAP_OPTIONS_ADVANCED_KEY,advanced_bt);
1956 if(airpcap_if_selected != NULL) {
1957 /* It is an airpcap interface */
1958 gtk_widget_set_sensitive(advanced_bt,TRUE);
1960 gtk_widget_set_sensitive(advanced_bt,FALSE);
1963 gtk_box_pack_start(GTK_BOX(right_vb),advanced_bt,FALSE,FALSE,0);
1964 gtk_widget_show(advanced_bt);
1967 #ifdef HAVE_PCAP_REMOTE
1968 remote_bt = gtk_button_new_with_label("Remote Settings");
1969 gtk_tooltips_set_tip(tooltips, remote_bt, "Various settings for remote capture.", NULL);
1971 /* Both the callback and the data are global */
1972 g_signal_connect(remote_bt,"clicked", G_CALLBACK(options_remote_cb),NULL);
1973 g_object_set_data(G_OBJECT(iftype_cbx), E_OPT_REMOTE_BT_KEY, remote_bt);
1975 if (global_capture_opts.src_type == CAPTURE_IFREMOTE) {
1976 gtk_widget_set_sensitive(remote_bt, TRUE);
1978 gtk_widget_set_sensitive(remote_bt, FALSE);
1981 gtk_box_pack_start(GTK_BOX(right_vb),remote_bt,FALSE,FALSE,0);
1982 gtk_widget_show(remote_bt);
1985 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
1986 buffer_size_hb = gtk_hbox_new(FALSE, 3);
1987 buffer_size_lb = gtk_label_new("Buffer size:");
1988 gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_lb, FALSE, FALSE, 0);
1990 buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.buffer_size,
1991 1, 65535, 1.0, 10.0, 0.0);
1992 buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0);
1993 gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) global_capture_opts.buffer_size);
1994 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE);
1995 gtk_widget_set_size_request(buffer_size_sb, 80, -1);
1996 gtk_tooltips_set_tip(tooltips, buffer_size_sb,
1997 "The memory buffer size used while capturing. If you notice packet drops, you can try to increase this size.", NULL);
1998 gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_sb, FALSE, FALSE, 0);
2000 buffer_size_lb = gtk_label_new("megabyte(s)");
2001 gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_lb, FALSE, FALSE, 3);
2002 gtk_box_pack_start (GTK_BOX(right_vb), buffer_size_hb, FALSE, FALSE, 0);
2005 main_hb = gtk_hbox_new(FALSE, 5);
2006 gtk_container_set_border_width(GTK_CONTAINER(main_hb), 0);
2007 gtk_container_add(GTK_CONTAINER(main_vb), main_hb);
2009 left_vb = gtk_vbox_new(FALSE, 0);
2010 gtk_container_set_border_width(GTK_CONTAINER(left_vb), 0);
2011 gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0);
2013 right_vb = gtk_vbox_new(FALSE, 0);
2014 gtk_container_set_border_width(GTK_CONTAINER(right_vb), 0);
2015 gtk_box_pack_start(GTK_BOX(main_hb), right_vb, FALSE, FALSE, 0);
2017 /* Capture file-related options frame */
2018 file_fr = gtk_frame_new("Capture File(s)");
2019 gtk_container_add(GTK_CONTAINER(left_vb), file_fr);
2021 file_vb = gtk_vbox_new(FALSE, 3);
2022 gtk_container_set_border_width(GTK_CONTAINER(file_vb), 5);
2023 gtk_container_add(GTK_CONTAINER(file_fr), file_vb);
2026 file_hb = gtk_hbox_new(FALSE, 3);
2027 gtk_box_pack_start(GTK_BOX(file_vb), file_hb, FALSE, FALSE, 0);
2029 file_lb = gtk_label_new("File:");
2030 gtk_box_pack_start(GTK_BOX(file_hb), file_lb, FALSE, FALSE, 3);
2032 file_te = gtk_entry_new();
2033 gtk_tooltips_set_tip(tooltips, file_te,
2034 "Enter the file name to which captured data will be written. "
2035 "If you don't enter something here, a temporary file will be used.",
2037 gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3);
2039 file_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
2040 gtk_tooltips_set_tip(tooltips, file_bt,
2041 "Select a file to which captured data will be written, "
2042 "instead of entering the file name directly. ",
2044 gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 0);
2046 g_signal_connect(file_bt, "clicked", G_CALLBACK(capture_prep_file_cb), file_te);
2048 /* multiple files table */
2049 multi_tb = gtk_table_new(5, 3, FALSE);
2050 gtk_table_set_row_spacings(GTK_TABLE(multi_tb), 1);
2051 gtk_table_set_col_spacings(GTK_TABLE(multi_tb), 3);
2052 gtk_box_pack_start(GTK_BOX(file_vb), multi_tb, FALSE, FALSE, 0);
2055 /* multiple files row */
2056 multi_files_on_cb = gtk_check_button_new_with_mnemonic("Use _multiple files");
2057 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb),
2058 global_capture_opts.multi_files_on);
2059 g_signal_connect(multi_files_on_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity),
2061 gtk_tooltips_set_tip(tooltips, multi_files_on_cb,
2062 "Instead of using a single capture file, multiple files will be created. "
2063 "The generated file names will contain an incrementing number and the start time of the capture.", NULL);
2064 gtk_table_attach_defaults(GTK_TABLE(multi_tb), multi_files_on_cb, 0, 1, row, row+1);
2067 /* Ring buffer filesize row */
2068 ring_filesize_cb = gtk_check_button_new_with_label("Next file every");
2069 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb),
2070 global_capture_opts.has_autostop_filesize || !global_capture_opts.has_file_duration);
2071 g_signal_connect(ring_filesize_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2072 gtk_tooltips_set_tip(tooltips, ring_filesize_cb,
2073 "If the selected file size is exceeded, capturing switches to the next file.\n"
2074 "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
2076 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cb, 0, 1, row, row+1);
2078 ring_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
2079 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2080 ring_filesize_sb = gtk_spin_button_new (ring_filesize_adj, 0, 0);
2081 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ring_filesize_sb), TRUE);
2082 gtk_widget_set_size_request(ring_filesize_sb, 80, -1);
2083 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_sb, 1, 2, row, row+1);
2085 ring_filesize_cbx = size_unit_combo_box_new(global_capture_opts.autostop_filesize);
2086 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ring_filesize_cbx, 2, 3, row, row+1);
2088 value = size_unit_combo_box_set_value(global_capture_opts.autostop_filesize);
2089 gtk_adjustment_set_value(ring_filesize_adj, (gfloat) value);
2093 /* Ring buffer duration row */
2094 file_duration_cb = gtk_check_button_new_with_label("Next file every");
2095 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_duration_cb),
2096 global_capture_opts.has_file_duration);
2097 g_signal_connect(file_duration_cb, "toggled",
2098 G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2099 gtk_tooltips_set_tip(tooltips, file_duration_cb,
2100 "If the selected duration is exceeded, capturing switches to the next file.\n"
2101 "PLEASE NOTE: at least one of the \"Next file every\" options MUST be selected.",
2103 gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cb, 0, 1, row, row+1);
2105 file_duration_adj = (GtkAdjustment *)gtk_adjustment_new(0.0,
2106 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2107 file_duration_sb = gtk_spin_button_new (file_duration_adj, 0, 0);
2108 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (file_duration_sb), TRUE);
2109 gtk_widget_set_size_request(file_duration_sb, 80, -1);
2110 gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_sb, 1, 2, row, row+1);
2112 file_duration_cbx = time_unit_combo_box_new(global_capture_opts.file_duration);
2113 gtk_table_attach_defaults(GTK_TABLE(multi_tb), file_duration_cbx, 2, 3, row, row+1);
2115 value = time_unit_combo_box_convert_value(global_capture_opts.file_duration);
2116 gtk_adjustment_set_value(file_duration_adj, (gfloat) value);
2119 /* Ring buffer files row */
2120 ringbuffer_nbf_cb = gtk_check_button_new_with_label("Ring buffer with");
2121 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb),
2122 global_capture_opts.has_ring_num_files);
2123 g_signal_connect(ringbuffer_nbf_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2124 gtk_tooltips_set_tip(tooltips, ringbuffer_nbf_cb,
2125 "After capturing has switched to the next file and the given number of files has exceeded, "
2126 "the oldest file will be removed.",
2128 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_cb, 0, 1, row, row+1);
2130 ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) global_capture_opts.ring_num_files,
2131 2/*RINGBUFFER_MIN_NUM_FILES*/, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0);
2132 ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0);
2133 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE);
2134 gtk_widget_set_size_request(ringbuffer_nbf_sb, 80, -1);
2135 g_signal_connect(ringbuffer_nbf_sb, "changed", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2136 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_sb, 1, 2, row, row+1);
2138 ringbuffer_nbf_lb = gtk_label_new("files");
2139 gtk_misc_set_alignment(GTK_MISC(ringbuffer_nbf_lb), 0, 0.5f);
2140 gtk_table_attach_defaults(GTK_TABLE(multi_tb), ringbuffer_nbf_lb, 2, 3, row, row+1);
2144 stop_files_cb = gtk_check_button_new_with_label("Stop capture after");
2145 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_files_cb),
2146 global_capture_opts.has_autostop_files);
2147 g_signal_connect(stop_files_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2148 gtk_tooltips_set_tip(tooltips, stop_files_cb,
2149 "Stop capturing after the given number of \"file switches\" have been done.", NULL);
2150 gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_cb, 0, 1, row, row+1);
2152 stop_files_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)global_capture_opts.autostop_files,
2153 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2154 stop_files_sb = gtk_spin_button_new (stop_files_adj, 0, 0);
2155 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_files_sb), TRUE);
2156 gtk_widget_set_size_request(stop_files_sb, 80, -1);
2157 gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_sb, 1, 2, row, row+1);
2159 stop_files_lb = gtk_label_new("file(s)");
2160 gtk_misc_set_alignment(GTK_MISC(stop_files_lb), 0, 0.5f);
2161 gtk_table_attach_defaults(GTK_TABLE(multi_tb), stop_files_lb, 2, 3, row, row+1);
2164 /* Capture limits frame */
2165 limit_fr = gtk_frame_new("Stop Capture ...");
2166 gtk_container_add(GTK_CONTAINER(left_vb), limit_fr);
2168 limit_vb = gtk_vbox_new(FALSE, 3);
2169 gtk_container_set_border_width(GTK_CONTAINER(limit_vb), 5);
2170 gtk_container_add(GTK_CONTAINER(limit_fr), limit_vb);
2173 limit_tb = gtk_table_new(3, 3, FALSE);
2174 gtk_table_set_row_spacings(GTK_TABLE(limit_tb), 1);
2175 gtk_table_set_col_spacings(GTK_TABLE(limit_tb), 3);
2176 gtk_box_pack_start(GTK_BOX(limit_vb), limit_tb, FALSE, FALSE, 0);
2179 /* Packet count row */
2180 stop_packets_cb = gtk_check_button_new_with_label("... after");
2181 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_packets_cb),
2182 global_capture_opts.has_autostop_packets);
2183 g_signal_connect(stop_packets_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2184 gtk_tooltips_set_tip(tooltips, stop_packets_cb,
2185 "Stop capturing after the given number of packets have been captured.", NULL);
2186 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_cb, 0, 1, row, row+1);
2188 stop_packets_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat)global_capture_opts.autostop_packets,
2189 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2190 stop_packets_sb = gtk_spin_button_new (stop_packets_adj, 0, 0);
2191 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_packets_sb), TRUE);
2192 gtk_widget_set_size_request(stop_packets_sb, 80, -1);
2193 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_sb, 1, 2, row, row+1);
2195 stop_packets_lb = gtk_label_new("packet(s)");
2196 gtk_misc_set_alignment(GTK_MISC(stop_packets_lb), 0, 0.5f);
2197 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_packets_lb, 2, 3, row, row+1);
2201 stop_filesize_cb = gtk_check_button_new_with_label("... after");
2202 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_filesize_cb),
2203 global_capture_opts.has_autostop_filesize);
2204 g_signal_connect(stop_filesize_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2205 gtk_tooltips_set_tip(tooltips, stop_filesize_cb,
2206 "Stop capturing after the given amount of capture data has been captured.", NULL);
2207 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cb, 0, 1, row, row+1);
2209 stop_filesize_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
2210 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2211 stop_filesize_sb = gtk_spin_button_new (stop_filesize_adj, 0, 0);
2212 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_filesize_sb), TRUE);
2213 gtk_widget_set_size_request(stop_filesize_sb, 80, -1);
2214 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_sb, 1, 2, row, row+1);
2216 stop_filesize_cbx = size_unit_combo_box_new(global_capture_opts.autostop_filesize);
2217 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_filesize_cbx, 2, 3, row, row+1);
2219 value = size_unit_combo_box_set_value(global_capture_opts.autostop_filesize);
2220 gtk_adjustment_set_value(stop_filesize_adj, (gfloat) value);
2225 stop_duration_cb = gtk_check_button_new_with_label("... after");
2226 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stop_duration_cb),
2227 global_capture_opts.has_autostop_duration);
2228 g_signal_connect(stop_duration_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2229 gtk_tooltips_set_tip(tooltips, stop_duration_cb,
2230 "Stop capturing after the given time is exceeded.", NULL);
2231 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cb, 0, 1, row, row+1);
2233 stop_duration_adj = (GtkAdjustment *) gtk_adjustment_new(0.0,
2234 1, (gfloat)INT_MAX, 1.0, 10.0, 0.0);
2235 stop_duration_sb = gtk_spin_button_new (stop_duration_adj, 0, 0);
2236 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (stop_duration_sb), TRUE);
2237 gtk_widget_set_size_request(stop_duration_sb, 80, -1);
2238 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_sb, 1, 2, row, row+1);
2240 stop_duration_cbx = time_unit_combo_box_new(global_capture_opts.autostop_duration);
2241 gtk_table_attach_defaults(GTK_TABLE(limit_tb), stop_duration_cbx, 2, 3, row, row+1);
2243 value = time_unit_combo_box_convert_value(global_capture_opts.autostop_duration);
2244 gtk_adjustment_set_value(stop_duration_adj, (gfloat) value);
2247 /* Display-related options frame */
2248 display_fr = gtk_frame_new("Display Options");
2249 gtk_container_add(GTK_CONTAINER(right_vb), display_fr);
2251 display_vb = gtk_vbox_new(FALSE, 0);
2252 gtk_container_set_border_width(GTK_CONTAINER(display_vb), 5);
2253 gtk_container_add(GTK_CONTAINER(display_fr), display_vb);
2255 /* "Update display in real time" row */
2256 sync_cb = gtk_check_button_new_with_mnemonic(
2257 "_Update list of packets in real time");
2258 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sync_cb),
2259 global_capture_opts.real_time_mode);
2260 g_signal_connect(sync_cb, "toggled", G_CALLBACK(capture_prep_adjust_sensitivity), cap_open_w);
2261 gtk_tooltips_set_tip(tooltips, sync_cb,
2262 "Using this option will show the captured packets immediately on the main screen. "
2263 "Please note: this will slow down capturing, so increased packet drops might appear.", NULL);
2264 gtk_container_add(GTK_CONTAINER(display_vb), sync_cb);
2266 /* "Auto-scroll live update" row */
2267 auto_scroll_cb = gtk_check_button_new_with_mnemonic(
2268 "_Automatic scrolling in live capture");
2269 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auto_scroll_cb), auto_scroll_live);
2270 gtk_tooltips_set_tip(tooltips, auto_scroll_cb,
2271 "This will scroll the \"Packet List\" automatically to the latest captured packet, "
2272 "when the \"Update List of packets in real time\" option is used.", NULL);
2273 gtk_container_add(GTK_CONTAINER(display_vb), auto_scroll_cb);
2275 /* "Hide capture info" row */
2276 hide_info_cb = gtk_check_button_new_with_mnemonic(
2277 "_Hide capture info dialog");
2278 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_info_cb), !global_capture_opts.show_info);
2279 gtk_tooltips_set_tip(tooltips, hide_info_cb,
2280 "Hide the capture info dialog while capturing.", NULL);
2281 gtk_container_add(GTK_CONTAINER(display_vb), hide_info_cb);
2283 /* Name Resolution frame */
2284 resolv_fr = gtk_frame_new("Name Resolution");
2285 gtk_container_add(GTK_CONTAINER(right_vb), resolv_fr);
2287 resolv_vb = gtk_vbox_new(FALSE, 0);
2288 gtk_container_set_border_width(GTK_CONTAINER(resolv_vb), 5);
2289 gtk_container_add(GTK_CONTAINER(resolv_fr), resolv_vb);
2291 m_resolv_cb = gtk_check_button_new_with_mnemonic(
2292 "Enable _MAC name resolution");
2293 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_resolv_cb),
2294 g_resolv_flags & RESOLV_MAC);
2295 gtk_tooltips_set_tip(tooltips, m_resolv_cb,
2296 "Perform MAC layer name resolution while capturing.", NULL);
2297 gtk_container_add(GTK_CONTAINER(resolv_vb), m_resolv_cb);
2299 n_resolv_cb = gtk_check_button_new_with_mnemonic(
2300 "Enable _network name resolution");
2301 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(n_resolv_cb),
2302 g_resolv_flags & RESOLV_NETWORK);
2303 gtk_tooltips_set_tip(tooltips, n_resolv_cb,
2304 "Perform network layer name resolution while capturing.", NULL);
2305 gtk_container_add(GTK_CONTAINER(resolv_vb), n_resolv_cb);
2307 t_resolv_cb = gtk_check_button_new_with_mnemonic(
2308 "Enable _transport name resolution");
2309 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(t_resolv_cb),
2310 g_resolv_flags & RESOLV_TRANSPORT);
2311 gtk_tooltips_set_tip(tooltips, t_resolv_cb,
2312 "Perform transport layer name resolution while capturing.", NULL);
2313 gtk_container_add(GTK_CONTAINER(resolv_vb), t_resolv_cb);
2315 /* Button row: "Start", "Cancel" and "Help" buttons */
2316 bbox = dlg_button_row_new(WIRESHARK_STOCK_CAPTURE_START, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
2317 gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
2319 ok_bt = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CAPTURE_START);
2320 g_signal_connect(ok_bt, "clicked", G_CALLBACK(capture_start_cb), cap_open_w);
2321 gtk_tooltips_set_tip(tooltips, ok_bt,
2322 "Start the capture process.", NULL);
2324 cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
2325 gtk_tooltips_set_tip(tooltips, cancel_bt,
2326 "Cancel and exit dialog.", NULL);
2327 window_set_cancel_button(cap_open_w, cancel_bt, capture_cancel_cb);
2329 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
2330 gtk_tooltips_set_tip(tooltips, help_bt,
2331 "Show help about capturing.", NULL);
2332 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_CAPTURE_OPTIONS_DIALOG);
2334 gtk_widget_grab_default(ok_bt);
2336 /* Attach pointers to needed widgets to the capture prefs window/object */
2337 #ifdef HAVE_PCAP_REMOTE
2338 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_REMOTE_DIALOG_PTR_KEY, NULL);
2340 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_CB_KEY, snap_cb);
2341 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_SB_KEY, snap_sb);
2342 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2343 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb);
2345 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PROMISC_KEY, promisc_cb);
2346 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PCAP_NG_KEY, pcap_ng_cb);
2347 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILT_KEY, filter_te);
2348 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_TE_KEY, file_te);
2349 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_MULTI_FILES_ON_CB_KEY, multi_files_on_cb);
2350 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_CB_KEY, ringbuffer_nbf_cb);
2351 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_SB_KEY, ringbuffer_nbf_sb);
2352 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_NBF_LB_KEY, ringbuffer_nbf_lb);
2353 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_CB_KEY, ring_filesize_cb);
2354 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_SB_KEY, ring_filesize_sb);
2355 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_RING_FILESIZE_CBX_KEY, ring_filesize_cbx);
2356 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_CB_KEY, file_duration_cb);
2357 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_SB_KEY, file_duration_sb);
2358 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_FILE_DURATION_CBX_KEY, file_duration_cbx);
2359 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SYNC_KEY, sync_cb);
2360 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_AUTO_SCROLL_KEY, auto_scroll_cb);
2361 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_HIDE_INFO_KEY, hide_info_cb);
2362 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_CB_KEY, stop_packets_cb);
2363 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_SB_KEY, stop_packets_sb);
2364 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_PACKETS_LB_KEY, stop_packets_lb);
2365 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_CB_KEY, stop_filesize_cb);
2366 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_SB_KEY, stop_filesize_sb);
2367 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILESIZE_CBX_KEY, stop_filesize_cbx);
2368 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_CB_KEY, stop_duration_cb);
2369 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_SB_KEY, stop_duration_sb);
2370 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_DURATION_CBX_KEY, stop_duration_cbx);
2371 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_CB_KEY, stop_files_cb);
2372 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_SB_KEY, stop_files_sb);
2373 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_STOP_FILES_LB_KEY, stop_files_lb);
2374 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_M_RESOLVE_KEY, m_resolv_cb);
2375 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_N_RESOLVE_KEY, n_resolv_cb);
2376 g_object_set_data(G_OBJECT(cap_open_w), E_CAP_T_RESOLVE_KEY, t_resolv_cb);
2378 /* Set the sensitivity of various widgets as per the settings of other
2380 capture_prep_adjust_sensitivity(NULL, cap_open_w);
2382 /* Catch the "activate" signal on the text
2383 entries, so that if the user types Return there, we act as if the
2384 "OK" button had been selected, as happens if Return is typed if some
2385 widget that *doesn't* handle the Return key has the input focus. */
2386 dlg_set_activate(GTK_COMBO(if_cb)->entry, ok_bt);
2387 dlg_set_activate(filter_te, ok_bt);
2388 dlg_set_activate(file_te, ok_bt);
2390 /* XXX - why does not
2392 gtk_widget_grab_focus(if_cb);
2394 give the initial focus to the "Interface" combo box?
2396 Or should I phrase that as "why does GTK+ continually frustrate
2397 attempts to make GUIs driveable from the keyboard?" We have to
2398 go catch the activate signal on every single GtkEntry widget
2399 (rather than having widgets whose activate signal is *not*
2400 caught not catch the Return keystroke, so that it passes on,
2401 ultimately, to the window, which can activate the default
2402 widget, i.e. the "OK" button); we have to catch the "key_press_event"
2403 signal and have the handler check for ESC, so that we can have ESC
2404 activate the "Cancel" button; in order to support Alt+<key> mnemonics
2405 for buttons and the like, we may have to construct an accelerator
2406 group by hand and set up the accelerators by hand (if that even
2407 works - I've not tried it yet); we have to do a "gtk_widget_grab_focus()"
2408 to keep some container widget from getting the initial focus, so that
2409 you don't have to tab into the first widget in order to start typing
2410 in it; and it now appears that you simply *can't* make a combo box
2411 get the initial focus, at least not in the obvious fashion. Sigh.... */
2413 g_signal_connect(cap_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
2414 g_signal_connect(cap_open_w, "destroy", G_CALLBACK(capture_prep_destroy_cb), NULL);
2416 /* Give the initial focus to the "Filter" entry box. */
2417 gtk_widget_grab_focus(filter_te);
2419 gtk_widget_show_all(cap_open_w);
2420 window_present(cap_open_w);
2423 /* everythings prepared, now it's really time to start the capture */
2425 capture_start_confirmed(void)
2429 /* init iface, if never used before */
2430 /* XXX - would better be doing this in main.c */
2431 if(global_capture_opts.iface == NULL) {
2433 const gchar *if_name;
2435 /* did the user ever selected a capture interface before? */
2436 if(prefs.capture_device == NULL) {
2437 simple_dialog(ESD_TYPE_CONFIRMATION,
2439 "%sNo capture interface selected!%s\n\n"
2440 "To select an interface use:\n\n"
2441 "Capture->Options (until Wireshark is stopped)\n"
2442 "Edit->Preferences/Capture (permanent, if saved)",
2443 simple_dialog_primary_start(), simple_dialog_primary_end());
2446 if_device = g_strdup(prefs.capture_device);
2447 if_name = get_if_name(if_device);
2448 global_capture_opts.iface = g_strdup(if_name);
2449 global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
2454 /* XXX - we might need to init other pref data as well... */
2455 menu_auto_scroll_live_changed(auto_scroll_live);
2457 if (capture_start(&global_capture_opts)) {
2458 /* The capture succeeded, which means the capture filter syntax is
2459 valid; add this capture filter to the recent capture filter list. */
2460 cfilter_combo_add_recent(global_capture_opts.cfilter);
2464 /* user confirmed the "Save capture file..." dialog */
2466 capture_start_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
2470 /* save file first */
2471 file_save_as_cmd(after_save_capture_dialog, data);
2473 case(ESD_BTN_DONT_SAVE):
2474 /* XXX - unlink old file? */
2475 /* start the capture */
2476 capture_start_confirmed();
2478 case(ESD_BTN_CANCEL):
2481 g_assert_not_reached();
2485 /* user pressed the "Start" button (in dialog or toolbar) */
2487 capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
2491 cap_settings_t *cap_settings_p = NULL;
2494 airpcap_if_active = airpcap_if_selected;
2495 airpcap_set_toolbar_start_capture(airpcap_if_active);
2499 /* Is WPcap loaded? */
2501 char * err_msg = cant_load_winpcap_err("Wireshark");
2503 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_msg);
2511 * There's an options dialog; get the values from it and close it.
2515 success = capture_dlg_prep(cap_open_w);
2516 window_destroy(GTK_WIDGET(cap_open_w));
2518 return; /* error in options dialog */
2521 if (global_capture_opts.iface == NULL) {
2522 if (prefs.capture_device == NULL) {
2523 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2524 "You didn't specify an interface on which to capture packets.");
2527 if_name = g_strdup(get_if_name(prefs.capture_device));
2529 if_name = g_strdup(global_capture_opts.iface);
2532 if (cap_settings_history != NULL) {
2533 cap_settings_p = g_hash_table_lookup(cap_settings_history, if_name);
2534 if (cap_settings_p == NULL) {
2535 cap_settings_p = g_malloc(sizeof (cap_settings_t));
2536 g_hash_table_insert(cap_settings_history, if_name, cap_settings_p);
2540 cap_settings_p->monitor_mode = global_capture_opts.monitor_mode;
2541 cap_settings_p->linktype = global_capture_opts.linktype;
2543 global_capture_opts.monitor_mode = prefs_capture_device_monitor_mode(if_name);
2544 global_capture_opts.linktype = capture_dev_user_linktype_find(if_name);
2548 if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
2549 /* user didn't saved his current file, ask him */
2550 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
2551 "%sSave capture file before starting a new capture?%s\n\n"
2552 "If you start a new capture without saving, your current capture data will\nbe discarded.",
2553 simple_dialog_primary_start(), simple_dialog_primary_end());
2554 simple_dialog_set_cb(dialog, capture_start_answered_cb, NULL);
2556 /* unchanged file, just capture a new one */
2557 capture_start_confirmed();
2562 capture_cancel_cb(GtkWidget *win, gpointer data)
2564 #ifdef HAVE_PCAP_REMOTE
2565 if (g_hash_table_size (remote_host_list) == 0) {
2566 /* Ensure we fall back to local interfaces */
2567 global_capture_opts.src_type = CAPTURE_IFLOCAL;
2569 if (global_capture_opts.iface) {
2570 g_free (global_capture_opts.iface);
2571 global_capture_opts.iface = NULL;
2573 if (global_capture_opts.iface_descr) {
2574 g_free (global_capture_opts.iface_descr);
2575 global_capture_opts.iface_descr = NULL;
2580 window_cancel_button_cb (win, data);
2583 /* user selected a link type, convert to internal value */
2585 select_link_type_cb(GtkWidget *w, gpointer data)
2587 int new_linktype = GPOINTER_TO_INT(data);
2588 GtkWidget *linktype_om = g_object_get_data(G_OBJECT(w), E_CAP_LT_OM_KEY);
2589 int old_linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
2591 /* If the link is changed, update the menu and store the index and the value
2592 to reuse later when the dialog window will be reopened */
2593 if (old_linktype != new_linktype) {
2594 g_object_set_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY, GINT_TO_POINTER(new_linktype));
2595 global_capture_opts.linktype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY));
2599 #ifdef HAVE_PCAP_REMOTE
2601 free_remote_host (gpointer key _U_, gpointer value, gpointer user _U_)
2603 struct remote_host *rh = value;
2605 g_free (rh->remote_host);
2606 g_free (rh->remote_port);
2607 g_free (rh->auth_username);
2608 g_free (rh->auth_password);
2613 /* user selected an interface type (local/remote), convert to internal value) */
2615 select_if_type_cb(GtkComboBox *iftype_cbx, gpointer data _U_)
2617 int new_iftype = gtk_combo_box_get_active(GTK_COMBO_BOX(iftype_cbx));
2618 int old_iftype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
2619 E_CAP_CBX_IFTYPE_VALUE_KEY));
2620 int no_update = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx),
2621 E_CAP_CBX_IFTYPE_NOUPDATE_KEY));
2622 gint num_remote = g_hash_table_size (remote_host_list);
2624 if (new_iftype == CAPTURE_IFREMOTE) {
2625 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
2626 GINT_TO_POINTER(old_iftype));
2627 capture_remote_cb(GTK_WIDGET(iftype_cbx), FALSE);
2628 } else if (new_iftype != old_iftype) {
2629 if (new_iftype > CAPTURE_IFREMOTE) {
2630 #if GTK_CHECK_VERSION(2,6,0)
2631 if (new_iftype == num_remote + 4)
2633 if (new_iftype == num_remote + 2)
2636 /* The user selected the "Clear list" entry */
2637 new_iftype = CAPTURE_IFLOCAL;
2638 gtk_combo_box_set_active(GTK_COMBO_BOX(iftype_cbx), new_iftype);
2639 g_hash_table_foreach_remove (remote_host_list, free_remote_host, NULL);
2641 while (num_remote--) /* Remove separator lines and "Clear" item */
2642 gtk_combo_box_remove_text (iftype_cbx, 2);
2644 struct remote_host *rh;
2646 #if GTK_CHECK_VERSION(2,6,0)
2647 string = gtk_combo_box_get_active_text (GTK_COMBO_BOX(iftype_cbx));
2649 GtkTreeModel *model;
2652 model = gtk_combo_box_get_model(GTK_COMBO_BOX(iftype_cbx));
2653 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(iftype_cbx), &iter);
2654 gtk_tree_model_get(model, &iter, 0, &string, -1);
2656 rh = g_hash_table_lookup (remote_host_list, string);
2659 g_free(global_capture_opts.remote_host);
2660 global_capture_opts.remote_host = g_strdup(rh->remote_host);
2661 g_free(global_capture_opts.remote_port);
2662 global_capture_opts.remote_port = g_strdup(rh->remote_port);
2663 global_capture_opts.auth_type = rh->auth_type;
2664 if (global_capture_opts.auth_type == CAPTURE_AUTH_PWD && strlen(rh->auth_username) == 0) {
2665 /* Empty username, ask for one */
2666 capture_remote_cb(GTK_WIDGET(iftype_cbx), TRUE);
2669 /* Already entered username and password */
2670 g_free(global_capture_opts.auth_username);
2671 global_capture_opts.auth_username = g_strdup(rh->auth_username);
2672 g_free(global_capture_opts.auth_password);
2673 global_capture_opts.auth_password = g_strdup(rh->auth_password);
2678 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_PREV_IFTYPE_VALUE_KEY,
2679 GINT_TO_POINTER(old_iftype));
2680 g_object_set_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY,
2681 GINT_TO_POINTER(new_iftype));
2682 update_interface_list();
2688 /* user pressed "File" button */
2690 capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
2692 file_selection_browse(file_bt, file_te, "Wireshark: Specify a Capture File", FILE_SELECTION_WRITE_BROWSE);
2696 /* convert dialog settings into capture_opts values */
2698 capture_dlg_prep(gpointer parent_w) {
2699 GtkWidget *if_cb, *snap_cb, *snap_sb, *promisc_cb,
2700 #ifdef HAVE_PCAP_CREATE
2703 *pcap_ng_cb, *filter_te, *filter_cm,
2704 *file_te, *multi_files_on_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_cb,
2705 *linktype_om, *sync_cb, *auto_scroll_cb, *hide_info_cb,
2706 *stop_packets_cb, *stop_packets_sb,
2707 *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_cbx,
2708 *stop_duration_cb, *stop_duration_sb, *stop_duration_cbx,
2709 *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_cbx,
2710 *file_duration_cb, *file_duration_sb, *file_duration_cbx,
2711 *stop_files_cb, *stop_files_sb,
2712 *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
2713 #ifdef HAVE_PCAP_REMOTE
2714 GtkWidget *iftype_cbx;
2716 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2717 GtkWidget *buffer_size_sb;
2721 const gchar *if_name;
2722 const gchar *filter_text;
2723 const gchar *g_save_file;
2728 if_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFACE_KEY);
2729 #ifdef HAVE_PCAP_REMOTE
2730 iftype_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFTYPE_CBX_KEY);
2732 snap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_CB_KEY);
2733 snap_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_SB_KEY);
2734 linktype_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_LT_OM_KEY);
2735 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2736 buffer_size_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_BUFFER_SIZE_SB_KEY);
2738 promisc_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PROMISC_KEY);
2739 #ifdef HAVE_PCAP_CREATE
2740 monitor_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_MONITOR_KEY);
2742 pcap_ng_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PCAP_NG_KEY);
2743 filter_cm = g_object_get_data(G_OBJECT(top_level), E_CFILTER_CM_KEY);
2744 filter_te = GTK_COMBO(filter_cm)->entry;
2745 file_te = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_TE_KEY);
2746 multi_files_on_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_MULTI_FILES_ON_CB_KEY);
2747 ringbuffer_nbf_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_CB_KEY);
2748 ringbuffer_nbf_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_SB_KEY);
2749 ring_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CB_KEY);
2750 ring_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_SB_KEY);
2751 ring_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CBX_KEY);
2752 file_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CB_KEY);
2753 file_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_SB_KEY);
2754 file_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CBX_KEY);
2755 sync_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SYNC_KEY);
2756 auto_scroll_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_AUTO_SCROLL_KEY);
2757 hide_info_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_HIDE_INFO_KEY);
2758 stop_packets_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_CB_KEY);
2759 stop_packets_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_SB_KEY);
2760 stop_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CB_KEY);
2761 stop_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_SB_KEY);
2762 stop_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CBX_KEY);
2763 stop_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CB_KEY);
2764 stop_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_SB_KEY);
2765 stop_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CBX_KEY);
2766 stop_files_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_CB_KEY);
2767 stop_files_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_SB_KEY);
2768 m_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_M_RESOLVE_KEY);
2769 n_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_N_RESOLVE_KEY);
2770 t_resolv_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_T_RESOLVE_KEY);
2773 g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
2774 if_text = g_strstrip(entry_text);
2775 if_name = get_if_name(if_text);
2776 if (*if_name == '\0') {
2777 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2778 "You didn't specify an interface on which to capture packets.");
2782 g_free(global_capture_opts.iface);
2783 g_free(global_capture_opts.iface_descr);
2784 global_capture_opts.iface = g_strdup(if_name);
2785 global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);
2787 /* The Linktype will be stored when the interface will be changed, or if not, not datalink option is used,
2788 the acquisition will be performed on the default datalink for the device */
2789 /* global_capture_opts.linktype =
2790 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(linktype_om), E_CAP_OM_LT_VALUE_KEY)); */
2792 #ifdef HAVE_PCAP_REMOTE
2793 global_capture_opts.src_type = (capture_source)
2794 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(iftype_cbx), E_CAP_CBX_IFTYPE_VALUE_KEY));
2795 if (global_capture_opts.src_type > CAPTURE_IFREMOTE)
2796 global_capture_opts.src_type = CAPTURE_IFREMOTE;
2799 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2800 global_capture_opts.buffer_size =
2801 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb));
2804 global_capture_opts.has_snaplen =
2805 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb));
2806 if (global_capture_opts.has_snaplen) {
2807 global_capture_opts.snaplen =
2808 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
2809 if (global_capture_opts.snaplen < 1)
2810 global_capture_opts.snaplen = WTAP_MAX_PACKET_SIZE;
2811 else if (global_capture_opts.snaplen < MIN_PACKET_SIZE)
2812 global_capture_opts.snaplen = MIN_PACKET_SIZE;
2815 global_capture_opts.promisc_mode =
2816 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb));
2817 #ifdef HAVE_PCAP_CREATE
2818 global_capture_opts.monitor_mode =
2819 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(monitor_cb));
2821 global_capture_opts.use_pcapng =
2822 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pcap_ng_cb));
2824 /* XXX - don't try to get clever and set "cfile.filter" to NULL if the
2825 filter string is empty, as an indication that we don't have a filter
2826 and thus don't have to set a filter when capturing - the version of
2827 libpcap in Red Hat Linux 6.1, and versions based on later patches
2828 in that series, don't bind the AF_PACKET socket to an interface
2829 until a filter is set, which means they aren't bound at all if
2830 no filter is set, which means no packets arrive as input on that
2831 socket, which means Wireshark never sees any packets. */
2832 filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
2833 if (global_capture_opts.cfilter)
2834 g_free(global_capture_opts.cfilter);
2835 g_assert(filter_text != NULL);
2836 global_capture_opts.cfilter = g_strdup(filter_text);
2838 /* Wireshark always saves to a capture file. */
2839 global_capture_opts.saving_to_file = TRUE;
2840 g_save_file = gtk_entry_get_text(GTK_ENTRY(file_te));
2841 if (g_save_file && g_save_file[0]) {
2842 /* User specified a file to which the capture should be written. */
2843 global_capture_opts.save_file = g_strdup(g_save_file);
2844 /* Save the directory name for future file dialogs. */
2845 cf_name = g_strdup(g_save_file);
2846 dirname = get_dirname(cf_name); /* Overwrites cf_name */
2847 set_last_open_dir(dirname);
2850 /* User didn't specify a file; save to a temporary file. */
2851 global_capture_opts.save_file = NULL;
2854 global_capture_opts.has_autostop_packets =
2855 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb));
2856 if (global_capture_opts.has_autostop_packets)
2857 global_capture_opts.autostop_packets =
2858 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_packets_sb));
2860 global_capture_opts.has_autostop_duration =
2861 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb));
2862 if (global_capture_opts.has_autostop_duration) {
2863 global_capture_opts.autostop_duration =
2864 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_duration_sb));
2865 global_capture_opts.autostop_duration =
2866 time_unit_combo_box_get_value(stop_duration_cbx, global_capture_opts.autostop_duration);
2869 global_capture_opts.real_time_mode =
2870 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb));
2873 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb));
2875 global_capture_opts.show_info =
2876 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hide_info_cb));
2878 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb)))
2879 g_resolv_flags |= RESOLV_MAC;
2881 g_resolv_flags &= ~RESOLV_MAC;
2882 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(n_resolv_cb)))
2883 g_resolv_flags |= RESOLV_NETWORK;
2885 g_resolv_flags &= ~RESOLV_NETWORK;
2886 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb)))
2887 g_resolv_flags |= RESOLV_TRANSPORT;
2889 g_resolv_flags &= ~RESOLV_TRANSPORT;
2891 global_capture_opts.has_ring_num_files =
2892 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb));
2894 global_capture_opts.ring_num_files =
2895 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb));
2896 if (global_capture_opts.ring_num_files > RINGBUFFER_MAX_NUM_FILES)
2897 global_capture_opts.ring_num_files = RINGBUFFER_MAX_NUM_FILES;
2898 #if RINGBUFFER_MIN_NUM_FILES > 0
2899 else if (global_capture_opts.ring_num_files < RINGBUFFER_MIN_NUM_FILES)
2900 global_capture_opts.ring_num_files = RINGBUFFER_MIN_NUM_FILES;
2903 global_capture_opts.multi_files_on =
2904 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb));
2906 global_capture_opts.has_file_duration =
2907 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb));
2908 if (global_capture_opts.has_file_duration) {
2909 global_capture_opts.file_duration =
2910 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(file_duration_sb));
2911 global_capture_opts.file_duration =
2912 time_unit_combo_box_get_value(file_duration_cbx, global_capture_opts.file_duration);
2915 global_capture_opts.has_autostop_files =
2916 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb));
2917 if (global_capture_opts.has_autostop_files)
2918 global_capture_opts.autostop_files =
2919 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_files_sb));
2921 if (global_capture_opts.multi_files_on) {
2922 global_capture_opts.has_autostop_filesize =
2923 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb));
2924 if (global_capture_opts.has_autostop_filesize) {
2925 tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ring_filesize_sb));
2926 tmp = size_unit_combo_box_convert_value(ring_filesize_cbx, tmp);
2928 global_capture_opts.autostop_filesize = tmp;
2930 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2931 "%sMultiple files: Requested filesize too large!%s\n\n"
2932 "The setting \"Next file every x byte(s)\" can't be greater than %u bytes (2GB).",
2933 simple_dialog_primary_start(), simple_dialog_primary_end(), G_MAXINT);
2938 /* test if the settings are ok for a ringbuffer */
2939 if (global_capture_opts.save_file == NULL) {
2940 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2941 "%sMultiple files: No capture file name given!%s\n\n"
2942 "You must specify a filename if you want to use multiple files.",
2943 simple_dialog_primary_start(), simple_dialog_primary_end());
2945 } else if (!global_capture_opts.has_autostop_filesize && !global_capture_opts.has_file_duration) {
2946 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2947 "%sMultiple files: No file limit given!%s\n\n"
2948 "You must specify a file size or duration at which is switched to the next capture file\n"
2949 "if you want to use multiple files.",
2950 simple_dialog_primary_start(), simple_dialog_primary_end());
2951 g_free(global_capture_opts.save_file);
2952 global_capture_opts.save_file = NULL;
2956 global_capture_opts.has_autostop_filesize =
2957 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb));
2958 if (global_capture_opts.has_autostop_filesize) {
2959 tmp = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(stop_filesize_sb));
2960 tmp = size_unit_combo_box_convert_value(stop_filesize_cbx, tmp);
2962 global_capture_opts.autostop_filesize = tmp;
2964 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
2965 "%sStop Capture: Requested filesize too large!%s\n\n"
2966 "The setting \"... after x byte(s)\" can't be greater than %u bytes (2GB).",
2967 simple_dialog_primary_start(), simple_dialog_primary_end(), G_MAXINT);
2971 } /* multi_files_on */
2975 /* user requested to destroy the dialog */
2977 capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_)
2980 #ifdef HAVE_PCAP_REMOTE
2982 GtkWidget *remote_w;
2985 /* Is there a file selection dialog associated with this
2986 Capture Options dialog? */
2987 fs = g_object_get_data(G_OBJECT(win), E_FILE_SEL_DIALOG_PTR_KEY);
2989 #ifdef HAVE_PCAP_REMOTE
2990 if_list = (GList *) g_object_get_data(G_OBJECT(win), E_CAP_IF_LIST_KEY);
2992 free_interface_list(if_list);
2997 /* Yes. Destroy it. */
3001 /* Note that we no longer have a "Capture Options" dialog box. */
3005 /* update airpcap toolbar */
3006 airpcap_set_toolbar_stop_capture(airpcap_if_active);
3009 #ifdef HAVE_PCAP_REMOTE
3010 remote_w = g_object_get_data(G_OBJECT(win), E_CAP_REMOTE_DIALOG_PTR_KEY);
3011 if (remote_w != NULL)
3012 window_destroy(remote_w);
3016 /* user changed the interface entry */
3018 capture_prep_interface_changed_cb(GtkWidget *entry _U_, gpointer argp _U_)
3020 set_if_capabilities(FALSE);
3023 #ifdef HAVE_PCAP_CREATE
3024 /* user changed the setting of the monitor-mode checkbox */
3026 capture_prep_monitor_changed_cb(GtkWidget *monitor _U_, gpointer argp _U_)
3028 set_if_capabilities(TRUE);
3033 * Adjust the sensitivity of various widgets as per the current setting
3037 capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
3041 *multi_files_on_cb, *ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
3042 *ring_filesize_cb, *ring_filesize_sb, *ring_filesize_cbx,
3043 *file_duration_cb, *file_duration_sb, *file_duration_cbx,
3044 *sync_cb, *auto_scroll_cb, *hide_info_cb,
3045 *stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
3046 *stop_filesize_cb, *stop_filesize_sb, *stop_filesize_cbx,
3047 *stop_duration_cb, *stop_duration_sb, *stop_duration_cbx,
3048 *stop_files_cb, *stop_files_sb, *stop_files_lb;
3050 if_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_IFACE_KEY);
3051 snap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_CB_KEY);
3052 snap_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_SB_KEY);
3053 multi_files_on_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_MULTI_FILES_ON_CB_KEY);
3054 ringbuffer_nbf_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_CB_KEY);
3055 ringbuffer_nbf_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_SB_KEY);
3056 ringbuffer_nbf_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_NBF_LB_KEY);
3057 ring_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CB_KEY);
3058 ring_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_SB_KEY);
3059 ring_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_RING_FILESIZE_CBX_KEY);
3060 file_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CB_KEY);
3061 file_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_SB_KEY);
3062 file_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_FILE_DURATION_CBX_KEY);
3063 sync_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SYNC_KEY);
3064 auto_scroll_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_AUTO_SCROLL_KEY);
3065 hide_info_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_HIDE_INFO_KEY);
3066 stop_packets_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_CB_KEY);
3067 stop_packets_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_SB_KEY);
3068 stop_packets_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_PACKETS_LB_KEY);
3069 stop_filesize_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CB_KEY);
3070 stop_filesize_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_SB_KEY);
3071 stop_filesize_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILESIZE_CBX_KEY);
3072 stop_duration_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CB_KEY);
3073 stop_duration_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_SB_KEY);
3074 stop_duration_cbx = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_DURATION_CBX_KEY);
3075 stop_files_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_CB_KEY);
3076 stop_files_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_SB_KEY);
3077 stop_files_lb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_STOP_FILES_LB_KEY);
3079 /* The snapshot length spinbox is sensitive if the "Limit each packet
3080 to" checkbox is on. */
3081 gtk_widget_set_sensitive(GTK_WIDGET(snap_sb),
3082 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)));
3085 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb))) {
3086 /* "Update list of packets in real time" captures enabled; we don't
3087 support ring buffer mode for those captures, so turn ring buffer
3088 mode off if it's on, and make its toggle button, and the spin
3089 button for the number of ring buffer files (and the spin button's
3090 label), insensitive. */
3091 /* gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(multi_files_on_cb), FALSE);
3092 gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), FALSE);*/
3094 /* Auto-scroll mode is meaningful only in "Update list of packets
3095 in real time" captures, so make its toggle button sensitive. */
3096 gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), TRUE);
3098 /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), TRUE);*/
3100 /* "Update list of packets in real time" captures disabled; that
3101 means ring buffer mode is OK, so make its toggle button
3103 /* gtk_widget_set_sensitive(GTK_WIDGET(multi_files_on_cb), TRUE);*/
3105 /* Auto-scroll mode is meaningful only in "Update list of packets
3106 in real time" captures, so make its toggle button insensitive. */
3107 gtk_widget_set_sensitive(GTK_WIDGET(auto_scroll_cb), FALSE);
3109 /*gtk_widget_set_sensitive(GTK_WIDGET(hide_info_cb), FALSE);*/
3112 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(multi_files_on_cb))) {
3113 /* Ring buffer mode enabled. */
3115 /* Force at least one of the "file switch" conditions (we need at least one) */
3116 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)) == FALSE &&
3117 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)) == FALSE) {
3118 if (tb == ring_filesize_cb)
3119 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_duration_cb), TRUE);
3121 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ring_filesize_cb), TRUE);
3124 gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), TRUE);
3125 gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb),
3126 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
3127 gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb),
3128 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_nbf_cb)));
3130 /* The ring filesize spinbox is sensitive if the "Next capture file
3131 after N kilobytes" checkbox is on. */
3132 gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), TRUE);
3133 gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),
3134 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
3135 gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cbx),
3136 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ring_filesize_cb)));
3138 /* The ring duration spinbox is sensitive if the "Next capture file
3139 after N seconds" checkbox is on. */
3140 gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), TRUE);
3141 gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),
3142 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
3143 gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cbx),
3144 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_duration_cb)));
3146 gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), FALSE);
3147 gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb), FALSE);
3148 gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cbx), FALSE);
3150 gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), TRUE);
3151 gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb),
3152 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
3153 gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb),
3154 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_files_cb)));
3156 /* Ring buffer mode disabled. */
3157 gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_cb), FALSE);
3158 gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_sb), FALSE);
3159 gtk_widget_set_sensitive(GTK_WIDGET(ringbuffer_nbf_lb), FALSE);
3161 gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cb), FALSE);
3162 gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_sb),FALSE);
3163 gtk_widget_set_sensitive(GTK_WIDGET(ring_filesize_cbx),FALSE);
3165 gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cb), FALSE);
3166 gtk_widget_set_sensitive(GTK_WIDGET(file_duration_sb),FALSE);
3167 gtk_widget_set_sensitive(GTK_WIDGET(file_duration_cbx),FALSE);
3169 /* The maximum file size spinbox is sensitive if the "Stop capture
3170 after N kilobytes" checkbox is on. */
3171 gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cb), TRUE);
3172 gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_sb),
3173 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
3174 gtk_widget_set_sensitive(GTK_WIDGET(stop_filesize_cbx),
3175 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_filesize_cb)));
3177 gtk_widget_set_sensitive(GTK_WIDGET(stop_files_cb), FALSE);
3178 gtk_widget_set_sensitive(GTK_WIDGET(stop_files_sb), FALSE);
3179 gtk_widget_set_sensitive(GTK_WIDGET(stop_files_lb), FALSE);
3182 /* The maximum packet count spinbox is sensitive if the "Stop capture
3183 after N packets" checkbox is on. */
3184 gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_sb),
3185 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
3186 gtk_widget_set_sensitive(GTK_WIDGET(stop_packets_lb),
3187 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_packets_cb)));
3189 /* The capture duration spinbox is sensitive if the "Stop capture
3190 after N seconds" checkbox is on. */
3191 gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_sb),
3192 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
3193 gtk_widget_set_sensitive(GTK_WIDGET(stop_duration_cbx),
3194 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stop_duration_cb)));
3197 #endif /* HAVE_LIBPCAP */