首页 > 代码库 > CentOS安装libpcap
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
下载地址:http://www.tcpdump.org/
下载版本:wget -c http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz
解压软件包:tar zxf libpcap-1.0.0.tar.gz
进入解压后的目录,输入命令行:
命令如下:
./configure
make
make install
5.简单的例子测试一下libpcap:
//device.c
#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
备注:编译时要使用libpcap的参数-lpcap,否则会提示“pcap_lookupdev 未定义的引用”的错误;
运行指令:./device
转载:http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz
http://blog.sina.com.cn/s/blog_6f289b0e01014jst.html
运行遇到错误解决办法:
error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or
//-----------------------------------------------------------
//AUTHOR:lanyang123456
//DATE:2011-11-10
//-----------------------------------------------------------
Linux系统下,运行sniff程序需要libpcap库。
首先下载安装该库,下载地址: http://www.tcpdump.org/
点击DOWNLOADS
下载后
(1)解压
(2)进入解压后文件目录, ./configure
(3)make install
默认安装目录/usr/local/lib
编译sniff程序通过,运行sniff程序时,出现如下错误:
./sn: error while loadingshared libraries: libpcap.so.1: cannot open shared object file: No such file ordirectory
由于libpcap已经安装,所以是程序无法找到库所在的位置的原因。
解决办法:
将libpcap.so.1所在目录添加到文件/etc/ld.so.conf中,
打开ld.so.conf文件,然后添加一行/usr/local/lib:
includeld.so.conf.d/*.conf //原来的内容
/usr/local/lib
然后保存,再终端下执行 ldconfig。
再运行sniff程序,OK。
有时用tar解压文件.错误如下:
gzip: stdin: unexpectedend of file tar: Unexpected EOF in archive tar: Unexpected EOF in archive tar:Error is not recoverable: exiting now
原因:
文件被破坏,重新下载。
转载:http://blog.csdn.net/lanyang123456/article/details/6956093