失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > libpcap linux安装 CentOS安装libpcap

libpcap linux安装 CentOS安装libpcap

时间:2022-11-12 08:58:45

相关推荐

libpcap linux安装 CentOS安装libpcap

1.安装GCC:

yum -y install gcc-c++

2.安装flex:

yum -y install flex

没有flex,直接安装libpcap会提示"Your operating system's lex is insufficient to compile libpcap"错误;

3.安装bison

yum -y install bison

前面安装的是flex,就需要搭配bison,如不会提示"don't have both flex and bison;reverting to lex/yacc"错误;

4.安装 libpcap

下载地址:/

下载版本:libpcap-1.2.1.tar.gz

命令如下:

./configure

make

make install

5.简单的例子测试一下libpcap:

//device.c

#include

#include

int main(int argc,char *argv[]){

char *dev, errbuf[PCAP_ERRBUF_SIZE];

dev=pcap_lookupdev(errbuf);

if(dev==NULL){

fprintf(stderr,"couldn't find default device: %s\n",errbuf);

return(2);

}

printf("Device: %s\n",dev);

return(0);

}

编译指令:gcc -o device device.c -lpcap 备注:编译时要使用libpcap的参数-lpcap,否则会提示“pcap_lookupdev 未定义的引用”的错误; 运行指令:./device

如果觉得《libpcap linux安装 CentOS安装libpcap》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。