Пытаюсь через ping перехватить девайс, через который идет трафик.
bool FindDevice( ) {
networkAdapters.clear();
pcap_if_t *alldevs = NULL;
// search for network devices
if( pcap_findalldevs( &alldevs, NULL ) == -1 )
return false;
unsigned devnum = 0;
char errbuf[PCAP_ERRBUF_SIZE];
for( pcap_if_t *curDev = alldevs; curDev != NULL; curDev = curDev->next, ++devnum ) // enumerate fonded devices
{
pcap_addr_t *addrs = NULL; // get network adapter ip-address
for( addrs = curDev->addresses; addrs != NULL; addrs = addrs->next )
if( addrs->addr->sa_family == AF_INET )
break;
if( pcap_t *capHandle = pcap_open_live(curDev->name, 65535, 0, 1, errbuf ) )
{
struct bpf_program bpf;
// create bpf filter for receiveing icmp packets, for current device
int rc = pcap_compile( capHandle, &bpf, "icmp[0] = 1 or icmp[0] = 8 and host google.com", 1, 0xFFFFFFFF );
if( rc < 0 )
{
pcap_close(capHandle);
continue;
}
rc = pcap_setfilter( capHandle, &bpf ); // Now set bpf filter
pcap_freecode( &bpf );
// handle packets for that device
NetworkAdapter netAdp( curDev, addrs, devnum, capHandle );
networkAdapters.push_back( netAdp );
netAdp.thread = ThreadCreate( reinterpret_cast<ThreadRoutine>(NetworkAdapter::CaptureIcmp), &networkAdapters.back() );
}
}
// all device listeners was run, now 'Ping' and determinate which device able to capture packets
//Ping("google.com");
system("ping google.com"); // в callback'e получаю TAP-Win32 Adapter V9. А хочется физ. адаптер D-Link :???: