在c ++中使用pcap_findalldevs_ex函数时出错

时间:2015-04-23 11:59:07

标签: sockets pcap

在此程序下方检索适配器列表并将其打印在屏幕上:

 #include <stdio.h>
 #include <pcap.h>  

 int main()  
 {  
     pcap_if_t *alldevs;  
     pcap_if_t *d;  
     int i=0;  
     char errbuf[PCAP_ERRBUF_SIZE];  

     if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)  
     {  
         fprintf(stderr,"Error in pcap_findalldevs_ex: %s/n", errbuf);  
         exit(1);  
     }  


     for(d= alldevs; d != NULL; d= d->next)  
     {  
         printf("%d. %s", ++i, d->name);  
         if (d->description)  
             printf(" (%s)/n", d->description);  
         else  
             printf(" (No description available)/n");  
     }  

     if (i == 0)  
     {  
         printf("/nNo interfaces found! Make sure WinPcap is installed./n");  
         return 0;  
     }  

     pcap_freealldevs(alldevs);  
 }

这是编译但是给出错误: enter image description here

1 个答案:

答案 0 :(得分:0)

每个人都有这些错误,在使用pcap.h时,请按照以下方式链接并下载pcap,安装后: http://www.winpcap.org/install/default.htm