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