summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-06-29 18:36:22 -0700
committerGuy Harris <guy@alum.mit.edu>2014-06-30 01:36:56 +0000
commitdf5833723c41003486eba83aaf6ca41f0c27816b (patch)
tree5f42331417eade5f6ffcfff77a0a8bcea96931b8 /ui
parentfe8661a7674ae944bb6545240104880ef945ad4d (diff)
downloadwireshark-df5833723c41003486eba83aaf6ca41f0c27816b.tar.gz
Move capture_ui_utils.[ch] to libui.
Change-Id: Id0f3d4d60a1acc7aa64fd3737b8f16df5bca4e5a Reviewed-on: https://code.wireshark.org/review/2708 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r--ui/CMakeLists.txt1
-rw-r--r--ui/Makefile.common2
-rw-r--r--ui/capture_ui_utils.c571
-rw-r--r--ui/capture_ui_utils.h135
-rw-r--r--ui/gtk/capture_dlg.c2
-rw-r--r--ui/gtk/capture_if_dlg.c2
-rw-r--r--ui/gtk/capture_info_dlg.c3
-rw-r--r--ui/gtk/main.c2
-rw-r--r--ui/gtk/main_statusbar.c4
-rw-r--r--ui/gtk/main_welcome.c2
-rw-r--r--ui/gtk/prefs_capture.c2
-rw-r--r--ui/iface_lists.c3
-rw-r--r--ui/qt/QtShark.pro1
-rw-r--r--ui/qt/capture_interfaces_dialog.cpp2
-rw-r--r--ui/qt/capture_preferences_frame.cpp2
-rw-r--r--ui/qt/interface_tree.h2
-rw-r--r--ui/qt/main.cpp4
-rw-r--r--ui/qt/main_window.cpp4
-rw-r--r--ui/qt/main_window_slots.cpp4
19 files changed, 732 insertions, 16 deletions
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt
index 79b093b55a..58a7cd8e2e 100644
--- a/ui/CMakeLists.txt
+++ b/ui/CMakeLists.txt
@@ -22,6 +22,7 @@
set(COMMON_UI_SRC
alert_box.c
+ capture_ui_utils.c
decode_as_utils.c
export_object.c
export_object_dicom.c
diff --git a/ui/Makefile.common b/ui/Makefile.common
index 3e1f209a33..a8c2e3026e 100644
--- a/ui/Makefile.common
+++ b/ui/Makefile.common
@@ -43,6 +43,7 @@ GENERATOR_FILES = \
WIRESHARK_UI_SRC = \
alert_box.c \
+ capture_ui_utils.c \
decode_as_utils.c \
export_object.c \
export_object_dicom.c \
@@ -73,6 +74,7 @@ WIRESHARK_UI_SRC = \
noinst_HEADERS = \
alert_box.h \
capture_globals.h \
+ capture_ui_utils.h \
decode_as_utils.h \
export_object.h \
last_open_dir.h \
diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c
new file mode 100644
index 0000000000..ae192fdf03
--- /dev/null
+++ b/ui/capture_ui_utils.c
@@ -0,0 +1,571 @@
+/* capture_ui_utils.c
+ * Utilities for capture user interfaces
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#ifdef HAVE_LIBPCAP
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <glib.h>
+
+#include "epan/prefs.h"
+#include "epan/ex-opt.h"
+#include <capchild/capture_ifinfo.h>
+#include "ui/capture_ui_utils.h"
+#include "wiretap/wtap.h"
+#include "epan/to_str.h"
+
+/*
+ * Find user-specified capture device description that matches interface
+ * name, if any.
+ */
+char *
+capture_dev_user_descr_find(const gchar *if_name)
+{
+ char *p;
+ char *p2 = NULL;
+ char *descr = NULL;
+ int lp = 0;
+ int ct = 0;
+
+ if ((prefs.capture_devices_descr == NULL) ||
+ (*prefs.capture_devices_descr == '\0')) {
+ /* There are no descriptions. */
+ return NULL;
+ }
+
+ if ((p = strstr(prefs.capture_devices_descr, if_name)) == NULL) {
+ /* There are, but there isn't one for this interface. */
+ return NULL;
+ }
+
+ while (*p != '\0') {
+ /* error: ran into next interface description */
+ if (*p == ',')
+ return NULL;
+ /* found left parenthesis, start of description */
+ else if (*p == '(') {
+ ct = 0;
+ lp++;
+ /* skip over left parenthesis */
+ p++;
+ /* save pointer to beginning of description */
+ p2 = p;
+ continue;
+ }
+ else if (*p == ')') {
+ /* end of description */
+ break;
+ }
+ else {
+ p++;
+ ct++;
+ }
+ }
+
+ if ((lp == 1) && (ct > 0) && (p2 != NULL)) {
+ /* Allocate enough space to return the string,
+ which runs from p2 to p, plus a terminating
+ '\0'. */
+ descr = (char *)g_malloc(p - p2 + 1);
+ memcpy(descr, p2, p - p2);
+ descr[p - p2] = '\0';
+ return descr;
+ }
+ else
+ return NULL;
+}
+
+gint
+capture_dev_user_linktype_find(const gchar *if_name)
+{
+ gchar *p, *next, *tmpname;
+ long linktype;
+
+ if ((prefs.capture_devices_linktypes == NULL) ||
+ (*prefs.capture_devices_linktypes == '\0')) {
+ /* There are no link-layer header types */
+ return -1;
+ }
+ tmpname = g_strdup_printf(",%s(", if_name);
+ if ((p = strstr(prefs.capture_devices_linktypes, tmpname)) == NULL) {
+ /* There are, but there isn't one for this interface. */
+ return -1;
+ }
+
+ p += strlen(if_name) + 2;
+ linktype = strtol(p, &next, 10);
+ if (next == p || *next != ')' || linktype < 0) {
+ /* Syntax error */
+ return -1;
+ }
+ if (linktype > G_MAXINT) {
+ /* Value doesn't fit in a gint */
+ return -1;
+ }
+
+ return (gint)linktype;
+}
+
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
+gint
+capture_dev_user_buffersize_find(const gchar *if_name)
+{
+ gchar *p, *next, *tmpname;
+ gint buffersize;
+
+ if ((prefs.capture_devices_buffersize == NULL) ||
+ (*prefs.capture_devices_buffersize == '\0')) {
+ /* There are no buffersizes defined */
+ return -1;
+ }
+ tmpname = g_strdup_printf(",%s(", if_name);
+ if ((p = strstr(prefs.capture_devices_buffersize, tmpname)) == NULL) {
+ /* There are, but there isn't one for this interface. */
+ return -1;
+ }
+
+ p += strlen(if_name) + 2;
+ buffersize = (gint)strtol(p, &next, 10);
+ if (next == p || *next != ')' || buffersize < 0) {
+ /* Syntax error */
+ return -1;
+ }
+ if (buffersize > G_MAXINT) {
+ /* Value doesn't fit in a gint */
+ return -1;
+ }
+
+ return (gint)buffersize;
+}
+#endif
+
+gint
+capture_dev_user_snaplen_find(const gchar *if_name)
+{
+ gchar *p, *next, *tmpname;
+ gint snaplen;
+
+ if ((prefs.capture_devices_snaplen == NULL) ||
+ (*prefs.capture_devices_snaplen == '\0')) {
+ /* There is no snap length defined */
+ return -1;
+ }
+ tmpname = g_strdup_printf(",%s:", if_name);
+ if ((p = strstr(prefs.capture_devices_snaplen, tmpname)) == NULL) {
+ /* There are, but there isn't one for this interface. */
+ return -1;
+ }
+
+ p += strlen(if_name) + 4;
+ snaplen = (gint)strtol(p, &next, 10);
+ if (next == p || *next != ')' || snaplen < 0) {
+ /* Syntax error */
+ return -1;
+ }
+ if (snaplen > WTAP_MAX_PACKET_SIZE) {
+ /* Value doesn't fit in a gint */
+ return -1;
+ }
+
+ return (gint)snaplen;
+}
+
+gboolean
+capture_dev_user_hassnap_find(const gchar *if_name)
+{
+ gchar *p, *next, *tmpname;
+ gboolean hassnap;
+
+ if ((prefs.capture_devices_snaplen == NULL) ||
+ (*prefs.capture_devices_snaplen == '\0')) {
+ /* There is no snap length defined */
+ return -1;
+ }
+ tmpname = g_strdup_printf(",%s:", if_name);
+ if ((p = strstr(prefs.capture_devices_snaplen, tmpname)) == NULL) {
+ /* There are, but there isn't one for this interface. */
+ return -1;
+ }
+
+ p += strlen(if_name) + 2;
+ hassnap = (gboolean)strtol(p, &next, 10);
+ if (next == p || *next != '(') {
+ /* Syntax error */
+ return -1;
+ }
+
+ return (gboolean)hassnap;
+}
+
+gboolean
+capture_dev_user_pmode_find(const gchar *if_name)
+{
+ gchar *p, *next, *tmpname;
+ gboolean pmode;
+
+ if ((prefs.capture_devices_pmode == NULL) ||
+ (*prefs.capture_devices_pmode == '\0')) {
+ /* There is no promiscuous mode defined */
+ return -1;
+ }
+ tmpname = g_strdup_printf(",%s(", if_name);
+ if ((p = strstr(prefs.capture_devices_pmode, tmpname)) == NULL) {
+ /* There are, but there isn't one for this interface. */
+ return -1;
+ }
+
+ p += strlen(if_name) + 2;
+ pmode = (gboolean)strtol(p, &next, 10);
+ if (next == p || *next != ')') {
+ /* Syntax error */
+ return -1;
+ }
+ return (gboolean)pmode;
+}
+
+gchar*
+capture_dev_user_cfilter_find(const gchar *if_name)
+{
+ gchar *p, q[MAX_VAL_LEN], *tmpname;
+ int i = 0;
+
+ if ((prefs.capture_devices_filter == NULL) ||
+ (*prefs.capture_devices_filter == '\0')) {
+ /* There is no capture filter defined */
+ return NULL;
+ }
+ tmpname = g_strdup_printf(",%s(", if_name);
+ if ((p = strstr(prefs.capture_devices_filter, tmpname)) == NULL) {
+ /* There are, but there isn't one for this interface. */
+ return NULL;
+ }
+
+ p += strlen(if_name) + 2;
+ while (p[i+1] != ',' && p[i+1] != '\0') {
+ q[i] = p[i];
+ i++;
+ }
+ q[i] = '\0';
+ return g_strdup(q);
+}
+
+/*
+ * Return as descriptive a name for an interface as we can get.
+ * If the user has specified a comment, use that. Otherwise,
+ * if capture_interface_list() supplies a description, use that,
+ * otherwise use the interface name.
+ *
+ * The result must be g_free()'d when you're done with it.
+ *
+ * Note: given that this calls capture_interface_list(), which attempts to
+ * open all adapters it finds in order to check whether they can be
+ * captured on, this is an expensive routine to call, so don't call it
+ * frequently.
+ */
+char *
+get_interface_descriptive_name(const char *if_name)
+{
+ char *descr;
+ GList *if_list;
+ GList *if_entry;
+ if_info_t *if_info;
+ int err;
+
+ /* Do we have a user-supplied description? */
+ descr = capture_dev_user_descr_find(if_name);
+ if (descr != NULL) {
+ /* Yes - make a copy of that. */
+ descr = g_strdup(descr);
+ } else if (strcmp(if_name, "-") == 0) {
+ /*
+ * Strictly speaking, -X (extension) options are for modules, e.g. Lua
+ * and using one here stretches that definition. However, this doesn't
+ * waste a single-letter option on something that might be rarely used
+ * and is backward-compatible to 1.0.
+ */
+ descr = g_strdup(ex_opt_get_nth("stdin_descr", 0));
+ if (!descr) {
+ descr = g_strdup("Standard input");
+ }
+ } else {
+ /* No, we don't have a user-supplied description; did we get
+ one from the OS or libpcap? */
+ descr = NULL;
+ if_list = capture_interface_list(&err, NULL, NULL);
+ if (if_list != NULL) {
+ if_entry = if_list;
+ do {
+ if_info = (if_info_t *)if_entry->data;
+ if (strcmp(if_info->name, if_name) == 0) {
+ if (if_info->friendly_name != NULL) {
+ /* We have a "friendly name"; return a copy of that
+ as the description - when we free the interface
+ list, that'll also free up the strings to which
+ it refers. */
+ descr = g_strdup(if_info->friendly_name);
+ } else if (if_info->vendor_description != NULL) {
+ /* We have no "friendly name", but we have a vendor
+ description; return a copy of that - when we free
+ the interface list, that'll also free up the strings
+ to which it refers. */
+ descr = g_strdup(if_info->vendor_description);
+ }
+ break;
+ }
+ } while ((if_entry = g_list_next(if_entry)) != NULL);
+ }
+ free_interface_list(if_list);
+
+ if (descr == NULL) {
+ /* The interface name is all we have, so just return a copy of that. */
+ descr = g_strdup(if_name);
+ }
+ }
+
+ return descr;
+}
+
+
+/* search interface info by interface name */
+static if_info_t *
+search_info(GList *if_list, gchar *if_name)
+{
+ GList *if_entry;
+ if_info_t *if_info;
+
+
+ for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) {
+ if_info = (if_info_t *)if_entry->data;
+
+ if(strcmp(if_name, if_info->name) == 0) {
+ return if_info;
+ }
+ }
+
+ return NULL;
+}
+
+
+/* build the string to display in the combo box for the given interface */
+char *
+build_capture_combo_name(GList *if_list, gchar *if_name)
+{
+ gchar *descr;
+ char *if_string;
+ if_info_t *if_info;
+
+ /* Do we have a user-supplied description? */
+ descr = capture_dev_user_descr_find(if_name);
+ if (descr != NULL) {
+ /* Yes, we have a user-supplied description; use it. */
+ if_string = g_strdup_printf("%s: %s", descr, if_name);
+ g_free(descr);
+ } else {
+ /* No, we don't have a user-supplied description; did we get
+ one from the OS or libpcap? */
+ if_info = search_info(if_list, if_name);
+ if (if_info != NULL && if_info->vendor_description != NULL) {
+ /* Yes - use it. */
+ if_string = g_strdup_printf("%s: %s", if_info->vendor_description,
+ if_info->name);
+ } else {
+ /* No. */
+ if_string = g_strdup(if_name);
+ }
+ }
+
+ return if_string;
+}
+
+
+GList *
+build_capture_combo_list(GList *if_list, gboolean do_hide)
+{
+ GList *combo_list;
+ GList *if_entry;
+ if_info_t *if_info;
+ char *if_string;
+ gchar *descr;
+
+ combo_list = NULL;
+ if (if_list != NULL) {
+ /* Scan through the list and build a list of strings to display. */
+ for (if_entry = if_list; if_entry != NULL;
+ if_entry = g_list_next(if_entry)) {
+ if_info = (if_info_t *)if_entry->data;
+
+ /* Is this interface hidden and, if so, should we include it
+ anyway? */
+ if (!prefs_is_capture_device_hidden(if_info->name) || !do_hide) {
+ /* It's not hidden, or it is but we should include it in the list. */
+
+ /* Do we have a user-supplied description? */
+ descr = capture_dev_user_descr_find(if_info->name);
+ if (descr != NULL) {
+ /* Yes, we have a user-supplied description; use it. */
+ if_string = g_strdup_printf("%s: %s", descr, if_info->name);
+ g_free(descr);
+ } else {
+ /* No, we don't have a user-supplied description; did we get
+ one from the OS or libpcap? */
+ if (if_info->vendor_description != NULL) {
+ /* Yes - use it. */
+ if_string = g_strdup_printf("%s: %s",
+ if_info->vendor_description,
+ if_info->name);
+ } else {
+ /* No. */
+ if_string = g_strdup(if_info->name);
+ }
+ }
+ combo_list = g_list_append(combo_list, if_string);
+ }
+ }/*for*/
+ }
+ return combo_list;
+}
+
+static void
+free_if_string(gpointer data, gpointer user_data _U_)
+{
+ g_free(data);
+}
+
+void
+free_capture_combo_list(GList *combo_list)
+{
+ if (combo_list != NULL) {
+ g_list_foreach(combo_list, free_if_string, NULL);
+ g_list_free(combo_list);
+ }
+}
+
+/*
+ * Given text that contains an interface name possibly prefixed by an
+ * interface description, extract the interface name.
+ */
+const char *
+get_if_name(const char *if_text)
+{
+ const char *if_name;
+
+#ifdef _WIN32
+ /*
+ * We cannot assume that the interface name doesn't contain a space;
+ * some names on Windows OT do.
+ *
+ * We also can't assume it begins with "\Device\", either, as, on
+ * Windows OT, WinPcap doesn't put "\Device\" in front of the name.
+ *
+ * As I remember, we can't assume that the interface description
+ * doesn't contain a colon, either; I think some do.
+ *
+ * We can probably assume that the interface *name* doesn't contain
+ * a colon, however; if any interface name does contain a colon on
+ * Windows, it'll be time to just get rid of the damn interface
+ * descriptions in the drop-down list, have just the names in the
+ * drop-down list, and have a "Browse..." button to browse for interfaces,
+ * with names, descriptions, IP addresses, blah blah blah available when
+ * possible.
+ *
+ * So we search backwards for a colon. If we don't find it, just
+ * return the entire string; otherwise, skip the colon and any blanks
+ * after it, and return that string.
+ */
+ if_name = if_text + strlen(if_text);
+ for (;;) {
+ if (if_name == if_text) {
+ /* We're at the beginning of the string; return it. */
+ break;
+ }
+ if_name--;
+ if (*if_name == ':') {
+ /*
+ * We've found a colon.
+ * Unfortunately, a colon is used in the string "rpcap://",
+ * which is used in case of a remote capture.
+ * So we'll check to make sure the colon isn't followed by "//";
+ * it'll be followed by a blank if it separates the description
+ * and the interface name. (We don't wire in "rpcap", in case we
+ * support other protocols in the same syntax.)
+ * Unfortunately, another colon can be used in "rpcap://host:port/"
+ * before port. Check if colon is followed by digit.
+ */
+ if ((strncmp(if_name, "://", 3) != 0) && !isdigit(if_name[1])) {
+ /*
+ * OK, we've found a colon followed neither by "//" nor by digit.
+ * Skip blanks following it.
+ */
+ if_name++;
+ while (*if_name == ' ')
+ if_name++;
+ break;
+ }
+ }
+ /* Keep looking for a colon not followed by "//". */
+ }
+#else
+ /*
+ * There's a space between the interface description and name, and
+ * the interface name shouldn't have a space in it (it doesn't, on
+ * UNIX systems); look backwards in the string for a space.
+ *
+ * (An interface name might, however, contain a colon in it, which
+ * is why we don't use the colon search on UNIX.)
+ */
+ if_name = strrchr(if_text, ' ');
+ if (if_name == NULL) {
+ if_name = if_text;
+ } else {
+ if_name++;
+ }
+#endif
+ return if_name;
+}
+
+/* Return interface_opts->descr (after setting it if it is not set)
+ * This is necessary because capture_opts.c can't set descr (at least
+ * not without adding significant dependencies there).
+ */
+const char *
+get_iface_description_for_interface(capture_options *capture_opts, guint i)
+{
+ interface_options interface_opts;
+
+ if (i < capture_opts->ifaces->len) {
+ interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
+ if (!interface_opts.descr && interface_opts.name) {
+ interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
+ capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
+ g_array_insert_val(capture_opts->ifaces, i, interface_opts);
+ }
+ return (interface_opts.descr);
+ } else {
+ return (NULL);
+ }
+}
+
+#endif /* HAVE_LIBPCAP */
diff --git a/ui/capture_ui_utils.h b/ui/capture_ui_utils.h
new file mode 100644
index 0000000000..fd2a4e4b1e
--- /dev/null
+++ b/ui/capture_ui_utils.h
@@ -0,0 +1,135 @@
+/* capture_ui_utils.c
+ * Declarations of utilities for capture user interfaces
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __CAPTURE_UI_UTILS_H__
+#define __CAPTURE_UI_UTILS_H__
+
+#include "capture_opts.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** @file
+ * GList of available capture interfaces.
+ */
+
+/**
+ * Find user-specified capture device description that matches interface
+ * name, if any.
+ */
+char *capture_dev_user_descr_find(const gchar *if_name);
+
+/**
+ * Find user-specified link-layer header type that matches interface
+ * name, if any.
+ */
+gint capture_dev_user_linktype_find(const gchar *if_name);
+
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
+/**
+ * Find user-specified buffer size that matches interface
+ * name, if any.
+ */
+gint capture_dev_user_buffersize_find(const gchar *if_name);
+#endif
+
+/**
+ * Find user-specified snap length that matches interface
+ * name, if any.
+ */
+gint capture_dev_user_snaplen_find(const gchar *if_name);
+gboolean capture_dev_user_hassnap_find(const gchar *if_name);
+
+/**
+ * Find user-specified promiscuous mode that matches interface
+ * name, if any.
+ */
+gboolean capture_dev_user_pmode_find(const gchar *if_name);
+
+/**
+ * Find user-specified capture filter that matches interface
+ * name, if any.
+ */
+gchar* capture_dev_user_cfilter_find(const gchar *if_name);
+
+/** Return as descriptive a name for an interface as we can get.
+ * If the user has specified a comment, use that. Otherwise,
+ * if capture_interface_list() supplies a description, use that,
+ * otherwise use the interface name.
+ *
+ * @param if_name The name of the interface.
+ *
+ * @return The descriptive name (must be g_free'd later)
+ */
+char *get_interface_descriptive_name(const char *if_name);
+
+/** Build the GList of available capture interfaces.
+ *
+ * @param if_list An interface list from capture_interface_list().
+ * @param do_hide Hide the "hidden" interfaces.
+ *
+ * @return A list of if_info_t structs (use free_capture_combo_list() later).
+ */
+GList *build_capture_combo_list(GList *if_list, gboolean do_hide);
+
+/** Free the GList from build_capture_combo_list().
+ *
+ * @param combo_list the interface list from build_capture_combo_list()
+ */
+void free_capture_combo_list(GList *combo_list);
+
+
+/** Given text that contains an interface name possibly prefixed by an
+ * interface description, extract the interface name.
+ *
+ * @param if_text A string containing the interface description + name.
+ * This is usually the data from one of the list elements returned by
+ * build_capture_combo_list().
+ *
+ * @return The raw interface name, without description (must NOT be g_free'd later)
+ */
+const char *get_if_name(const char *if_text);
+
+/** Convert plain interface name to the displayed name in the combo box.
+ *
+ * @param if_list The list of interfaces returned by build_capture_combo_list()
+ * @param if_name The name of the interface.
+ *
+ * @return The descriptive name (must be g_free'd later)
+ */
+char *build_capture_combo_name(GList *if_list, gchar *if_name);
+
+/** Return the interface description (after setting it if not already set)
+ *
+ * @param capture_opts The capture_options structure that contains the used interface
+ * @param i The index of the interface
+ *
+ * @return A pointer to interface_opts->descr
+ */
+const char *get_iface_description_for_interface(capture_options *capture_opts, guint i);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CAPTURE_UI_UTILS_H__ */
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c
index dcaf302f2c..e2a65ff602 100644
--- a/ui/gtk/capture_dlg.c
+++ b/ui/gtk/capture_dlg.c
@@ -39,9 +39,9 @@
#include "../capture.h"
#include <capchild/capture_ifinfo.h>
#include "../capture-pcap-util.h"
-#include "../capture_ui_utils.h"
#include "../ringbuffer.h"
+#include "ui/capture_ui_utils.h"
#include "ui/capture_globals.h"
#include "ui/iface_lists.h"
#include "ui/preference_utils.h"
diff --git a/ui/gtk/capture_if_dlg.c b/ui/gtk/capture_if_dlg.c
index 306e2ab64e..5d9302d812 100644
--- a/ui/gtk/capture_if_dlg.c
+++ b/ui/gtk/capture_if_dlg.c
@@ -36,10 +36,10 @@
#include <capchild/capture_ifinfo.h>
#include "../capture.h"
#include "../capture-pcap-util.h"
-#include "../capture_ui_utils.h"
#include "wsutil/file_util.h"
#include <wiretap/wtap.h>
+#include "ui/capture_ui_utils.h"
#include "ui/capture_globals.h"
#include "ui/recent.h"
#include "ui/simple_dialog.h"
diff --git a/ui/gtk/capture_info_dlg.c b/ui/gtk/capture_info_dlg.c
index 16cde28839..d7c946cfcf 100644
--- a/ui/gtk/capture_info_dlg.c
+++ b/ui/gtk/capture_info_dlg.c
@@ -32,9 +32,10 @@
#include "../capture.h"
#include "../capture_info.h"
-#include "../capture_ui_utils.h"
#include "../capture-pcap-util.h"
+#include "ui/capture_ui_utils.h"
+
#include "ui/gtk/dlg_utils.h"
#include "ui/gtk/gui_utils.h"
#include "ui/gtk/main.h"
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index ff5bf274b3..c7a4a615db 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -123,6 +123,7 @@
#include "ui/ui_util.h"
#ifdef HAVE_LIBPCAP
+#include "ui/capture_ui_utils.h"
#include "ui/capture_globals.h"
#include "ui/iface_lists.h"
#endif
@@ -130,7 +131,6 @@
#include "codecs/codecs.h"
#ifdef HAVE_LIBPCAP
-#include "capture_ui_utils.h"
#include "capture-pcap-util.h"
#include <capchild/capture_ifinfo.h>
#include "capture.h"
diff --git a/ui/gtk/main_statusbar.c b/ui/gtk/main_statusbar.c
index a76d03470c..8cdfc18f36 100644
--- a/ui/gtk/main_statusbar.c
+++ b/ui/gtk/main_statusbar.c
@@ -39,7 +39,6 @@
#ifdef HAVE_LIBPCAP
#include "../capture_opts.h"
#include "../capture_session.h"
-#include "../capture_ui_utils.h"
#include "../capture.h"
#endif
@@ -48,6 +47,9 @@
#include "ui/main_statusbar.h"
#include "ui/recent.h"
#include "ui/utf8_entities.h"
+#ifdef HAVE_LIBPCAP
+#include "ui/capture_ui_utils.h"
+#endif
#include "ui/gtk/main.h"
#include "ui/gtk/main_statusbar_private.h"
diff --git a/ui/gtk/main_welcome.c b/ui/gtk/main_welcome.c
index ca34a12230..24159f6d99 100644
--- a/ui/gtk/main_welcome.c
+++ b/ui/gtk/main_welcome.c
@@ -32,7 +32,6 @@
#include "capture.h"
#include "capture-pcap-util.h"
#include "capture_opts.h"
-#include "capture_ui_utils.h"
#endif
#include <wsutil/file_util.h>
@@ -40,6 +39,7 @@
#include <wsutil/ws_version_info.h>
#ifdef HAVE_LIBPCAP
+#include "ui/capture_ui_utils.h"
#include "ui/iface_lists.h"
#include "ui/capture_globals.h"
#endif
diff --git a/ui/gtk/prefs_capture.c b/ui/gtk/prefs_capture.c
index 703afd9c98..d92b4a15fb 100644
--- a/ui/gtk/prefs_capture.c
+++ b/ui/gtk/prefs_capture.c
@@ -31,7 +31,7 @@
#include "capture_opts.h"
#include <capchild/capture_ifinfo.h>
-#include "capture_ui_utils.h"
+#include "ui/capture_ui_utils.h"
#include "ui/capture_globals.h"
#include "ui/iface_lists.h"
#include "ui/simple_dialog.h"
diff --git a/ui/iface_lists.c b/ui/iface_lists.c
index 3667c87eab..26702fc184 100644
--- a/ui/iface_lists.c
+++ b/ui/iface_lists.c
@@ -32,8 +32,7 @@
#include <epan/prefs.h>
#include <epan/to_str.h>
-#include "../capture_ui_utils.h"
-
+#include "ui/capture_ui_utils.h"
#include "ui/capture_globals.h"
#include "ui/iface_lists.h"
#include "../log.h"
diff --git a/ui/qt/QtShark.pro b/ui/qt/QtShark.pro
index dd3033039c..5278589966 100644
--- a/ui/qt/QtShark.pro
+++ b/ui/qt/QtShark.pro
@@ -191,7 +191,6 @@ SOURCES_WS_C = \
../../capture.c \
../../capture_info.c \
../../capture_opts.c \
- ../../capture_ui_utils.c \
../../cfile.c \
../../color_filters.c \
../../file.c \
diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp
index b7259d032a..4146354dbf 100644
--- a/ui/qt/capture_interfaces_dialog.cpp
+++ b/ui/qt/capture_interfaces_dialog.cpp
@@ -35,7 +35,7 @@
#include <QTimer>
#include <QMessageBox>
-#include "capture_ui_utils.h"
+#include "ui/capture_ui_utils.h"
#include "ui/capture_globals.h"
#include "ui/iface_lists.h"
diff --git a/ui/qt/capture_preferences_frame.cpp b/ui/qt/capture_preferences_frame.cpp
index dd3a3417ea..5aea33ff84 100644
--- a/ui/qt/capture_preferences_frame.cpp
+++ b/ui/qt/capture_preferences_frame.cpp
@@ -28,7 +28,7 @@
#include <QSpacerItem>
-#include "capture_ui_utils.h"
+#include "ui/capture_ui_utils.h"
#include "ui/ui_util.h"
#include <cstdio>
diff --git a/ui/qt/interface_tree.h b/ui/qt/interface_tree.h
index 6a63590221..e9331d9c4e 100644
--- a/ui/qt/interface_tree.h
+++ b/ui/qt/interface_tree.h
@@ -30,7 +30,7 @@
#include "capture.h"
#include "capture-pcap-util.h"
#include "capture_opts.h"
-#include "capture_ui_utils.h"
+#include "ui/capture_ui_utils.h"
#endif
#include <QTreeWidget>
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index ef4704bc4f..8efba08cb7 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -95,6 +95,9 @@
#include "ui/alert_box.h"
#include "ui/capture_globals.h"
+#ifdef HAVE_LIBPCAP
+# include "ui/capture_ui_utils.h"
+#endif
#include "ui/iface_lists.h"
#include "ui/main_statusbar.h"
#include "ui/persfilepath_opt.h"
@@ -103,7 +106,6 @@
#include "ui/ui_util.h"
#ifdef HAVE_LIBPCAP
-# include "capture_ui_utils.h"
# include "capture-pcap-util.h"
# include <capchild/capture_ifinfo.h>
# include "capture.h"
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 3dc1efbf79..ca87034192 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -33,11 +33,13 @@
#ifdef HAVE_LIBPCAP
#include "capture.h"
#include "capture-pcap-util.h"
-#include "capture_ui_utils.h"
#include "capture_session.h"
#endif
#include "ui/alert_box.h"
+#ifdef HAVE_LIBPCAP
+#include "ui/capture_ui_utils.h"
+#endif
#include "ui/capture_globals.h"
#include "ui/main_statusbar.h"
#include "ui/recent.h"
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp
index 69f5d61f1a..567287cca4 100644
--- a/ui/qt/main_window_slots.cpp
+++ b/ui/qt/main_window_slots.cpp
@@ -45,7 +45,6 @@
#ifdef HAVE_LIBPCAP
#include "capture.h"
#include "capture-pcap-util.h"
-#include "capture_ui_utils.h"
#endif
#include "wsutil/file_util.h"
@@ -56,6 +55,9 @@
#include <epan/value_string.h>
#include "ui/alert_box.h"
+#ifdef HAVE_LIBPCAP
+#include "ui/capture_ui_utils.h"
+#endif
#include "ui/ui_util.h"
#include "ui/capture_globals.h"
#include "ui/help_url.h"