Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C (http://www.programmingforums.org/forum60.html)
-   -   Trying to make a simple packet sniffer (http://www.programmingforums.org/showthread.php?t=11396)

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.

niteice Sep 25th, 2006 10:12 PM

cc simpsnif.c -o simpsnif -l pcap

Intimidat0r Sep 25th, 2006 10:18 PM

Thank you, that worked perfectly.

Pizentios Sep 26th, 2006 10:25 AM

keep us informed of your progress (if you are going to continue development), cause i am interested in stuff like this :-)


All times are GMT -5. The time now is 1:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC