取消引用 pcap_t 结构的不完整类型的指针 [英] dereferencing pointer to incomplete type for pcap_t structure
问题描述
我正在用 C 编写代码并使用 libpcap 库.我想查看 pcap_t 结构的字段,但总是有错误:
I am coding in C and using libpcap library. I want to see the fields of a pcap_t structure, but always have the error :
error: dereferencing pointer to incomplete type
最小代码如下:
#include <stdio.h>
#include <pcap/pcap.h>
int main()
{
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *handle;
handle=pcap_open_live("eth0", 65535, 1, 1, errbuf);
printf("Handle%d\n", handle->fd);
pcap_close(handle);
}
编译完成:
gcc test.c -lpcap
根据http://www.opensource.apple.com/source/libpcap/libpcap-9/libpcap/pcap-int.h,pcap_t 结构确实有这个字段.libpcap通常是包含的,所以我完全不明白.
According to http://www.opensource.apple.com/source/libpcap/libpcap-9/libpcap/pcap-int.h, the pcap_t structure does have this field. The libpcap is normally included, so I do not understand at all.
谢谢!
结论: Olaf 似乎是对的:我有这个错误,因为我无法访问 pcap_t 结构.正如 Antti Haapala 所说,pcap_t 结构不是在 pcap/pcap.h 中定义的,而是在另一个文件中.
Conclusion: Olaf seems to be right : I have this error because I am not able to access the pcap_t structure. As Antti Haapala said, pcap_t struct is not defined in pcap/pcap.h but in another file.
我确实设法做我想做的事情,即使无法访问结构的字段.
I did manage to do what I wanted to do anyway, even without access to the fields of the structure.
问题已解决,感谢您的帮助!
Problem solved, thanks for your help !
推荐答案
pcap-int.h
代表 内部.但是,您没有在代码中包含此标头.
the -int in pcap-int.h
stands for internal. However you're not including this header in your code.
注意pcap.h
本身不包含这个头文件,也不包含 struct pcap
的完整声明;而只是在 typedef 中使用前向声明:
Notice that pcap.h
itself does not include this header, neither does it contain a full declaration of struct pcap
; instead just using the forward declaration in typedef:
typedef struct pcap pcap_t;
试试吧:
#include <stdio.h>
#include <pcap/pcap-int.h>
#include <pcap/pcap.h>
int main()
{
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *handle;
handle=pcap_open_live("eth0", 65535, 1, 1, errbuf);
printf("Handle%d\n", handle->fd);
pcap_close(handle);
}
<小时>
唉,这个内部头文件似乎没有安装在 Linux 和 Mac 上.对于一个非常丑陋的黑客,您可以尝试从链接中复制 pcap-int.h
.
这篇关于取消引用 pcap_t 结构的不完整类型的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!