您的位置:首页 > 运维架构 > Linux

Red hat9.0 Linux下安装libpcap库

2010-06-29 13:48 387 查看
安装前的预备工作:

1.确定已安装了gcc(2.4.6 or higher)。可以输入命令gcc --version来查看当前gcc版本。

2.确定已安装了GNU M4(V1.4.12)。

3.确定已安装了flex(V2.5.4 )。可以输入命令flex --version来查看当前flex版本。

下载地址:http://sourceforge.net/projects/flex/

4.确定已安装修了bison(V2.4.0)。可以输入命令bison --version来查看当前bison版本。

下载地址:http://ftp.gnu.org/gnu/bison/

完成了上面的几个步骤后,下面以安装libpcap(V4.1.1)

执行下列三个安装命令:

./configure
make
make install

注意:如果你已运行过./configure,重新运行./configure前,先运行make distclean 将先前配置清除.

测试用例(参见http://www.tcpdump.org/pcap.htm):

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

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

这时运行后出,错误信息为./device: error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory

找了半天都不知道是什么原因,后来在libpcap-1.1.1的README文件中提到一句:

It sets the soname of the library to "libpcap.so.1"; this is what it
should be, *NOT* libpcap.so.1.x or libpcap.so.1.x.y or something such as
that.

接下来就是找到libpcap.so.1.1.1文件,将其改为libpcap.so.1后拷贝文件到/usr/lib目录下。

接下来运行就OK了。

初次学LINUX,弄了一下午才安装好了个libpcap.

在这里要感谢网上一篇文章:http://blog.csdn.net/zhangzhenhu/archive/2010/05/12/5584119.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: