说明:直接用yum安装的libpcap会在libnids安装的时候检查有问题,所以需要下载安装包来安装!
1. 安装libpcap
① 下载软件包libpcap-1.0.0.tar.gz
下载地址:http://www.tcpdump.org/release/libpcap-1.0.0.tar.gz
② 解压软件包:tar zxf libpcap-1.0.0.tar.gz
③ 进入解压后的目录,输入命令行:
./configure
报错:configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
解决:安装gcc: sudo yum install gcc
继续:./configure
报错:configure: error: Your operating system's lex is insufficient to compile
libpcap. flex is a lex replacement that has many advantages, including
being able to compile libpcap. For more information, see
http://www.gnu.org/software/flex/flex.html .
解决:安装flex:sudo yum install flex
继续:./configure
make
报错:make: yacc:命令未找到
make: *** [grammar.c] 错误 127
解决: CentOS下是用flex和bison来分别代替lex和yacc的,安装bison:sudo yum install bison
继续:./configure
make
sudo make install
如果没有事先安装flex和bison,而是像我描述的这样遇到问题才装,请先清理及卸载。
输入命令行:make clean
make uninstall
再重新来过,否则会遇到libnids中的安装错误。
2. 安装libnids
① 下载软件包libnids-1.24.tar.gz
下载地址:
https://sourceforge.net/projects/libnids/files/libnids/1.24/libnids-1.24.tar.gz/download
② 解压软件包:tar zxf libnids-1.24.tar.gz
③ 进入解压后的目录,输入命令行:
./configure --disable-libglib --disable-libnet
make
sudo make install
④ 进入libnids-1.24/samples,运行:make,将printall.c编译为printall,表示之后本机中所有与外界的TCP连接的数据包内容都会被打印在终端上。
报错:grammar.c:(.text+0x44e): undefined reference to `pcap_lex'
collect2: ld 返回 1
make: *** [overflows] 错误 1
解决:与libpcap的安装有关系,所以完全卸载libnids和libpcap,重新安装。
继续:make
报错:“警告:隐式声明与内建函数‘exit’不兼容”之类的
解决:请按如下说明在相应的C文件中添加头文件
警告: 隐式声明与内建函数‘exit’不兼容 添加 #include
与str相关的警告:隐式声明与内建函数‘strlen’不兼容 添加 #include
继续:make