tcpdump mailing list archives

Re: What is meant by the callback function


From: "Varuna De Silva" <varunax () gmail com>
Date: Mon, 24 Sep 2007 09:49:24 +0530

On 9/23/07, Guy Harris <guy () alum mit edu> wrote:

Varuna De Silva wrote:

1. what is really meant by the callback routine, what does it do? How
should I write this function?where should this be written. please be
kind
to guide me to starting place. my idea is that it is the higher layer sw
which makes use of libpcap.

Yes, the callback function is in the higher-layer software that uses
libpcap/WinPcap.  tcpdump, for example, has two callback functions that
write raw packet data to a capture file and one callback function that
dissects the packet and prints the dissection; other programs such as
Wireshark/TShark, snort, etc. have their own callback functions.

The callback function processes the packet data handed to it as the third
argument, and the packet time stamp and length information in the
structure passed to it as the second argument.

If you're modifying libpcap to support a new type of capture, you don't
write the callback function,


I am doing this for my device to be supported by wireshark. As I understand
I dont need to write the callback function??? Please correct me if I am
wrong.

you write code in the read_op routine to call
the callback function;

Yes, I did so as following, ( I am guilty, of copying it directly from
pcap-septel.c)

int muwis_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
callback(user, &pcap_header, dp);
:
:
}

As I understand this need to be called for each packet captured, and
this dp as you say the pointer to the packet data, have to point
to the first byte of the packet. Kindly correct me if wrong.


a pointer to the callback function is passed to the
read_op routine.


This is the "user" in the above code. Now my question is what will
be this "user" function in my case. That is when I call xxxx_read()
pointer to what function will I have to pass to it as " *user "

Thanks,

Varuna
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: