在Ubuntu平台安装libpcap

通过官方提供的资料可以了解安装的基本环境:To compile the libpcap library, your Unix distribution must have a C compiler, and the lex and bison text parsers. For Open Source Unix distributions such as Linux and FreeBSD, the gcc, flex, and bison programs provide these functions. 安装Ubuntu操作系统后是没有安装C compiler、flex、bison

1.安装gcc编译器直接在终端执行sudo apt-get install gcc libc6-dev 安装gcc(需要系统光盘),要不然连helloworld这么简单的都编译不过,或者在编译tar.gz文件时提示“C compiler cannot create executable”的错误。

编写helloworld测试gcc编译器:#includeint main(){printf(“hello,world!\n”);return 0;}

第一次接触gcc编译器,发现不支持void main()这种main函数的。

2.编译GNU M4 (version 1.4)这个是编译flex必备的环境,否则会提示“GNU M4 1.4 is required”的错误

3.编译flex(version 2.5.33)没有flex,直接安装libpcap会提示“Your operating system’s lex is insufficient to compile libpcap”错误。

4.编译bison(version 2.3)在安装flex后直接安装libpcap会提示“don’t have both flex and bison;reverting to lex/yacc”错误,前面安装的是flex,就需要搭配bison

5.编译libpcap全面四步完成后,就可以使用下面三个指令安装libpcap环境:./configuremakemake install

简单的例子测试一下libpcap://device.c#include int main(int argc,char *argv[]){char *dev, errbuf[PCAP_ERRBUF_SIZE];dev=pcap_lookupdev(errbuf);if(dev==NULL){fprintf(stderr,”couldn’t find default device: %s\n”,errbuf);return(2);}printf(“Device: %s\n”,dev);return(0);}

编译指令:gcc -o device device.c -lpcap

备注:编译时要使用libpcap的参数-lpca,否则会提示“pcap_lookupdev 未定义的引用”的错误。

运行指令:./device

6.总结就这么简单的几个步骤,我花了一天的时间才弄出来的,跑到国外查阅了很多资料,国内几乎找不到这方面的资料,主要原因其一是使用Ubuntu的人很少,而 使用RedHat的直接安装就可以,本身系统不会缺少flex、bison;其二是我不熟悉在linux平台安装程序,不象windows平台点几下鼠标 就可以安装的,还有flex、bison很难才找到提供下载的地方,也是在国外。

备注:1)出现“无法创建一般文件 ‘/usr/local/bin/m4’:Permission denied”错误,权限问题,Ubuntu默认root用户不启用的,可以使用sudo指令解决这个问题。

2)Ubuntu不支持rpm安装文件,rpm是Red Hat操作系统的标准安装文件格式,,可以采用alien将rpm包转换为deb包。安装alien:sudo apt-get install alienalien使用:alien ****.rpm这样就生成Ubuntu支持的****.deb 安装deb:sudo dpkg -i ****.deb 或者右键菜单,安装deb

我想一个人旅行,可以不带相机,也不要带上手机,

在Ubuntu平台安装libpcap

相关文章:

你感兴趣的文章:

标签云: