說明:直接用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