Reputation: 3807
I am trying to compile the following code:
#include <stdio.h>
#include <pcap.h>
#define listen_device "eth0"
int main(int argc, char *argv[])
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf); // err 'pcap_lookupdev undefined'
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device: %s\n", dev);
return(0);
}
Even know my pcap header defines pcap_lookupdev
:
...
char *pcap_lookupdev(char *);
...
I installed libpcap via:
sudo apt-get install libpcap0.8-dev
Whenever I try to use a function that is declared in the pcap header, gcc gives the error function is undefined
. Does anyone know what I am doing wrong?
Upvotes: 1
Views: 3942
Reputation: 3807
How to compile libpcap applications under Ubuntu:
sudo apt-get install libpcap0.8-dev
setup eclipse linker to handle libpcap:
Project -> properties -> build settings -> linker -> libraries -> add library
All you have to do is type in pcap.
To compile from the command line all you have to do is:
gcc -o {output} file.c -lpcap
Upvotes: 2