Ubuntu下Libnids的安装详解



在安装libpcap之前需要安装flex和bison.flex和bison在进行手动安装时安装的似乎不太成功。这是我小小的疑问?为什么在使用tar安装之后还是不行呢?
1)我安装的目录的原因。我之前在/home/song/   下运行 sudo apt-get flex
sudo apt-get install bison结果是couldnot find。。。
sudo apt-get install libpcap-dev也是不行的
之后跳到 /home/songzhichao/Desktop运行上述命令才得以解决。
注意在这之前我已经通过tar -zvxf   .tar.gz手动安装过了flex  bison  
在这其间也安装了yacc


2)之前是网络问题?




http://www.geeksww.com/tutorials/operating_systems/linux/installation/installing_flex_fast_lexical_analyzer_ubuntu_linux.php
这是flex的手动安装网站的内容:
wget http://prdownloads.sourceforge.net/flex/flex-2.5.33.tar.gz?download
Extracting files from the downloaded package:
tar -xvzf flex-2.5.33.tar.gz
Now, enter the directory where the package is extracted.
cd flex-2.5.33
Configuring flex before installation:
If you haven't installed m4 yet then please do so. Click here to read about the installation instructions for m4. Run the commands below to include m4 in your PATH variable.


PATH=$PATH:/usr/local/m4/bin/
NOTE: Replace '/usr/local/m4/bin' with the location of m4 binary. Now, configure the source code before installation.


./configure --prefix=/usr/local/flex
Replace "/usr/local/flex" above with the directory path where you want to copy the files and folders. Note: check for any error message.


Compiling flex:
make


最后 sudo make install    这种手动的方式感觉不靠谱。






configure:error :Your operating system's lex is insufficient ....
就是由于flex没有安装造成的






可能出现:make[4]:Nothing to be done for 'install-data-amm'等,这不是错误信息


一、 安装过程参照以下步骤: 
1、打开网址:www.tcpdump.org/ 下载 libpcap-1.0.0.tar.gz (512.0KB) 软件包,通过命令 tar zxvf libpcap-1.0.0.tar.gz 解压文件,并将其放入自定义的安装目录。
2、打开网址:flex.sourceforge.net/ 下载 flex-2.5.35.tar.gz (1.40MB) 软件包,通过 tar zxvf flex-2.5.35.tar.gz 解压文件,并将其放入上述自定义的安装目录中。
   注:如果没有编译安装此文件,在编译安装libpcap时,就会出现 “configure: error: Your operating system's lex is insufficient to compile libpcap.”的错误提示。
3、打开网址:ftp.gnu.org/gnu/bison/ 下载 bison-2.4.1.tar.gz (1.9MB) 软件包,通过 tar zxvf bison-2.4.1.tar.gz 解压文件,并将其放入上述自定义的安装目录中。
  注:如果没有编译安装此文件,在编译安装libpcap时,就会出现 "configure: WARNING: don't have both flex and bison; reverting to lex/yacc checking for capable lex... 


insufficient" 的错误提示。
4、打开网址:ftp.gnu.org/gnu/m4/ 下载 m4-1.4.13.tar.gz (1.2MB)软件包,通过 tar zxvf m4-1.4.13.tar.gz 解压文件,并将其放入上述自定义的安装目录中。
  注:如果没有编译安装此文件,在编译安装bison-2.4.1时,就会出现 “configure: error: GNU M4 1.4 is required”的错误提示。
5、而后依次进入目录m4-1.4.13,bison-2.4.1,flex-2.5.35,libpcap-1.0.0 并执行以下命令:
  (sudo) ./configure
  (sudo) make
  (sudo) make install
 
二、简单的抓包程序,程序来源于http://recursos.aldabaknocking.com/libpcapHakin9LuisMartinGarcia.pdf,这个pdf讲的是如何使用libpcap来做sniffer。
[cpp] view plaincopy 
#include <string.h>  
#include <stdlib.h>  
#include <pcap.h>  
  
#define MAXBYTE2CAPTURE 2048  
  
void processPacket(u_char *arg, const struct pcap_pkthdr *pkthdr, const u_char *packet) {  
    int i = 0, *counter = (int *)arg;  
  
    printf("Packet Count: %d\n", ++(*counter));  
    printf("Received Packet Size: %d\n", pkthdr->len);  
    printf("Payload:\n");  
    for (i = 0; i < pkthdr->len; i++) {  
        if (isprint(packet[i]))  
            printf("%c ", packet[i]);  
        else   
            printf(". ");  
  
        if ((i % 16 == 0 && i != 0) || i == pkthdr->len-1)  
            printf("\n");  
  
    }  
    return;  
}  
  
int main() {  
  
    int i = 0, count = 0;  
    pcap_t *descr = NULL;  
    char errbuf[PCAP_ERRBUF_SIZE], *device = NULL;  
    memset(errbuf, 0, PCAP_ERRBUF_SIZE);  
  
    /* Get the name of the first device suitable for capture */  
    device = pcap_lookupdev(errbuf);  
  
    printf("Opening device %s\n", device);  
  
    /* Open device in promiscuous mode */  
    descr = pcap_open_live(device, MAXBYTE2CAPTURE, 1, 512, errbuf);  
  
    /* Loop forever & call processPacket() for every received packet */  
    pcap_loop(descr, -1, processPacket, (u_char *)&count);  
  
    return 0;  
}  


这个程序只讲将抓到的包直接打印出来,并没有根据协议解析为方便为我们看的形式,这是下来需要做的工作。
 
三、运行上面这个程序时出现的问题
用命令:gcc simplesniffer.c -g -Wall -lpcap -o simplesniffer 编译链接生成simplesniffer后,运行时出现了这个错误:
./simplesniffer: error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory
跑到/usr/lib/目录下一看,发现只有libcap.so.1.0.0文件,使用命令ln -s libpcap.so.1.0.0 libpcap.so.1创建一个符号链接文件,解决该错误
sudo apt-get install libnet-dev


sudo apt-get install libnids-dev








最后进行测试:
随便写一个程序,只要是
gcc -o test 1.c -lpcap -lnet -lnids  编译是没有报错那么,说明已经全部安装成功了


type libnids是不好使的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值