pflz
pflz

Reputation: 1931

Problem with libpcap functions?

#include <stdio.h>
#include <pcap.h>

int main(int argc,char* argv[])
{
    char* dev=argv[1];
    char errbuf[PCAP_ERRBUF_SIZE];
    dev=pcap_lookupdev(errbuf);
    if(dev==NULL) {
        fprintf(stderr,"Couldn't find default device: %s\n",errbuf);
        return 0;   
    }
    printf("Device: %s\n",dev); 

    return 0;
}

On compiling:

$ cc pcap1.c 
/tmp/ccZLrRlF.o: In function `main':
pcap1.c:(.text+0x37): undefined reference to `pcap_lookupdev'
collect2: ld returned 1 exit status

This is happening with other functions of the libpcap library as well. Can you please explain the problem to me and a way to correct it? Thanks in advance...

Upvotes: 0

Views: 1772

Answers (2)

Rafik Harzi
Rafik Harzi

Reputation: 33

I had this Error and I have just solved it.

I am working on Debian 7 so here is what I have done:

1 - insaled the libpcap you find how in this link install libpcap

!!!!!! installed flex (sudo apt-get install bison) because I had some problems while

installing libpcap

2 - gcc test.c -lpcap that returned this error " collect2: ld returned 1 exit status "

3 - installed libpcap-devel (sudo apt-get install libpcap-dev)

and it went through the next time

I hope this is going to be of help to you.

good luck

Upvotes: 0

Brian Roach
Brian Roach

Reputation: 76888

Because you're not linking the pcap library when you're compiling, therefore none of the functions you're trying to use are available.

cc pcap1.c -lpcap

If you haven't installed libpcap somewhere in the standard library path, you would need to add that as well

cc pcap1.c -lpcap -L/directory/libpcap/is/in

Upvotes: 3

Related Questions