1.安装GCC:
yum -y install gcc-c++html
2.安装flex:
yum -y install flex
没有flex,直接安装libpcap会提示"Your operating system's lex is insufficient to compile libpcap"错误;mysql
3.安装bison
yum -y install bison
前面安装的是flex,就须要搭配bison,如不会提示"don't have both flex and bison;reverting to lex/yacc"错误;linux
4.安装 libpcap
下载地址:http://www.tcpdump.org/
下载版本:wget -c http://www.tcpdump.org/release/libpcap-1.5.3.tar.gzc++
解压软件包:tar zxf libpcap-1.0.0.tar.gzsql
进入解压后的目录,输入命令行:
命令以下:
./configure
make
make installvim
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);
}tcp
编译指令:gcc -o device device.c -lpcap
备注:编译时要使用libpcap的参数-lpcap,不然会提示“pcap_lookupdev 未定义的引用”的错误;
运行指令:./device测试
转载:http://www.tcpdump.org/release/libpcap-1.5.3.tar.gzflex
http://blog.sina.com.cn/s/blog_6f289b0e01014jst.htmlspa
运行遇到错误解决办法:
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
解决方法: