Add an additional DONT_HAVE_PCAP return value from get_interface_list()

and capture_interface_list().  Return it if, on Windows, we ask for the
interface list but don't have WinPcap installed.  Handle it like
CANT_GET_INTERFACE_LIST.

svn path=/trunk/; revision=40334
This commit is contained in:
Guy Harris 2011-12-29 22:49:49 +00:00
parent 21f5ea24e4
commit 3864d5d19d
9 changed files with 28 additions and 4 deletions

View File

@ -35,6 +35,8 @@
#include "capture_ifinfo.h"
#include "capture-pcap-util.h"
#include "capture-pcap-util-int.h"
#include "capture-wpcap.h"
#include "capture_errs.h"
#include <wsutil/file_util.h>
@ -694,6 +696,16 @@ get_interface_list(int *err, char **err_str)
int i, j;
char errbuf[PCAP_ERRBUF_SIZE];
if (!has_wpcap) {
/*
* We don't have WinPcap, so we can't get a list of
* interfaces.
*/
*err = DONT_HAVE_PCAP;
*err_str = cant_load_winpcap_err("you");
return NULL;
}
#ifdef HAVE_PCAP_FINDALLDEVS
if (p_pcap_findalldevs != NULL)
return get_interface_list_findalldevs(err, err_str);

View File

@ -64,6 +64,7 @@ extern GList *capture_interface_list(int *err, char **err_str);
/* Error values from "get_interface_list()/capture_interface_list()". */
#define CANT_GET_INTERFACE_LIST 1 /* error getting list */
#define NO_INTERFACES_FOUND 2 /* list is empty */
#define DONT_HAVE_PCAP 3 /* couldn't load WinPcap */
void free_interface_list(GList *if_list);

View File

@ -471,6 +471,7 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
cmdarg_err("%s", err_str);
g_free(err_str);
break;
@ -842,6 +843,7 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
cmdarg_err("%s", err_str);
g_free(err_str);
break;

View File

@ -1301,6 +1301,7 @@ print_statistics_loop(gboolean machine_readable)
if (if_list == NULL) {
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
cmdarg_err("%s", err_str);
g_free(err_str);
break;
@ -4207,6 +4208,7 @@ main(int argc, char *argv[])
if (if_list == NULL) {
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
cmdarg_err("%s", err_str);
g_free(err_str);
exit_main(2);

View File

@ -1068,7 +1068,8 @@ update_interface_list(void)
g_object_set_data(G_OBJECT(cap_open_w), E_CAP_IF_LIST_KEY, NULL);
}
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
if (if_list == NULL &&
(err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP)) {
gpointer dialog = simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
g_free(err_str);
@ -2765,7 +2766,8 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
if_list = capture_interface_list(&err, &err_str);
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
if (if_list == NULL &&
(err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
g_free(err_str);
}
@ -3727,7 +3729,8 @@ make_and_fill_rows(void)
/* Scan through the list and build a list of strings to display. */
if_list = capture_interface_list(&err, &err_str);
if_list = g_list_sort (if_list, if_list_comparator_alph);
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
if (if_list == NULL &&
(err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
g_free(err_str);
return;

View File

@ -763,6 +763,7 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
g_free(err_str);
break;

View File

@ -2207,6 +2207,7 @@ main(int argc, char *argv[])
if (if_list == NULL) {
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
cmdarg_err("%s", err_str);
g_free(err_str);
break;

View File

@ -971,7 +971,8 @@ welcome_if_tree_load(void)
interfaces = g_array_new(TRUE, TRUE, sizeof(displayed_interface));
if_list = capture_interface_list(&err, &err_str);
if_list = g_list_sort (if_list, if_list_comparator_alph);
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
if (if_list == NULL &&
(err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
g_free(err_str);
return;

View File

@ -1138,6 +1138,7 @@ main(int argc, char *argv[])
if (if_list == NULL) {
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
cmdarg_err("%s", err_str);
g_free(err_str);
break;