#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"
}
}
+/*
+ * 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 */
/*
*/
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 */
} 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) {
device.monitor_mode_enabled = monitor_mode;
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;
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;
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) {