Skip to content

Commit

Permalink
Track loopback status in adapter object directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Apr 26, 2022
1 parent 9d87bae commit 4fc2b1c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Common/Packet32.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ typedef WAN_ADAPTER* PWAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...)
#define INFO_FLAG_AIRPCAP_CARD 16 ///< Flag for ADAPTER_INFO: this is an airpcap card
#define INFO_FLAG_NPFIM_DEVICE 32 /// NPFIM device, not supported
#define INFO_FLAG_MASK_NOT_NPF 0xff /// If any of these bits are set, it's not a NPF/Npcap-managed adapter.
#define INFO_FLAG_NPCAP_LOOPBACK 0x100

/*!
\brief Describes an opened network adapter.
Expand Down
3 changes: 0 additions & 3 deletions packetWin7/Dll/Packet32-Int.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ PADAPTER_INFO PacketFindAdInfo(_In_ PCCH AdapterName);
_Success_(return != 0)
BOOLEAN PacketUpdateAdInfo(_In_ PCCH AdapterName);

_Ret_maybenull_
LPADAPTER PacketOpenAdapterNPF(_In_ PCCH AdapterName);

HANDLE PacketGetAdapterHandle(_In_ PCCH AdapterNameA);

#ifdef __cplusplus
Expand Down
13 changes: 8 additions & 5 deletions packetWin7/Dll/Packet32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,7 @@ BOOLEAN PacketSetMaxLookaheadsize (LPADAPTER AdapterObject)

TRACE_ENTER();

_ASSERT(AdapterObject->Name[0] != '\0');
if (g_bLoopbackSupport && PacketIsLoopbackAdapter(AdapterObject->Name)) {
if (AdapterObject->Flags & INFO_FLAG_NPCAP_LOOPBACK) {
// Loopback adapter doesn't support this; fake success
TRACE_EXIT();
SetLastError(ERROR_SUCCESS);
Expand Down Expand Up @@ -1498,10 +1497,10 @@ HANDLE PacketGetAdapterHandle(PCCH AdapterNameA)
\return If the function succeeds, the return value is the pointer to a properly initialized ADAPTER object,
otherwise the return value is NULL.
\note internal function used by PacketOpenAdapter() and AddAdapter()
\note internal function used by PacketOpenAdapter()
*/
_Use_decl_annotations_
LPADAPTER PacketOpenAdapterNPF(PCCH AdapterNameA)
_Ret_maybenull_
LPADAPTER PacketOpenAdapterNPF(_In_ PCCH AdapterNameA)
{
DWORD error;
LPADAPTER lpAdapter;
Expand All @@ -1518,6 +1517,10 @@ LPADAPTER PacketOpenAdapterNPF(PCCH AdapterNameA)
return NULL;
}

if (g_bLoopbackSupport && PacketIsLoopbackAdapter(AdapterNameA)) {
lpAdapter->Flags |= INFO_FLAG_NPCAP_LOOPBACK;
}

lpAdapter->NumWrites=1;

lpAdapter->hFile = PacketGetAdapterHandle(AdapterNameA);
Expand Down

0 comments on commit 4fc2b1c

Please sign in to comment.