Since yesterday i'm learning how to use pcap to parse a pcap file.
And since yesterday i'm getting an error :
Here is my simple code, trying to write the fd in pcap_t structure:
#include <pcap/pcap.h>
#include <sys/types.h>
#include <pcap-bpf.h>
#include <stdio.h>
int main() {
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *result;
if ((result = pcap_open_offline("test.pcap", errbuf)) == NULL) {
printf("%s\n", errbuf);
return -1;
}
printf("fd=%d\n", result->fd);
return 0;
}
and here is my error:
gcc -Wextra -Wall -Werror -I./includes -c -o main.o main.c
main.c: In function ‘main’:
main.c:14:27: error: dereferencing pointer to incomplete type
printf("fd=%d\n", result->fd);
^
make: *** [main.o] Error 1
I saw this post: Pcap Incomplete Type
Where the guy is having almost the same problem as I have, but still, I can't find a solution, I included what pcap_open_offline needs, I also included pcap-bpf.h because I saw that pcap_t is using bpf_program.
The first answer is saying "The error is because the compiler cannot see the definition of the structure" but in my case the structure is pcap_t and is typedef in pcap.h, which i included.
I just don't get how to include correclty with pcap.
Also, I'm on Ubuntu, and i cannot find all my .h file about pcap. When I look on google, I only find .h from apple and windows, so I assume that i'm using the same as the apple one, but i'm not sure about that !
I'm reading this documentation to see structures fields : http://www.opensource.apple.com/source/libpcap/libpcap-18/libpcap/pcap.h http://www.opensource.apple.com/source/libpcap/libpcap-9/libpcap/pcap-int.h
But again, the apple.com is scaring me, i'm not sure that I should rely on that. For instance, pcap-int.h doesn't seem to exist in my system.
Thank you !