由于缺少 pcap 定义而无法制作 ethping 程序

Unable to make ethping program because of missing pcap definitions

我似乎在构建 ethping 可执行文件时遇到了问题。它找不到 pcap.h.

中定义的任何函数

起初我以为找不到 pcap.h,但我检查了 $PATH/usr/include 在那里(pcap.h 有一个存根然后包括 pcap/pcap.h,但看起来也不错)。

我什至尝试了 -I /usr/include-I /usr/include/pcap,但仍然没有成功。

我已经搜索了大量的论坛帖子,但找不到解决方案。所以这就是我来这里的原因。有什么想法吗?

root:src# gcc -Wall -Werror -ggdb -g -O2 -lpcap -o ethping ethping.o ieee8021ag.o dot1ag_eth.o 
ethping.o: In function `timeout_handler':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:65: undefined reference to `pcap_breakloop'
ethping.o: In function `main':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:183: undefined reference to `pcap_open_live'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:202: undefined reference to `pcap_compile'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:203: undefined reference to `pcap_setfilter'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:254: undefined reference to `pcap_next_ex'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:257: undefined reference to `pcap_perror'
collect2: error: ld returned 1 exit status

同样:

root:src# gcc -Wall -Werror -ggdb -g -O2 -lpcap -I /usr/include/pcap -o ethping ethping.o ieee8021ag.o dot1ag_eth.o 
ethping.o: In function `timeout_handler':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:65: undefined reference to `pcap_breakloop'
ethping.o: In function `main':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:183: undefined reference to `pcap_open_live'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:202: undefined reference to `pcap_compile'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:203: undefined reference to `pcap_setfilter'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:254: undefined reference to `pcap_next_ex'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:257: undefined reference to `pcap_perror'
collect2: error: ld returned 1 exit status
root:src# 

要么您正在调用链接器而没有包含 libpcap 库的参数,要么这些库未安装。请参阅 http://www.tcpdump.org/ 以获取库。或者,如果您使用的是受良好支持的发行版,请使用适用的安装命令:

sudo apt-get install libpcap-dev

sudo yum install libpcap-dev

更改编译行修复了它。将 -lpcap 放在最右边可以按照建议进行。

gcc -Wall -Werror -ggdb -g -O2  -o ethping ethping.o ieee8021ag.o dot1ag_eth.o -lpcap