Work around WinPcap bug wherein pcap_open() returns -1 without putting

an error message into errbuf (the bug has been reported to
winpcap-bugs).

Should fix bug 6922.

svn path=/trunk/; revision=41937
This commit is contained in:
Guy Harris 2012-04-04 19:13:39 +00:00
parent f2977b2f97
commit 9c781b0939
1 changed files with 17 additions and 2 deletions

View File

@ -1099,12 +1099,27 @@ get_if_capabilities(const char *devname, gboolean monitor_mode
*/
caps = g_malloc(sizeof *caps);
/*
* WinPcap 4.1.2, and possibly earlier versions, have a bug
* wherein, when an open with an rpcap: URL fails, the error
* message for the error is not copied to errbuf and whatever
* on-the-stack junk is in errbuf is treated as the error
* message.
*
* To work around that (and any other bugs of that sort, we
* initialize errbuf to an empty string. If we get an error
* and the string is empty, we report it as an unknown error.
* (If we *don't* get an error, and the string is *non*-empty,
* that could be a warning returned, such as "can't turn
* promiscuous mode on"; we currently don't do so.)
*/
errbuf[0] = '\0';
#ifdef HAVE_PCAP_OPEN
pch = pcap_open(devname, MIN_PACKET_SIZE, 0, 0, NULL, errbuf);
caps->can_set_rfmon = FALSE;
if (pch == NULL) {
if (err_str != NULL)
*err_str = g_strdup(errbuf);
*err_str = g_strdup(errbuf[0] == '\0' ? "Unknown error (pcap bug; actual error cause not reported)" : errbuf);
g_free(caps);
return NULL;
}
@ -1163,7 +1178,7 @@ get_if_capabilities(const char *devname, gboolean monitor_mode
caps->can_set_rfmon = FALSE;
if (pch == NULL) {
if (err_str != NULL)
*err_str = g_strdup(errbuf);
*err_str = g_strdup(errbuf[0] == '\0' ? "Unknown error (pcap bug; actual error cause not reported)" : errbuf);
g_free(caps);
return NULL;
}