diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-04-04 19:13:39 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-04-04 19:13:39 +0000 |
commit | 9c781b0939c6c4fc863f7f560bf46ca13349039a (patch) | |
tree | 6505481c7f4abfed700916115e2f0027fffa2882 /dumpcap.c | |
parent | f2977b2f97413f59b97e8c5851fb033ab643c670 (diff) |
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
Diffstat (limited to 'dumpcap.c')
-rw-r--r-- | dumpcap.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -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; } |