]> The Tcpdump Group git mirrors - libpcap/commitdiff
Move NPF_SURFACE_MOBILE_NONPROMISC to pcap-npf.c.
authorGuy Harris <[email protected]>
Thu, 29 Apr 2021 18:35:07 +0000 (11:35 -0700)
committerGuy Harris <[email protected]>
Wed, 12 May 2021 08:11:24 +0000 (01:11 -0700)
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)

pcap-int.h
pcap-npf.c

index 60e939f17dafa4702b749b695f8142e2739285e8..dc18d50cb633ebb277c3617a9cad464a06182d95 100644 (file)
@@ -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.
index 141ff88af379f23bb818fcd83cedbfdcf0791b7e..6e9e0f04630695549710f588667800dfc951975e 100644 (file)
@@ -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;
                        }