From: Guy Harris Date: Wed, 3 Jul 2019 20:54:36 +0000 (-0700) Subject: Report PCAP_ERROR_NO_SUCH_DEVICE for a non-existent device. X-Git-Tag: libpcap-1.10-bp~472 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/7850af83ae9119f35ed56e4e29dabb3a78e2e485?ds=sidebyside Report PCAP_ERROR_NO_SUCH_DEVICE for a non-existent device. --- diff --git a/pcap-npf.c b/pcap-npf.c index 15018da9..09969f3d 100644 --- a/pcap-npf.c +++ b/pcap-npf.c @@ -938,14 +938,28 @@ pcap_activate_npf(pcap_t *p) if (pw->adapter == NULL) { - /* Adapter detected but we are not able to open it. Return failure. */ - pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, - GetLastError(), "Error opening adapter"); - if (pw->rfmon_selfstart) - { - PacketSetMonitorMode(p->opt.device, 0); + DWORD errcode = GetLastError(); + + /* + * What error did we get when trying to open the adapter? + */ + if (errcode == ERROR_BAD_UNIT) { + /* + * There's no such device. + */ + return (PCAP_ERROR_NO_SUCH_DEVICE); + } else { + /* + * Unknown - report details. + */ + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + errcode, "Error opening adapter"); + if (pw->rfmon_selfstart) + { + PacketSetMonitorMode(p->opt.device, 0); + } + return (PCAP_ERROR); } - return (PCAP_ERROR); } /*get network type*/