Home › Forums › Discussions › Support › if i have two or more adapter connect to the Internet
- This topic has 3 replies, 2 voices, and was last updated 19 years, 9 months ago by Vadim Smirnov.
-
AuthorPosts
-
March 1, 2005 at 3:35 pm #4906
if i have two or more adapter connect to the internet, how i find adapter that send packter automatically? or Can winpkfiler capture the packet of all adapter that connect to the Internet?
March 1, 2005 at 3:46 pm #5702With WinpkFilter you can capture packets from any amount of adapters (using dedicated for each with WaitForSingleObject, or using single thread for all adapters with WaitForMultiplyObjects).
Another question is how to determine wich adapters are of your interest (connected to the Internet). There is no universal way to do it. If default Internet connection can be determined as the default route (0.0.0.0 mask 0.0.0.0) then other Internet connections look similar to LAN connections.
March 2, 2005 at 12:32 pm #5703Can you give me an example for WaitForMultiplyObjects? i can’t create thread for each adapter because it waste my time for recreate the whole system.
March 2, 2005 at 1:43 pm #5704An example, it can be done like in the code below (I’m sorry C code only)
TCP_AdapterList AdList;
CNdisApi api;
ETH_REQUEST Request;
INTERMEDIATE_BUFFER PacketBuffer;
HANDLE hEvent[32];
DWORD dwAdapterCount;
int InitHandles()
{
api.GetTcpipBoundAdaptersInfo ( &AdList );
ADAPTER_MODE Mode;
Mode.dwFlags = MSTCP_FLAG_SENT_TUNNEL|MSTCP_FLAG_RECV_TUNNEL;
dwAdapterCount = AdList.m_nAdapterCount ;
// Create notification events
for(int nCount = 0; nCount < dwAdapterCount; nCount++)
{
hEvent[nCount] = CreateEvent(NULL, TRUE, FALSE, NULL);
Mode.hAdapterHandle = (HANDLE)AdList.m_nAdapterHandle[nCount];
// Set event for helper driver
if ((!hEvent[nCount])||(!api.SetPacketEvent((HANDLE)AdList.m_nAdapterHandle[nCount], hEvent[nCount])))
{
printf ("Failed to create notification event or set it for driver.n");
return 0;
}
api.SetAdapterMode(&Mode);
}
return 1;
}
void ReleaseHandles()
{
// This function releases packets in the adapter queue and stops listening the interface
ADAPTER_MODE Mode;
for(int nCount = 0; nCount < dwAdapterCount; nCount++)
{
Mode.dwFlags = 0;
Mode.hAdapterHandle = (HANDLE)AdList.m_nAdapterHandle[nCount];
// Set NULL event to release previously set event object
api.SetPacketEvent(AdList.m_nAdapterHandle[nCount], NULL);
// Close Event
if (hEvent[nCount])
CloseHandle ( hEvent[nCount+1] );
// Set default adapter mode
api.SetAdapterMode(&Mode);
// Empty adapter packets queue
api.FlushAdapterPacketQueue (AdList.m_nAdapterHandle[nCount]);
}
}
int main(int argc, char* argv[])
{
ether_header* pEthHeader = NULL;
iphdr* pIpHeader = NULL;
DWORD dwEvent;
.............
if(!api.IsDriverLoaded())
{
printf ("Driver not installed on this system of failed to load.n");
return 0;
}
InitHandles();
atexit (ReleaseHandles);
while (TRUE)
{
dwEvent = WaitForMultipleObjects (dwAdapterCount, hEvent, FALSE, INFINITE );
ResetEvent(hEvent[dwEvent]);
// Initialize Request
ZeroMemory ( &Request, sizeof(ETH_REQUEST) );
ZeroMemory ( &PacketBuffer, sizeof(INTERMEDIATE_BUFFER) );
Request.EthPacket.Buffer = &PacketBuffer;
Request.hAdapterHandle = (HANDLE)AdList.m_nAdapterHandle[dwEvent-1];
while(api.ReadPacket(&Request))
{
pEthHeader = (ether_header*)PacketBuffer.m_IBuffer;
pIpHeader = (iphdr*)(PacketBuffer.m_IBuffer + ETHER_HEADER_LENGTH);
if (PacketBuffer.m_dwDeviceFlags == PACKET_FLAG_ON_SEND)
{
// Place packet on the network interface
api.SendPacketToAdapter(&Request);
}
else
{
// Indicate packet to MSTCP
api.SendPacketToMstcp(&Request);
}
}
}
return 0;
} -
AuthorPosts
- You must be logged in to reply to this topic.