1 /* capture_combo_utils.c
2 * Utilities for combo box of interface names
4 * $Id: capture_combo_utils.c,v 1.3 2003/11/03 10:36:45 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include "pcap-util.h"
38 #include "capture_combo_utils.h"
41 * Find capture device description that matches interface name.
44 capture_dev_descr_find(const gchar *if_name)
52 if (prefs.capture_devices_descr == NULL) {
53 /* There are no descriptions. */
57 if ((p = strstr(prefs.capture_devices_descr, if_name)) == NULL) {
58 /* There are, but there isn't one for this interface. */
63 /* error: ran into next interface description */
66 /* found left parenthesis, start of description */
70 /* skip over left parenthesis */
72 /* save pointer to beginning of description */
77 /* end of description */
86 if ((lp == 1) && (ct > 0) && (p2 != NULL)) {
87 /* Allocate enough space to return the string,
88 which runs from p2 to p, plus a terminating
90 descr = g_malloc(p - p2 + 1);
91 memcpy(descr, p2, p - p2);
100 build_capture_combo_list(GList *if_list, gboolean do_hide)
109 if (if_list != NULL) {
110 /* Scan through the list and build a list of strings to display. */
111 for (if_entry = if_list; if_entry != NULL;
112 if_entry = g_list_next(if_entry)) {
113 if_info = if_entry->data;
115 /* Is this interface hidden and, if so, should we include it
117 if (prefs.capture_devices_hide == NULL ||
118 strstr(prefs.capture_devices_hide, if_info->name) == NULL ||
120 /* It's not hidden, or it is but we should include it in the list. */
122 /* Do we have a user-supplied description? */
123 descr = capture_dev_descr_find(if_info->name);
125 /* Yes, we have a user-supplied description; use it. */
126 if_string = g_strdup_printf("%s: %s", descr, if_info->name);
129 /* No, we don't have a user-supplied description; did we get
130 one from the OS or libpcap? */
131 if (if_info->description != NULL) {
133 if_string = g_strdup_printf("%s: %s", if_info->description,
137 if_string = g_strdup(if_info->name);
140 combo_list = g_list_append(combo_list, if_string);
148 free_if_string(gpointer data, gpointer user_data _U_)
154 free_capture_combo_list(GList *combo_list)
156 if (combo_list != NULL) {
157 g_list_foreach(combo_list, free_if_string, NULL);
158 g_list_free(combo_list);
162 #endif /* HAVE_LIBPCAP */