I'm not entirely sure I understand what you're asking, but I think I might to be able to cover it.
Firstly, a dispatch handler is just a function matching this signature:
void packethandler( u_char *args, const struct pcap_pkthdr* pkthdr,
const u_char* packet )
The arguments there are, from right to left, the packet libpcap has extracted from the network interface, the pcap format packet header and the arguments to the packet handler.
I imagine if anything, the first argument is possibly causing you a problem. If you need to pass multiple arguments, you can do this - it's just not quite what you'd expect. Rather than use va_args
, if you want to pass multiple arguments you can simply define a struct. Assuming typedef struct { ... } myparams;
you can then pass:
(u_char*) myparamstruct
as a parameter and inside your handler do:
myparams* params = (myparams*) args;
This works because you're passing pointers, not data. The type for pointers simply describes the underlying, dereferenced location type (a way of interpreting the data), not the actual value of the pointer - as all pointers are equally wide (for the purposes of this, anyway).
So that might cover getting those arguments in. As for the remaining two arguments, as I said before, these are what libpcap has captured from the specified network interface. Essentially, every time a packet is successfully extracted your handler is called by means of a function pointer, with the packet details encoded in those arguments and passing through the user-supplied argument pointer.