fedora10安装libpcap

来源:互联网 发布:windows过期如何激活 编辑:程序博客网 时间:2024/04/26 23:17

       系统默认安装了libpcap0.9.8版本,但是目录/usr/include目录下面没有pcap文件夹,所以下载最新版的libpcap源文件,解压并将pcap文件拷贝到/usr/include文件夹下。验证代码如下:

#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pcap/pcap.h>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);}
     

存为test.c。用命令:gcc test.c -o test -lpcap 编译。运行此类程序时需要以root的身份运行,因为系统不允许非root用户进行一些网络操作。所以,运行命令为:(sudo)./test ..

运行结果:Device: eth1

验证代码来自:http://blog.csdn.net/fengyun1989/article/details/7384899


原创粉丝点击