diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c index b6aa4ad1d8..36e75b37e9 100644 --- a/ui/capture_ui_utils.c +++ b/ui/capture_ui_utils.c @@ -599,6 +599,48 @@ get_iface_list_string(capture_options *capture_opts, guint32 style) return iface_list_string; } +gchar * +get_iface_display_name(const gchar *description, const if_info_t *if_info) +{ + if (description && description[0]) { + /* We have a user-supplied description. */ +#ifdef _WIN32 + gchar *if_string = if_info->friendly_name ? if_info->friendly_name : if_info->name; + return g_strdup_printf("%s: %s", description, if_string); +#else + return g_strdup_printf("%s: %s", description, if_info->name); +#endif + } + + if (if_info->friendly_name) { + /* We have a friendly name from the OS. */ +#ifdef _WIN32 + /* + * On Windows, if we have a friendly name, just show it, + * don't show the name, as that's a string made out of + * the device GUID, and not at all friendly. + */ + return g_strdup_printf("%s", if_info->friendly_name); +#else + /* + * On UN*X, if we have a friendly name, show it along + * with the interface name; the interface name is short + * and somewhat friendly, and many UN*X users are used + * to interface names, so we should show it. + */ + return g_strdup_printf("%s: %s", if_info->friendly_name, if_info->name); +#endif + } + + if (if_info->vendor_description) { + /* We have a device description from libpcap. */ + return g_strdup_printf("%s: %s", if_info->vendor_description, if_info->name); + } + + /* No additional descriptions found. */ + return g_strdup(if_info->name); +} + #endif /* HAVE_LIBPCAP */ /* diff --git a/ui/capture_ui_utils.h b/ui/capture_ui_utils.h index eb4cdf9db5..5f6cdcd284 100644 --- a/ui/capture_ui_utils.h +++ b/ui/capture_ui_utils.h @@ -175,6 +175,15 @@ extern void set_active_dlt(interface_t *device, int global_default_dlt); extern GString *get_iface_list_string(capture_options *capture_opts, guint32 style); +/** Get the interface display name to present in the interfaces list. + * + * @param description A user-specified capture device description + * @param if_info The if_info for the interface + * + * @return A interface display name (must be g_free'd later) + */ +extern gchar *get_iface_display_name(const gchar *description, const if_info_t *if_info); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ui/iface_lists.c b/ui/iface_lists.c index b7eb749b32..bd8dd4a905 100644 --- a/ui/iface_lists.c +++ b/ui/iface_lists.c @@ -64,7 +64,6 @@ scan_local_interfaces(void (*update_cb)(void)) { GList *if_entry, *lt_entry, *if_list; if_info_t *if_info, temp; - char *if_string; gchar *descr; if_capabilities_t *caps=NULL; gint linktype_count; @@ -141,42 +140,9 @@ scan_local_interfaces(void (*update_cb)(void)) #endif /* Is this interface hidden and, if so, should we include it anyway? */ - /* 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->friendly_name != NULL) { - /* We have a friendly name from the OS, use it */ -#ifdef _WIN32 - /* - * On Windows, if we have a friendly name, just show it, - * don't show the name, as that's a string made out of - * the device GUID, and not at all friendly. - */ - if_string = g_strdup_printf("%s", if_info->friendly_name); -#else - /* - * On UN*X, if we have a friendly name, show it along - * with the interface name; the interface name is short - * and somewhat friendly, and many UN*X users are used - * to interface names, so we should show it. - */ - if_string = g_strdup_printf("%s: %s", if_info->friendly_name, if_info->name); -#endif - } else if (if_info->vendor_description != NULL) { - /* We have a device description from libpcap - 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); - } - } - device.display_name = if_string; + device.display_name = get_iface_display_name(descr, if_info); + g_free(descr); device.selected = FALSE; if (prefs_is_capture_device_hidden(if_info->name)) { device.hidden = TRUE; diff --git a/ui/qt/manage_interfaces_dialog.cpp b/ui/qt/manage_interfaces_dialog.cpp index 5f1e11ae89..89feac1621 100644 --- a/ui/qt/manage_interfaces_dialog.cpp +++ b/ui/qt/manage_interfaces_dialog.cpp @@ -389,14 +389,7 @@ void ManageInterfacesDialog::saveLocalCommentChanges(QTreeWidgetItem* item) } g_free(device.display_name); - // XXX The GTK+ UI uses the raw device name instead of the friendly name. - // This seems to make more sense. - gchar *if_string = device.friendly_name ? device.friendly_name : device.name; - if (comment.isEmpty()) { - device.display_name = g_strdup(if_string); - } else { - device.display_name = qstring_strdup(QString("%1: %2").arg(comment).arg(if_string)); - } + device.display_name = get_iface_display_name(comment.toUtf8().constData(), &device.if_info); global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); g_array_insert_val(global_capture_opts.all_ifaces, i, device); }