| Intimidat0r |
Sep 25th, 2006 9:55 PM |
Trying to make a simple packet sniffer
So this is my first time out with libpcap. And sadly this is not compiling:
:
#include <stdio.h>
#include <pcap.h>
#define NUM_PACKETS 10
void pcap_handler_cb(u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data)
{
printf("Got packet: %d bytes captured:", pkt_header->caplen);
if (pkt_header->caplen > 2)
printf("%02X %02X ... \n", pkt_data[0], pkt_data[1]);
else
printf("...\n");
}
int main(int argc, char *argv[])
{
char errbuf[PCAP_ERRBUF_SIZE];
char *default_device;
pcap_t* ph;
default_device = pcap_lookupdev(errbuf);
if (!default_device)
{
fprintf(stderr, "%s\n", errbuf);
exit(1);
}
printf("Opening %s\n", default_device);
ph = pcap_open_live(default_device, BUFSIZ, 1, 0, errbuf);
printf("Capturing on %s\n", default_device);
pcap_loop(ph, NUM_PACKETS, pcap_handler_cb, NULL);
printf("Done.\n");
return 0;
}
And when I try to compile it I get this:
Quote:
Originally Posted by my terminal
intimidat0r@gibson:~$ cc simpsniff.c
simpsniff.c: In function ‘main’:
simpsniff.c:24: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/ccCQpoev.o: In function `main':simpsniff.c:(.text+0x89): undefined reference to `pcap_lookupdev'
:simpsniff.c:(.text+0xfe): undefined reference to `pcap_open_live'
:simpsniff.c:(.text+0x137): undefined reference to `pcap_loop'
collect2: ld returned 1 exit status
intimidat0r@gibson:~$
|
I used to get a lot more errors until I installed libpcap0.8 and libpcap0.8-dev. :)
Now I only get these. Any idea how to fix 'er?
Thanks.
|