summaryrefslogtreecommitdiff
path: root/gtk/capture_dlg.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-09-10 05:35:26 +0000
committerGuy Harris <guy@alum.mit.edu>2003-09-10 05:35:26 +0000
commit27ea7816ee9c4613a4272ee6ddadb65a02a8233b (patch)
treef4f2db48edccdb7e402fef88f3c4672bf5991283 /gtk/capture_dlg.c
parentdf25d4167371367c9e8e19ccde6135250a174846 (diff)
downloadwireshark-27ea7816ee9c4613a4272ee6ddadb65a02a8233b.tar.gz
Have "get_interface_list()" return a list of "if_info_t" structures
containing a pointer to an interface name and possibly a pointer to an interface description (although that pointer might be null if no description is available), rather than having the Windows version glue together the name and description into a single string. Supply for the Linux "any" device the same description that libpcap's "pcap_findalldevs()" returns. svn path=/trunk/; revision=8440
Diffstat (limited to 'gtk/capture_dlg.c')
-rw-r--r--gtk/capture_dlg.c178
1 files changed, 12 insertions, 166 deletions
diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c
index 1331b69b14..98d835c54c 100644
--- a/gtk/capture_dlg.c
+++ b/gtk/capture_dlg.c
@@ -1,7 +1,7 @@
/* capture_dlg.c
* Routines for packet capture windows
*
- * $Id: capture_dlg.c,v 1.80 2003/09/08 21:44:42 guy Exp $
+ * $Id: capture_dlg.c,v 1.81 2003/09/10 05:35:25 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -43,6 +43,7 @@
#include "simple_dialog.h"
#include "dlg_utils.h"
#include "pcap-util.h"
+#include "capture_combo_utils.h"
#include "prefs.h"
#include "ringbuffer.h"
#include <epan/filesystem.h>
@@ -104,15 +105,6 @@ capture_prep_close_cb(GtkWidget *close_bt, gpointer parent_w);
static void
capture_prep_destroy_cb(GtkWidget *win, gpointer user_data);
-static GList *
-capture_dev_descr_add(GList *if_list);
-
-static char *
-capture_dev_descr_find(gchar *devs_descr, gchar *if_name);
-
-static GList *
-capture_dev_hide(GList *if_list);
-
void
capture_stop_cb(GtkWidget *w _U_, gpointer d _U_)
{
@@ -155,7 +147,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
#endif
GtkAdjustment *snap_adj, *ringbuffer_nbf_adj,
*count_adj, *filesize_adj, *duration_adj, *ring_duration_adj;
- GList *if_list;
+ GList *if_list, *combo_list;
int err;
char err_str[PCAP_ERRBUF_SIZE];
@@ -230,15 +222,9 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
gtk_widget_show(if_lb);
if_cb = gtk_combo_new();
- if (if_list != NULL) {
- /* remove interface(s) from list if "hidden" */
- if (prefs.capture_devices_hide != NULL)
- if_list = capture_dev_hide(if_list);
- /* prepend interface descriptions to device name */
- if (prefs.capture_devices_descr != NULL)
- if_list = capture_dev_descr_add(if_list);
- gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), if_list);
- }
+ combo_list = build_capture_combo_list(if_list, TRUE);
+ gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
+ free_capture_combo_list(combo_list);
if (cfile.iface == NULL && prefs.capture_device != NULL) {
/* No interface was specified on the command line or in a previous
capture, but there is one specified in the preferences file;
@@ -247,13 +233,14 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
}
if (cfile.iface != NULL)
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), cfile.iface);
- else if (if_list != NULL)
- gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), if_list->data);
+ else if (if_list != NULL) {
+ gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry),
+ ((if_info_t *)(if_list->data))->name);
+ }
+ free_interface_list(if_list);
gtk_box_pack_start(GTK_BOX(if_hb), if_cb, TRUE, TRUE, 6);
gtk_widget_show(if_cb);
- free_interface_list(if_list);
-
/* Capture length row */
snap_hb = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(capture_vb), snap_hb);
@@ -807,7 +794,7 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
/* Remove interface description. Also, Windows combo entries have a
description followed by the interface name. These two cases are
- OK as long as they're in front (see capture_dev_descr_add()). */
+ OK as long as they're in front. */
if_name = strrchr(if_text, ' ');
if (if_name == NULL) {
if_name = if_text;
@@ -1075,145 +1062,4 @@ capture_prep_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
}
-/*
- * Prepend capture devices description to interface list. Remove OS (pcap)
- * supplied description if present.
- */
-static GList *
-capture_dev_descr_add(GList *if_list)
-{
-
- GList *if_new_list = NULL;
- char *osd;
- char *tmp_descr;
- gchar *tmp_devs_descr;
- gchar *tmp_dev_name;
- guint i;
- guint nitems;
-
- /* Seems we need to be at list head for g_list_length()? */
- if_list = g_list_first(if_list);
- nitems = g_list_length(if_list);
-
- /* Create new interface list with "(descr) if_name". */
- for (i=0; i < nitems; i++) {
- tmp_dev_name = g_list_nth_data(if_list, i);
- /* should never happen, but just in case */
- if (tmp_dev_name == NULL) {
- if (if_new_list != NULL)
- free_interface_list(if_new_list);
- return if_list;
- }
- /* create copy since capture_dev_descr_find() inserts terminator */
- tmp_devs_descr = g_strdup(prefs.capture_devices_descr);
- /* find matching description */
- tmp_descr = capture_dev_descr_find(tmp_devs_descr, tmp_dev_name);
- /* prepend description */
- if (tmp_descr != NULL) {
- /* remove OS (pcap) description */
- if ((osd = strrchr(tmp_dev_name, ' ')) != NULL) {
- osd++;
- if (osd != NULL)
- tmp_dev_name = osd;
- }
- if_new_list = g_list_append(if_new_list,
- g_strdup_printf("%s %s", tmp_descr, tmp_dev_name));
- }
- /* no description for this interface, just copy name */
- else {
- if_new_list = g_list_append(if_new_list, g_strdup(tmp_dev_name));
- }
- g_free(tmp_devs_descr);
- }
-
- free_interface_list(if_list);
- /* return pointer to new interface list with descriptions */
- return if_new_list;
-}
-
-/*
- * Find capture device description that matches interface name.
- */
-static char *
-capture_dev_descr_find(gchar *devs_descr, gchar *if_name)
-{
- char *p;
- char *p2 = NULL;
- char *descr = NULL;
- int lp = 0;
- int ct = 0;
-
- if (if_name == NULL)
- return NULL;
-
- if ((p = strstr(devs_descr, if_name)) == NULL)
- return NULL;
-
- while (p != NULL) {
- /* error: ran into next interface description */
- if (*p == ',')
- return NULL;
- /* found left parenthesis, start of description */
- else if (*p == '(') {
- lp++;
- /* save pointer to beginning of description */
- p2 = p;
- p++;
- continue;
- }
- else if (*p == ')') {
- /* end of description */
- break;
- }
- else {
- p++;
- ct++;
- }
- }
-
- if ((lp == 1) && (ct > 0) && (p2 != NULL)) {
- /* set returned pointer to beginning of description */
- descr = p2;
- /* insert terminator */
- *(p+1) = '\0';
- return descr;
- }
- else
- return NULL;
-}
-
-/*
- * Remove "hidden" interface(s) from list.
- */
-static GList *
-capture_dev_hide(GList *if_list)
-{
- GList *if_new_list = NULL;
- gchar *tmp_dev_name;
- guint i;
- guint nitems;
-
- /* Seems we need to be at list head for g_list_length()? */
- if_list = g_list_first(if_list);
- nitems = g_list_length(if_list);
-
- /* Create new list without "hidden" interfaces. */
- for (i=0; i < nitems; i++) {
- tmp_dev_name = g_list_nth_data(if_list, i);
- /* should never happen, but just in case */
- if (tmp_dev_name == NULL) {
- if (if_new_list != NULL)
- free_interface_list(if_new_list);
- return if_list;
- }
- /* check if interface name is in "hidden" preferences string */
- if (strstr(prefs.capture_devices_hide, tmp_dev_name) == NULL)
- if_new_list = g_list_append(if_new_list, g_strdup(tmp_dev_name));
- }
-
- free_interface_list(if_list);
- /* return pointer to new interface list */
- return if_new_list;
-}
-
#endif /* HAVE_LIBPCAP */