From: Guy Harris Date: Wed, 2 May 2018 19:08:27 +0000 (-0700) Subject: Use OID_GEN_LINK_STATE rather than OID_GEN_MEDIA_CONNECT_STATUS_EX. X-Git-Tag: libpcap-1.9-bp~51 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/0d3df9488a5a19cb2b15f96ee8529aa5822045d2 Use OID_GEN_LINK_STATE rather than OID_GEN_MEDIA_CONNECT_STATUS_EX. According to https://www.osronline.com/ShowThread.cfm?link=235910 "LWFs are not allowed to query certain deprecated OIDs, including OID_GEN_LINK_SPEED, OID_GEN_MEDIA_CONNECT_STATUS, and OID_GEN_MAXIMUM_FRAME_SIZE. These queries will always fail. Instead, query OID_GEN_LINK_STATE." An "LWF" is a lightweight filter driver; the Npcap driver is a lightweight filter driver. The post in question doesn't say whether OID_GEN_MEDIA_CONNECT_STATUS_EX is banned; it's what OID_GEN_MEDIA_CONNECT_STATUS was deprecated in favor of, so maybe it's not banned, but, from that post, it's in the "unknown" state rather than the "connected" or "disconnected" state. :-) Let's use OID_GEN_LINK_STATE instead; if we ever provide a new API to provide more interface attributes, it'll also let us provide the link speed. --- diff --git a/pcap-npf.c b/pcap-npf.c index 0b3dfea3..f33f3114 100644 --- a/pcap-npf.c +++ b/pcap-npf.c @@ -1450,10 +1450,10 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) #define N_GEN_PHYSICAL_MEDIUM_OIDS (sizeof gen_physical_medium_oids / sizeof gen_physical_medium_oids[0]) size_t i; #endif /* OID_GEN_PHYSICAL_MEDIUM */ -#ifdef OID_GEN_MEDIA_CONNECT_STATUS_EX - NET_IF_MEDIA_CONNECT_STATE connect_state_ex; +#ifdef OID_GEN_LINK_STATE + NDIS_LINK_STATE link_state; #endif - int connect_state; + int connect_status; if (*flags & PCAP_IF_LOOPBACK) { /* @@ -1604,12 +1604,16 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) /* * Get the connection status. */ -#ifdef OID_GEN_MEDIA_CONNECT_STATUS_EX - len = sizeof(connect_state_ex); - status = oid_get_request(adapter, OID_GEN_MEDIA_CONNECT_STATUS_EX, - &connect_state_ex, &len, errbuf); +#ifdef OID_GEN_LINK_STATE + len = sizeof(link_state); + status = oid_get_request(adapter, OID_GEN_LINK_STATE, &link_state, + &len, errbuf); if (status == 0) { - switch (connect_state_ex) { + /* + * NOTE: this also gives us the receive and transmit + * link state. + */ + switch (link_state.MediaConnectState) { case MediaConnectStateConnected: /* @@ -1628,20 +1632,19 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) } #else /* - * OID_GEN_MEDIA_CONNECT_STATUS_EX isn't supported because it's - * not in our SDK. + * OID_GEN_LINK_STATE isn't supported because it's not in our SDK. */ status = -1; #endif if (status == -1) { /* - * OK, OID_GEN_MEDIA_CONNECT_STATUS_EX didn't work, - * try OID_GEN_MEDIA_CONNECT_STATUS. + * OK, OID_GEN_LINK_STATE didn't work, try + * OID_GEN_MEDIA_CONNECT_STATUS. */ status = oid_get_request(adapter, OID_GEN_MEDIA_CONNECT_STATUS, - &connect_state, &len, errbuf); + &connect_status, &len, errbuf); if (status == 0) { - switch (connect_state) { + switch (connect_status) { case NdisMediaStateConnected: /*