Skip to content

Commit

Permalink
Avoid allocating/opening a full ADAPTER just for listing adapter names
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Apr 8, 2022
1 parent e9eccab commit b76ca89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packetWin7/Dll/AdInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static BOOLEAN PacketAddAdapterNPF(PIP_ADAPTER_ADDRESSES pAdapterAddr)
{
//this function should acquire the g_AdaptersInfoMutex, since it's NOT called with an ADAPTER_INFO as parameter
LONG Status;
LPADAPTER adapter = NULL;
HANDLE hAdapter = INVALID_HANDLE_VALUE;
PADAPTER_INFO TmpAdInfo;
PADAPTER_INFO TAdInfo;
CHAR AdName[ADAPTER_NAME_LENGTH];
Expand Down Expand Up @@ -178,9 +178,9 @@ static BOOLEAN PacketAddAdapterNPF(PIP_ADAPTER_ADDRESSES pAdapterAddr)
TRACE_PRINT("Trying to open the NPF adapter and see if it's available...");

// Try to Open the adapter
adapter = PacketOpenAdapterNPF(AdName);
hAdapter = PacketGetAdapterHandle(AdName);

if(adapter == NULL)
if(hAdapter == INVALID_HANDLE_VALUE)
{
TRACE_PRINT("NPF Adapter not available, do not add it to the global list");
// We are not able to open this adapter. Skip to the next one.
Expand All @@ -189,7 +189,7 @@ static BOOLEAN PacketAddAdapterNPF(PIP_ADAPTER_ADDRESSES pAdapterAddr)
return FALSE;
}

PacketCloseAdapter(adapter);
CloseHandle(hAdapter);

//
// PacketOpenAdapter was succesful. Consider this a valid adapter and allocate an entry for it
Expand Down
2 changes: 2 additions & 0 deletions packetWin7/Dll/Packet32-Int.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ BOOLEAN PacketUpdateAdInfo(_In_ PCCH AdapterName);
_Ret_maybenull_
LPADAPTER PacketOpenAdapterNPF(_In_ PCCH AdapterName);

HANDLE PacketGetAdapterHandle(_In_ PCCH AdapterNameA);

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
3 changes: 2 additions & 1 deletion packetWin7/Dll/Packet32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,8 @@ BOOL PacketStartService()
return Result;
}

static HANDLE PacketGetAdapterHandle(PCCH AdapterNameA)
_Use_decl_annotations_
HANDLE PacketGetAdapterHandle(PCCH AdapterNameA)
{
CHAR SymbolicLinkA[MAX_PATH] = {0};
HRESULT hrStatus = S_OK;
Expand Down

0 comments on commit b76ca89

Please sign in to comment.