tcpdump mailing list archives
Re: pcap_loop
From: Eloy Paris <peloy () chapus net>
Date: Tue, 3 Jun 2008 09:57:35 -0400
On Tue, Jun 03, 2008 at 10:13:49AM +0200, m. kh wrote:
how to use a the last argument of pcap_loop ? in my program i use : u_char *user; user="the message "; pcap_loop(handle, -1, (pcap_handler) callback , user); but not succe ,help me give me example ?
Using the example you started: void mycallback(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes) { printf("mycallback() called. \"user\" pointer is '%s'\n", user); } void f(void) { u_char *user = "the message "; pcap_loop(handle, -1, mycallback, user); } The last argument to pcap_loop() is a pointer that will be passed to your callback function. The pointer points to any variable or structure of your choosing. It's just a standard way of passing data to callback functions. Here's another example: void mycallback(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes) { int *counter = (int *) user; printf("Packet #%d: %u bytes.\n", *counter++, h->caplen); } void f(void) { int pktcounter = 0; pcap_loop(handle, -1, mycallback, (u_char *) &pktcounter); } Cheers, Eloy Paris.- - This is the tcpdump-workers list. Visit https://cod.sandelman.ca/ to unsubscribe.
Current thread:
- pcap_loop m. kh (Jun 03)
- Re: pcap_loop Michael Krüger (Jun 03)
- Re: pcap_loop khaled (Jun 03)
- Re: pcap_loop Guy Harris (Jun 03)
- Re: pcap_loop khaled (Jun 03)
- Re: pcap_loop Eloy Paris (Jun 03)
- Re: pcap_loop Michael Krüger (Jun 03)