您的位置:首页 > 其它

在Ubuntu安装测试libpcap(Install the libpcap in Ubuntu 11.04)

2012-12-11 23:45 656 查看
1.Download the tar of libpcap

in site: http://www.tcpdump.org/
My File is libpcap-1.2.1.tar.gz.

tar -zxvf libpcap-1.3.0.tar.gz


2.Now, We get the folder libpcap-1.3.0

cd libpcap-1.3.0


3.we need install flex

sudo apt-get install flex

if don't do this step will:

4. Configure

./configure


5.Install byacc

sudo apt-get install byacc

if not do this step will :

yacc -d grammar.y

make: yacc: Command not found

make: *** [grammar.c] Error 127

6. make

7. sudo make install

8. Test
.

vim 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 errbuf[PCAP_ERRBUF_SIZE];
    dev = pcap_lookupdev(errbuf);
    if(dev ==NULL)
    {
        printf("%s\n",errbuf);
        exit(1);
    }
    printf("设备名:%s\n",dev);
    return 0;
}
gcc  testlibpcap.c -o testlibpcap -lpcap -Wall


9 ln a link for libpcap

sudo ln -s /usr/lib/libpcap.1.X.X /usr/lib/libpcap.1

if don't do this step, 10th step will:

error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory

10 Run it!

sudo ./testlibpcap
If it show:

设备名:XXX

Congratulation for your success !
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐