当前位置:编程学习 > C/C++ >>

使用libpcap抓包编译错误

同样的程序从我fedora14上编译没问题,放到Fedora12上出现一大堆的错误,如下
[cpp]  
[root@root sias_catch]# make  
gcc -o jack_ip -g jack.c show_flow.c save_del.c -lpcap -lpthread  
In file included from jack.c:1:  
<span style="color:#ff0000;">jack.h:9:17: error: pcap.h: No such file or directory</span>  
In file included from jack.c:1:  
jack.h:81: warning: ‘struct pcap_pkthdr’ declared inside parameter list  
jack.h:81: warning: its scope is only this definition or declaration, which is probably not what you want  
jack.c:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token  
jack.c:32: warning: ‘struct pcap_pkthdr’ declared inside parameter list  
jack.c:32: error: conflicting types for ‘mycallback’  
jack.h:81: note: previous declaration of ‘mycallback’ was here  
jack.c: In function ‘mycallback’:  
jack.c:62: error: dereferencing pointer to incomplete type  
jack.c:63: error: dereferencing pointer to incomplete type  
jack.c:64: error: dereferencing pointer to incomplete type  
jack.c:135: error: dereferencing pointer to incomplete type  
jack.c:135: error: dereferencing pointer to incomplete type  
jack.c:159: error: dereferencing pointer to incomplete type  
jack.c:160: error: dereferencing pointer to incomplete type  
jack.c: In function ‘handler’:  
<span style="color:#ff0000;">jack.c:400: error: ‘pt’ undeclared (first use in this function)</span>  
jack.c:400: error: (Each undeclared identifier is reported only once  
jack.c:400: error: for each function it appears in.)  
jack.c: In function ‘main’:  
<span style="color:#ff0000;">jack.c:647: error: ‘PCAP_ERRBUF_SIZE’ undeclared (first use in this function)  
jack.c:648: error: ‘bpf_u_int32’ undeclared (first use in this function)</span>  
jack.c:648: error: expected ‘;’ before ‘mask’  
jack.c:649: error: expected ‘;’ before ‘subnet’  
jack.c:656: error: ‘pcap_if_t’ undeclared (first use in this function)  
jack.c:656: error: ‘alldevs’ undeclared (first use in this function)  
jack.c:657: error: ‘d’ undeclared (first use in this function)  
jack.c:658: error: ‘pcap_addr_t’ undeclared (first use in this function)  
jack.c:658: error: ‘a’ undeclared (first use in this function)  
jack.c:710: error: ‘subnet’ undeclared (first use in this function)  
jack.c:710: error: ‘mask’ undeclared (first use in this function)  
jack.c:740: error: ‘pt’ undeclared (first use in this function)  
In file included from save_del.c:3:  
<span style="color:#ff0000;">jack.h:9:17: error: pcap.h: No such file or directory</span>  
In file included from save_del.c:3:  
jack.h:81: warning: ‘struct pcap_pkthdr’ declared inside parameter list  
jack.h:81: warning: its scope is only this definition or declaration, which is probably not what you want  
make: *** [default] Error 1  
[root@root sias_catch]#  
从上面的错误可以看出来是头文件没包含进去的原因,但是用命令安装libpcap确实安装了啊!
[cpp]  
[root@root sias_catch]# yum install libpcap  
Loaded plugins: refresh-packagekit  
updates/metalink                                                                                                      | 4.0 kB     00:00       
Setting up Install Process  
Package 14:libpcap-1.0.0-4.20090922gite154e2.fc12.i686 already installed and latest version  
Nothing to do  
[root@root sias_catch]#   
 
然后就想到可能还有其他的没有安装!libpcap-devel
[cpp]  
[root@root sias_catch]# yum install libpcap-devel  
 
安装上,再编译下,成功了!
[cpp] 
[root@root sias_catch]# make  
gcc -o jack_ip -g jack.c show_flow.c save_del.c -lpcap -lpthread  
[root@root sias_catch]#   
 
 
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,