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
解決方法: