Wednesday

[solved] OMNeT++ and WinPcap c:/mingw32/bin/ld.exe: cannot find -lpcap, error: 'PCAP_SRC_IF_STRING' undeclared

Problem 1:
On the MSYS Bash Shell,
$ gcc -o testprog testprog.c -lpcap
c:/omnetpp-4.1-rc2-src-windows/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: cannot find -lpcap

Solution. Change from -lpcap to -lwpcap:
$ gcc -o testprog testprog.c -lwpcap
This is because
C:\omnetpp-4.1-rc2-src-windows\mingw\lib\wpcap.lib and
C:\omnetpp-4.1-rc2-src-windows\mingw\lib\libwpcap.a.

Problem 2:
$ gcc -o testprog testprog.c -lwpcap
testprog.c: In function 'main':
testprog.c:12:29: error: 'PCAP_SRC_IF_STRING' undeclared (first use in this function)

Solution:
Change from
//if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
to
if (pcap_findalldevs_ex("127.0.0.1", NULL, &alldevs, errbuf) == -1)
{
...
}
The 127.0.0.1 is the localhost IP number.

Run it. On my Windows 7 workstation, the obtained result is:
$ testprog
1. rpcap://\Device\NPF_{88888888-4444-4444-4444-48D0E52A0B83} (Network adapter 'Atheros(NDIS6.20)' on local host)
2. rpcap://\Device\NPF_{88888888-4444-4444-4444-8B5EC6C7F430} (Network adapter 'Sun' on local host)

No comments:

Measure execution time with Julia, example using sorting algorithms

# random integers between 1 and 100 inclusive, generate thousands of them x = rand ( 1 : 100 , 100000 ) @time sort (x; alg=InsertionSort, r...