开发者

Problem with libpcap functions?

开发者 https://www.devze.com 2023-02-25 13:55 出处:网络
#include <stdio.h> #include <pcap.h> int main(int argc,char* argv[]) { char* dev=argv[1]; char errbuf[PCAP_ERRBUF_SIZE];
#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,"Cou开发者_StackOverflow社区ldn'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...


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消