Since I would like to do some tests with libpcap and a small C program, I am trying to pass the structure from main () to got_packet (). After reading the libpcap tutorial, I found the following:
The prototype for pcap_loop () is below:
int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
The last argument is useful in some applications, but many times just set to NULL. Suppose we have arguments that we want to send to our callback functions, in addition to the arguments that pcap_loop () sends. This is where we do it. Obviously, you must typecast to the u_char pointer to ensure the results do it there correctly; as we will see later, pcap uses some very interesting means of transmitting information in the form of a u_char pointer.
Thus, in accordance with this, you can send the structure to got_packet () using argument number 4 pcap_loop (). But after trying, I get an error message.
Here is my (listened) code:
int main(int argc, char **argv) { typedef struct _configuration Configuration; struct _configuration { int id; char title[255]; }; Configuration conf[2] = { {0, "foo"}, {1, "bar"}}; pcap_loop(handle, num_packets, got_packet, &conf); } void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { printf("test: %d\n", *args[0]->id); }
I get this error after some tests:
gcc -c got_packet.c -o got_packet.o got_packet.c: In function 'got_packet': got_packet.c:25: error: invalid type argument of '->'
You see how I can edit this code to pass conf (with an array of configuration structure) to get_packet ()?
Thanks so much for any help.
Hi