diff options
author | Guy Harris <guy@alum.mit.edu> | 1999-09-08 05:41:25 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 1999-09-08 05:41:25 +0000 |
commit | 28009b86d2e89c31e5457702df9af1a513588c2a (patch) | |
tree | 0051089401b5d849594c0f19ffe6c30c98d0b190 /capture.c | |
parent | cde9b4699cb4ad4865deb0d81ebe977d3dbc92f1 (diff) | |
download | wireshark-28009b86d2e89c31e5457702df9af1a513588c2a.tar.gz wireshark-28009b86d2e89c31e5457702df9af1a513588c2a.tar.bz2 wireshark-28009b86d2e89c31e5457702df9af1a513588c2a.zip |
Don't include in the list of interfaces offered by the "capture" dialog
box interfaces we can't open; this filters out loopback interfaces on
e.g. Solaris (which you can't get at with a DLPI device, so you can't
capture traffic on them), and also means we don't report *any*
interfaces if you don't have permission to open any (which means you
don't have permission to capture packets).
If we don't find any interfaces, pop up a message box saying so.
Free up the interface "ioctl" buffer, and close the socket we were
using, before returning from "get_interface_list()".
If "get_interface_list()" returns a null pointer (meaning it failed),
don't pop up the "capture" dialog box.
svn path=/trunk/; revision=634
Diffstat (limited to 'capture.c')
-rw-r--r-- | capture.c | 38 |
1 files changed, 32 insertions, 6 deletions
@@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.63 1999/09/01 03:04:09 gram Exp $ + * $Id: capture.c,v 1.64 1999/09/08 05:41:25 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -131,6 +131,8 @@ get_interface_list() { struct ifreq ifrflags; int sock = socket(AF_INET, SOCK_DGRAM, 0); struct search_user_data user_data; + pcap_t *pch; + gchar err_str[PCAP_ERRBUF_SIZE]; if (sock < 0) { @@ -149,7 +151,7 @@ get_interface_list() { { simple_dialog(ESD_TYPE_WARN, NULL, "Can't list interfaces: SIOCGIFCONF error: %s", strerror(errno)); - return NULL; + goto fail; } ifr = (struct ifreq *) ifc.ifc_req; @@ -197,6 +199,14 @@ get_interface_list() { goto next; /* + * Skip interfaces that we can't open with "libpcap". + */ + pch = pcap_open_live(ifr->ifr_name, WTAP_MAX_PACKET_SIZE, 0, 0, err_str); + if (pch == NULL) + goto next; + pcap_close(pch); + + /* * If it's a loopback interface, add it at the end of the list, * otherwise add it after the last non-loopback interface, * so all loopback interfaces go at the end - we don't want a @@ -221,11 +231,25 @@ next: } free(ifc.ifc_buf); + close(sock); + + if (il == NULL) { + simple_dialog(ESD_TYPE_WARN, NULL, + "There are no network interfaces that can be opened.\n" + "Please check to make sure you have sufficient permission\n" + "to capture packets."); + return NULL; + } + return il; fail: - g_list_foreach(il, free_if_cb, NULL); - g_list_free(il); + if (il != NULL) { + g_list_foreach(il, free_if_cb, NULL); + g_list_free(il); + } + free(ifc.ifc_buf); + close(sock); return NULL; } @@ -255,6 +279,10 @@ capture_prep_cb(GtkWidget *w, gpointer d) { GList *if_list, *count_list = NULL; gchar *count_item1 = "0 (Infinite)", count_item2[16]; + if_list = get_interface_list(); + if (if_list == NULL) + return; + cap_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(cap_open_w), "Ethereal: Capture Preferences"); @@ -273,8 +301,6 @@ capture_prep_cb(GtkWidget *w, gpointer d) { gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 0); gtk_widget_show(if_lb); - if_list = get_interface_list(); - if_cb = gtk_combo_new(); gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), if_list); if (cf.iface) |