Skip to content

Commit

Permalink
Avoid retrieving link speed, unused by libpcap
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed May 13, 2022
1 parent 8c1c570 commit 6590202
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
Errors from lower functions are correctly propagated, making diagnosis of failures easier. Fixes
[#168](http://issues.npcap.org/168), [#61](http://issues.npcap.org/61), and [#586](http://issues.npcap.org/586).

* PacketGetNetType() now always sets the LinkSpeed field to 0. Many adapters did not support the OID
that was being used to get the link speed, and libpcap (Npcap's published API) does not pass this
information through, so there should be no impact on the majority of software. Software that needs
link speed may use `pcap_oid_get_request()` or `GetAdaptersAddresses()` to get the information.

* Npcap is only supported on Windows 7 SP1 and later, and requires KB4474419 to support SHA-2
signature validation. The installer will now check these specific requirements, rather than
attempting an installation that will fail anyway.
Expand Down
4 changes: 2 additions & 2 deletions Common/Packet32.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ typedef struct _AirpcapHandle* PAirpcapHandle;
/*!
\brief Network type structure.
This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.
This structure is used by the PacketGetNetType() function to return information on the current adapter's type.
*/
typedef struct NetType
{
UINT LinkType; ///< The MAC of the current network adapter (see function PacketGetNetType() for more information)
ULONGLONG LinkSpeed; ///< The speed of the network in bits per second
ULONGLONG LinkSpeed; /// UNUSED, set to 0
}NetType;


Expand Down
52 changes: 14 additions & 38 deletions packetWin7/Dll/Packet32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3439,60 +3439,36 @@ BOOLEAN PacketGetNetType(LPADAPTER AdapterObject, NetType *type)
break;
}
}
//
// For the moment, we always set the speed to 54Mbps, since the speed is not channel-specific,
// but per packet
//
type->LinkSpeed = 54000000;
}
else
#endif // HAVE_AIRPCAP_API
{
// If this is our loopback adapter, use static values.
if (AdapterObject->Flags & INFO_FLAG_NPCAP_LOOPBACK) {
type->LinkType = (UINT) NdisMediumNull;
type->LinkSpeed = 10 * 1000 * 1000; //we emulate a fake 10MBit Ethernet
}
// request the media type from the driver
else do
{
// Request the link speed
// If this is a WIFI_ adapter, change the link type.
else if (AdapterObject->Flags & INFO_FLAG_NPCAP_DOT11) {
type->LinkType = (UINT)NdisMediumRadio80211;
}
else {
//get the link-layer type
PPACKET_OID_DATA OidData = (PPACKET_OID_DATA) IoCtlBuffer;
//get the link-layer speed
OidData->Oid = OID_GEN_LINK_SPEED_EX;
OidData->Length = sizeof(NDIS_LINK_SPEED);

OidData->Oid = OID_GEN_MEDIA_IN_USE;
OidData->Length = sizeof (ULONG);
if (!PacketRequest(AdapterObject, FALSE, OidData)) {
err = GetLastError();
TRACE_PRINT1("PacketRequest(OID_GEN_LINK_SPEED_EX) error: %d", err);
break;
TRACE_PRINT1("PacketGetLinkLayerFromRegistry error: %d", err);
}
else {
PNDIS_LINK_SPEED NdisSpeed = (PNDIS_LINK_SPEED)OidData->Data;
// Average of Xmit and Rcv speeds is historical. Maybe we should report min instead?
type->LinkSpeed = (NdisSpeed->XmitLinkSpeed + NdisSpeed->RcvLinkSpeed) / 2;
type->LinkType=*((UINT*)OidData->Data);
}

// If this is a WIFI_ adapter, change the link type.
if (AdapterObject->Flags & INFO_FLAG_NPCAP_DOT11) {
type->LinkType = (UINT)NdisMediumRadio80211;
}
else {
ZeroMemory(IoCtlBuffer, sizeof(IoCtlBuffer));
//get the link-layer type
OidData->Oid = OID_GEN_MEDIA_IN_USE;
OidData->Length = sizeof (ULONG);
if (!PacketRequest(AdapterObject, FALSE, OidData)) {
err = GetLastError();
TRACE_PRINT1("PacketGetLinkLayerFromRegistry error: %d", err);
break;
}
else {
type->LinkType=*((UINT*)OidData->Data);
}
}
} while (FALSE);
}
}

// LinkSpeed is not supported
type->LinkSpeed = 0;
TRACE_EXIT();
SetLastError(err);
return (err == ERROR_SUCCESS);
Expand Down

0 comments on commit 6590202

Please sign in to comment.