libpcap 函数有问题吗?

发布于 2024-11-01 03:44:18 字数 614 浏览 0 评论 0原文

#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;
}

编译时:

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

libpcap 库的其他函数也会发生这种情况。您能给我解释一下这个问题以及纠正它的方法吗?提前致谢...

#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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小女人ら 2024-11-08 03:44:18

由于您在编译时没有链接 pcap 库,因此您尝试使用的函数都不可用。

cc pcap1.c -lpcap

如果您尚未在标准库路径中的某个位置安装 libpcap,则还需要添加它

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

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
冷了相思 2024-11-08 03:44:18

我遇到了这个错误,我刚刚解决了它。

我正在 Debian 7 上工作,所以这就是我所做的:

1 - 安装 libpcap,您可以在此链接中找到如何操作 安装 libpcap

!!!!!! 时遇到了一些问题

安装了flex(sudo apt-get install bison),因为我在安装libpcap

2 - gcc test.c -lpcap返回了这个错误“collect2:ld返回1退出状态”

3 - 安装了libpcap-devel(sudo apt-get)安装 libpcap-dev)

,下次就可以了,

希望这对您有帮助。

祝你好运

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文