]> The Tcpdump Group git mirrors - libpcap/commitdiff
Don't try to distinguish "unsupported OID" from "hard error".
authorGuy Harris <[email protected]>
Mon, 30 Apr 2018 02:46:26 +0000 (19:46 -0700)
committerGuy Harris <[email protected]>
Mon, 30 Apr 2018 02:46:26 +0000 (19:46 -0700)
We don't seem to reliably get the NDIS "unsupported OID" errors from
packet.dll, so just treat *all* OID get errors as "try something else".

pcap-npf.c
pcap.c
pcap/pcap.h

index dbf2b617282e454d5237825e6213ab36fa5ea33a..c07c291783ecd0162e322154a4d290731e525d94 100644 (file)
@@ -129,11 +129,12 @@ PacketGetMonitorMode(PCHAR AdapterName _U_)
 /*
  * Sigh.  PacketRequest() will have made a DeviceIoControl()
  * call to the NPF driver to perform the OID request, with a
- * BIOCQUERYOID ioctl.  It looks as if the returned status
- * will be an NDIS_STATUS_ value, but those aren't defined
- * in any userland header.
- *
- * So we define them here.
+ * BIOCQUERYOID ioctl.  The kernel code should get back one
+ * of NDIS_STATUS_INVALID_OID, NDIS_STATUS_NOT_SUPPORTED,
+ * or NDIS_STATUS_NOT_RECOGNIZED if the OID request isn't
+ * supported by the OS or the driver, but that doesn't seem
+ * to make it to the caller of PacketRequest() in a
+ * reiable fashion.
  */
 #define NDIS_STATUS_INVALID_OID                0xc0010017
 #define NDIS_STATUS_NOT_SUPPORTED      0xc00000bb      /* STATUS_NOT_SUPPORTED */
@@ -165,22 +166,13 @@ oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp,
        oid_data_arg->Oid = oid;
        oid_data_arg->Length = (ULONG)(*lenp);  /* XXX - check for ridiculously large value? */
        if (!PacketRequest(adapter, FALSE, oid_data_arg)) {
-               int status;
-               DWORD request_error;
                char errmsgbuf[PCAP_ERRBUF_SIZE+1];
 
-               request_error = GetLastError();
-               if (request_error == NDIS_STATUS_INVALID_OID ||
-                   request_error == NDIS_STATUS_NOT_SUPPORTED ||
-                   request_error == NDIS_STATUS_NOT_RECOGNIZED)
-                       status = PCAP_ERROR_OPERATION_NOTSUP;
-               else
-                       status = PCAP_ERROR;
-               pcap_win32_err_to_str(request_error, errmsgbuf);
+               pcap_win32_err_to_str(GetLastError(), errmsgbuf);
                pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
                    "Error calling PacketRequest: %s", errmsgbuf);
                free(oid_data_arg);
-               return (status);
+               return (-1);
        }
 
        /*
@@ -1500,13 +1492,6 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
                len = sizeof (phys_medium);
                status = oid_get_request(adapter, gen_physical_medium_oids[i],
                    &phys_medium, &len, errbuf);
-               if (status == PCAP_ERROR) {
-                       /*
-                        * Failed with a hard error.
-                        */
-                       PacketCloseAdapter(adapter);
-                       return (-1);
-               }
                if (status == 0) {
                        /*
                         * Success.
@@ -1514,8 +1499,10 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
                        break;
                }
                /*
-                * Failed with "I don't support that OID", so try the
-                * next one, if we have a next one.
+                * Failed.  We can't determine whether it failed
+                * because that particular OID isn't supported
+                * or because some other problem occurred, so we
+                * just drive on and try the next OID.
                 */
        }
        if (status == 0) {
@@ -1546,13 +1533,6 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
        len = sizeof(connect_state_ex);
        status = oid_get_request(adapter, OID_GEN_MEDIA_CONNECT_STATUS_EX,
            &connect_state_ex, &len, errbuf);
-       if (status == PCAP_ERROR) {
-               /*
-                * Fatal error.
-                */
-               PacketCloseAdapter(adapter);
-               return (-1);
-       }
        if (status == 0) {
                switch (connect_state_ex) {
 
@@ -1576,22 +1556,15 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
         * OID_GEN_MEDIA_CONNECT_STATUS_EX isn't supported because it's
         * not in our SDK.
         */
-       status = PCAP_ERROR_OPERATION_NOTSUP;
+       status = -1;
 #endif
-       if (status == PCAP_ERROR_OPERATION_NOTSUP) {
+       if (status == -1) {
                /*
-                * OK, OID_GEN_MEDIA_CONNECT_STATUS_EX isn't supported,
+                * OK, OID_GEN_MEDIA_CONNECT_STATUS_EX didn't work,
                 * try OID_GEN_MEDIA_CONNECT_STATUS.
                 */
                status = oid_get_request(adapter, OID_GEN_MEDIA_CONNECT_STATUS,
                    &connect_state, &len, errbuf);
-               if (status == PCAP_ERROR) {
-                       /*
-                        * Fatal error.
-                        */
-                       PacketCloseAdapter(adapter);
-                       return (-1);
-               }
                if (status == 0) {
                        switch (connect_state) {
 
diff --git a/pcap.c b/pcap.c
index b2c2790968c8b74d6a673f56f3bfddd618b9160f..a60344e853f89abbf8aa904ccc259615b5c05a72 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -3312,9 +3312,6 @@ pcap_statustostr(int errnum)
 
        case PCAP_ERROR_TSTAMP_PRECISION_NOTSUP:
                return ("That device doesn't support that time stamp precision");
-
-       case PCAP_ERROR_OPERATION_NOTSUP:
-               return ("That device doesn't support that operation");
        }
        (void)pcap_snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
        return(ebuf);
index 4ea9592f484025e5c8389894015592b9121a8449..f809dd1145e4d900858836ef7eb02ab5a1574788 100644 (file)
@@ -302,7 +302,6 @@ typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
 #define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10     /* this device doesn't support setting the time stamp type */
 #define PCAP_ERROR_PROMISC_PERM_DENIED -11     /* you don't have permission to capture in promiscuous mode */
 #define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12  /* the requested time stamp precision is not supported */
-#define PCAP_ERROR_OPERATION_NOTSUP    -13     /* OID operation not supported by adapter */
 
 /*
  * Warning codes for the pcap API.