aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-03-22 16:58:42 -0700
committerGuy Harris <guy@alum.mit.edu>2015-03-23 00:00:42 +0000
commit1b4120846ee1a139f7d3ff9c2bfe2eab593745bb (patch)
treef500d385ecbe57b324b5eda1dd6875893630beeb /ui
parentc474bb86912aedb13669fb14627b2ad29f082b40 (diff)
Centralize the code to set the active_dlt value for a device.
We were doing it similarly, but not the same, in several places; make a common routine for it. Have that code check to make sure the DLT_ value in question is actually supported by the device; if not, pick the first supported DLT_ value, if any; this keeps it from, for example, picking a bad DLT_ value if your defaults were set based on monitor mode being on but monitor mode actually being off, or vice versa. Change-Id: I1722bfeaf60429bc5c6f665fdea3d466052b13bd Reviewed-on: https://code.wireshark.org/review/7795 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r--ui/capture_ui_utils.c51
-rw-r--r--ui/capture_ui_utils.h7
-rw-r--r--ui/gtk/capture_dlg.c4
-rw-r--r--ui/iface_lists.c23
-rw-r--r--ui/qt/capture_interfaces_dialog.cpp5
5 files changed, 66 insertions, 24 deletions
diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c
index f94afb6b3a..b5d0e3e0e1 100644
--- a/ui/capture_ui_utils.c
+++ b/ui/capture_ui_utils.c
@@ -33,6 +33,7 @@
#include "epan/ex-opt.h"
#include "caputils/capture_ifinfo.h"
#include "ui/capture_ui_utils.h"
+#include "ui/capture_globals.h"
#include "wiretap/wtap.h"
#include "epan/to_str.h"
@@ -490,6 +491,56 @@ get_iface_description_for_interface(capture_options *capture_opts, guint i)
}
}
+/*
+ * Set the active DLT for a device appropriately.
+ */
+void
+set_active_dlt(interface_t *device, int global_default_dlt)
+{
+ GList *list;
+ gboolean found_active_dlt;
+ link_row *link;
+
+ /*
+ * If there's a preference for the link-layer header type for
+ * this interface, use it. If not, use the all-interface
+ * default; if that's not set on the command line, that will
+ * be -1, meaning "use per-interface defaults", otherwise
+ * we'll fail if it's not one of the types the interface
+ * supports.
+ */
+ if ((device->active_dlt = capture_dev_user_linktype_find(device->name)) == -1) {
+ device->active_dlt = global_default_dlt;
+ }
+
+ /*
+ * Is that one of the supported link-layer header types?
+ * If not, set it to -1, so we'll fall back on the first supported
+ * link-layer header type.
+ */
+ found_active_dlt = FALSE;
+ for (list = device->links; list != NULL; list = g_list_next(list)) {
+ link = (link_row *)(list->data);
+ if (link->dlt != -1 && link->dlt == device->active_dlt) {
+ found_active_dlt = TRUE;
+ break;
+ }
+ }
+ if (!found_active_dlt) {
+ device->active_dlt = -1;
+ }
+ if (device->active_dlt == -1) {
+ /* Fall back on the first supported DLT, if we have one. */
+ for (list = device->links; list != NULL; list = g_list_next(list)) {
+ link = (link_row *)(list->data);
+ if (link->dlt != -1) {
+ device->active_dlt = link->dlt;
+ break;
+ }
+ }
+ }
+}
+
#endif /* HAVE_LIBPCAP */
/*
diff --git a/ui/capture_ui_utils.h b/ui/capture_ui_utils.h
index 6b5361f83e..ee411e05fd 100644
--- a/ui/capture_ui_utils.h
+++ b/ui/capture_ui_utils.h
@@ -145,6 +145,13 @@ const char *get_if_name(const char *if_text);
*/
const char *get_iface_description_for_interface(capture_options *capture_opts, guint i);
+/** Set the active DLT for a device appropriately.
+ *
+ * @param device the device on which to set the active DLT
+ * @param global_default_dlt the global default DLT
+ */
+extern void set_active_dlt(interface_t *device, int global_default_dlt);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c
index 350660d86f..9b919427e1 100644
--- a/ui/gtk/capture_dlg.c
+++ b/ui/gtk/capture_dlg.c
@@ -5656,10 +5656,8 @@ create_and_fill_model(GtkTreeView *view)
} else {
temp = g_strdup_printf("<b>%s</b>\n<span size='small'>%s</span>", device.display_name, device.addresses);
}
+ set_active_dlt(&device, global_capture_opts.default_options.linktype);
linkname = NULL;
- if(capture_dev_user_linktype_find(device.name) != -1) {
- device.active_dlt = capture_dev_user_linktype_find(device.name);
- }
for (list = device.links; list != NULL; list = g_list_next(list)) {
linkr = (link_row*)(list->data);
if (linkr->dlt == device.active_dlt) {
diff --git a/ui/iface_lists.c b/ui/iface_lists.c
index 1310c30a3f..1dfb9b88c3 100644
--- a/ui/iface_lists.c
+++ b/ui/iface_lists.c
@@ -244,28 +244,10 @@ scan_local_interfaces(void (*update_cb)(void))
device.monitor_mode_supported = caps->can_set_rfmon;
#endif
/*
- * If there's a preference for the link-layer header type for
- * this interface, use it. If not, use the all-interface
- * default; if that's not set on the command line, that will
- * be -1, meaning "use per-interface defaults", otherwise
- * we'll fail if it's not one of the types the interface
- * supports.
- */
- if ((device.active_dlt = capture_dev_user_linktype_find(if_info->name)) == -1) {
- device.active_dlt = global_capture_opts.default_options.linktype;
- }
-
- /*
* Process the list of link-layer header types.
- * If the active link-layer header type wasn't set from a
- * preference or a global option (meaning it's -1), default
- * to the first link-layer header type in the list.
*/
for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
data_link_info = (data_link_info_t *)lt_entry->data;
- if (linktype_count == 0 && device.active_dlt == -1) {
- device.active_dlt = data_link_info->dlt;
- }
link = (link_row *)g_malloc(sizeof(link_row));
if (data_link_info->description != NULL) {
link->dlt = data_link_info->dlt;
@@ -277,6 +259,11 @@ scan_local_interfaces(void (*update_cb)(void))
device.links = g_list_append(device.links, link);
linktype_count++;
}
+
+ /*
+ * Set the active DLT for the device appropriately.
+ */
+ set_active_dlt(&device, global_capture_opts.default_options.linktype);
} else {
#if defined(HAVE_PCAP_CREATE)
device.monitor_mode_enabled = FALSE;
diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp
index f1c8539429..2e164770f0 100644
--- a/ui/qt/capture_interfaces_dialog.cpp
+++ b/ui/qt/capture_interfaces_dialog.cpp
@@ -487,10 +487,9 @@ void CaptureInterfacesDialog::updateInterfaces()
ti->setToolTip(col_interface_, tr("no addresses"));
}
+ set_active_dlt(device, global_capture_opts.default_options.linktype);
+
QString linkname = "unknown";
- if(capture_dev_user_linktype_find(device->name) != -1) {
- device->active_dlt = capture_dev_user_linktype_find(device->name);
- }
for (list = device->links; list != NULL; list = g_list_next(list)) {
linkr = (link_row*)(list->data);
if (linkr->dlt == device->active_dlt) {