「Linux」Ubuntu12.10的Libpcap1.3安装过程

由于课设的需要,以前的教程都比较久远了,今晚弄了一个,顺手写下教程……

1. 安装过程

scue@Link:~$ wget http://www.tcpdump.org/release/libpcap-1.3.0.tar.gz
scue@Link:~$ tar zxvf libpcap-1.3.0.tar.gz
scue@Link:~$ cd libpcap-1.3.0/
scue@Link:~/libpcap-1.3.0$ ./configure 
scue@Link:~/libpcap-1.3.0$ sudo make install

2. 现在已经安装好了,但运行需要调用它的程序时候还是不能调用到它的,需要ln下

# 先找到它的位置
scue@Link:~/libpcap-1.3.0$ whereis libpcap.so*
libpcap: /usr/local/lib/libpcap.a /usr/local/lib/libpcap.so
# 找到它之后,使用ln -s创建链接到/us/lib/目录下
scue@Link:~/libpcap-1.3.0$  sudo ln -s /usr/local/lib/libpcap.so /usr/lib/libpcap.so.1

3. 现在我们来编写一下小程序看看网络设备捕获的效果

 -- 开始编辑.c文件

scue@Link:~$ cd ~
scue@Link:~$ gedit testlibpcap.c

 -- 然后把以下代码复制进testlibpcap.c里边

#include<stdio.h>
#include<stdlib.h>
#include<pcap.h>
#include<errno.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
 
int main(int argc,char *argv[])
{
    char *dev;
    char *net;
    char *mask;
    int ret;
    char errbuf[PCAP_ERRBUF_SIZE];
    bpf_u_int32 netp;
    bpf_u_int32 maskp;
    struct in_addr addr;
    dev = pcap_lookupdev(errbuf);
    if(dev ==NULL)
    {
        printf("%s,这……啥也没有,退出!\n",errbuf);
        exit(1);
    }
    printf("设备名:%s\n",dev);
    return 0;
}

 -- 开始编译并执行程序

scue@Link:~$  gcc testlibpcap.c -lpcap -o testlibpcap.o
scue@Link:~$ ./testlibpcap.o 
no suitable device found,这……啥也没有,退出! 
scue@Link:~$
posted @ 2012-11-10 21:42  scue  阅读(796)  评论(0编辑  收藏  举报