From: Guy Harris Date: Thu, 29 Apr 2021 18:35:07 +0000 (-0700) Subject: Move NPF_SURFACE_MOBILE_NONPROMISC to pcap-npf.c. X-Git-Tag: libpcap-1.10.1~18 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/6deed0abb9ef7a186cedf9fbbdd412fe280a69ef?ds=sidebyside Move NPF_SURFACE_MOBILE_NONPROMISC to pcap-npf.c. It's an error code seen only for NPF devices, so move it there. While we're at it, make only one GetLastError() call for the case that can get that error. (cherry picked from commit cdcc34ad751d5aa5998d5af7cbfce9f4cb440a97) --- diff --git a/pcap-int.h b/pcap-int.h index 60e939f1..dc18d50c 100644 --- a/pcap-int.h +++ b/pcap-int.h @@ -350,17 +350,6 @@ struct pcap { * BPF code generation flags. */ #define BPF_SPECIAL_VLAN_HANDLING 0x00000001 /* special VLAN handling for Linux */ -/* - * Interface Error Codes - * It is likely that there are other devices which throw spurious errors, at which point - * this will need refactoring to efficiently check against a list, but for now we can just - * check this one value. - */ -#define NPF_SURFACE_MOBILE_NONPROMISC 0xe00000bb -/* Attempting to set non-promiscuous mode on a noncompliant Microsoft Surface Pro - * Mobile Broadband Adapter returns an error that can safely be ignored, as it's - * always in non-promiscuous mode. - */ /* * This is a timeval as stored in a savefile. diff --git a/pcap-npf.c b/pcap-npf.c index 141ff88a..6e9e0f04 100644 --- a/pcap-npf.c +++ b/pcap-npf.c @@ -939,6 +939,27 @@ pcap_breakloop_npf(pcap_t *p) SetEvent(PacketGetReadEvent(pw->adapter)); } +/* + * Vendor-specific error codes. + * + * These are NTSTATUS values: + * + * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781 + * + * with the "Customer" bit set. If a driver returns them, they are not + * mapped to Windows error values in userland; they're returned by + * GetLastError(). + * + * Attempting to set non-promiscuous mode on a Microsoft Surface Pro's + * Mobile Broadband Adapter returns an error; that error can safely be + * ignored, as it's always in non-promiscuous mode. + * + * It is likely that there are other devices which throw spurious errors, + * at which point this will need refactoring to efficiently check against + * a list, but for now we can just check this one value. + */ +#define NPF_SURFACE_MOBILE_NONPROMISC 0xe00000bb + static int pcap_activate_npf(pcap_t *p) { @@ -1210,11 +1231,13 @@ pcap_activate_npf(pcap_t *p) } else { - /* NDIS_PACKET_TYPE_ALL_LOCAL selects "All packets sent by installed - * protocols and all packets indicated by the NIC" but if no protocol - * drivers (like TCP/IP) are installed, NDIS_PACKET_TYPE_DIRECTED, - * NDIS_PACKET_TYPE_BROADCAST, and NDIS_PACKET_TYPE_MULTICAST are needed to - * capture incoming frames. + /* + * NDIS_PACKET_TYPE_ALL_LOCAL selects "All packets sent by + * installed protocols and all packets indicated by the NIC", + * but if no protocol drivers (like TCP/IP) are installed, + * NDIS_PACKET_TYPE_DIRECTED, NDIS_PACKET_TYPE_BROADCAST, + * and NDIS_PACKET_TYPE_MULTICAST are needed to capture + * incoming frames. */ if (PacketSetHwFilter(pw->adapter, NDIS_PACKET_TYPE_ALL_LOCAL | @@ -1222,11 +1245,16 @@ pcap_activate_npf(pcap_t *p) NDIS_PACKET_TYPE_BROADCAST | NDIS_PACKET_TYPE_MULTICAST) == FALSE) { - /* suppress spurious error generated by noncompiant MS Surface mobile adaptors */ - if (GetLastError() != NPF_SURFACE_MOBILE_NONPROMISC) + DWORD errcode = GetLastError(); + + /* + * Suppress spurious error generated by non-compiant + * MS Surface mobile adaptors + */ + if (errcode != NPF_SURFACE_MOBILE_NONPROMISC) { pcap_fmt_errmsg_for_win32_err(p->errbuf, - PCAP_ERRBUF_SIZE, GetLastError(), + PCAP_ERRBUF_SIZE, errcode, "failed to set hardware filter to non-promiscuous mode"); goto bad; }