Joojoo
Joojoo

Reputation: 79

libpcap: Delay between receiving frames and call of callback-function

i am experiencing the following situation: I open with pcap_open_live() one of my network-interfaces. Then i am compiling a filter for pcap for only capturing a specified ethernet-type (ether proto 0x1234). Now i am starting the pcap_loop(). The only thing, that the callback-function executes, is to send a frame via pcap_inject(). (The frame is hard-coded as a global char array).

When i compare now the timestamps of the received and the sent frame (e.g. on wireshark on a third non-involved computer) the delay is around 3 milliseconds (minumum 1 millisecond, but also up to 10 milliseconds). So pcap needs in average around 3 milliseconds to proceed with the received frame and calling the callback-function for sending the new frame. I want/have to decrease that delay.

Following things i already tried:

But i never decreased the delay under the average of 3 milliseconds.

For my planned application it is necessary to react to incoming packets in a time unter 100 microseconds. Is this even generally doable with libpcap?! Or are there any other suggestions for realizing such a application?

Thanks for all your replies, i hope anyone can help me!

Notes: I am deploying under Linux/Ubuntu in C/C++.

Upvotes: 4

Views: 2568

Answers (1)

user862787
user862787

Reputation:

For my planned application it is necessary to react to incoming packets in a time under 100 microseconds.

Then the buffering that many of the capture mechanisms atop which libpcap runs (BPF except on AIX, TPACKET_V3 on Linux with newer libpcap and kernel, DLPI on Solaris 10 and earlier, etc.) provide in order to reduce per-packet overhead would get in your way.

If the libpcap on your system has the pcap_set_immediate_mode() function, then:

  • use pcap_create() and pcap_activate(), rather than pcap_open_live(), to open the capture device;
  • call pcap_set_immediate_mode() between the pcap_create() and pcap_activate() calls.

In "immediate mode", packets should be delivered to the application by the capture mechanism as soon as the capture mechanism receives them.

Upvotes: 6

Related Questions