Re: [tcpdump-workers] Pcap delivers packets every 200ms

2023-02-02 Thread Guy Harris via tcpdump-workers
--- Begin Message ---
On Feb 2, 2023, at 7:42 AM, Paschal Chukwuebuk Amusuo via tcpdump-workers 
 wrote:

> Please, is there any way to force pcap to deliver packets once it receives 
> the packet?
> Currently, pcap delivers packets to my application at intervals and it 
> batches the packets before delivering them. There are substantial time 
> differences between when the packet is received by pcap and when it is 
> finally delivered by the application.

pcap does not itself buffer packets.  Packet capture mechanisms, such as 
PF_PACKET sockets in memory-mapped mode on Linux, BPF devices on 
macOS/*BSD/AIX/Solaris 11, and NPF for Windows, do the buffering.

This is intentional; it's done to reduce the overhead of per-packet capture by:

doing only one wakeup per batch of packets rather than per packet;

if the mechanism copies from the kernel to user space, doing one copy 
per batch of packets rather than per packet;

packing multiple packets into a single chunk of the buffer.

The buffering has a timeout, so that packets don't have to wait for a buffer to 
fill up before being delivered to userland code such as libpcap.  Libpcap 
allows the application to choose the timeout.

See the "packet buffer timeout" section of the main pcap man page:

https://www.tcpdump.org/manpages/pcap.3pcap.html

> In the screenshot I attached, 6 packets were received within 400ms but all 
> delivered at the same time.

That's probably because your application has requested a 400ms timeout in a 
call to pcap_open_live() or pcap_set_timeout() by passing 400 as the timeout 
value (which is in milliseconds).  You can either 1) choose a shorter timeout 
or 2) use immediate mode, as per Denis's message.--- End Message ---
___
tcpdump-workers mailing list
tcpdump-workers@lists.tcpdump.org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers


Re: [tcpdump-workers] Pcap delivers packets every 200ms

2023-02-02 Thread Denis Ovsienko via tcpdump-workers
--- Begin Message ---
On Thu, 2 Feb 2023 15:42:55 +
Paschal Chukwuebuk Amusuo via tcpdump-workers
 wrote:

> Hi,
> 
> Please, is there any way to force pcap to deliver packets once it
> receives the packet? Currently, pcap delivers packets to my
> application at intervals and it batches the packets before delivering
> them. There are substantial time differences between when the packet
> is received by pcap and when it is finally delivered by the
> application.

Please see
https://www.tcpdump.org/manpages/pcap_set_immediate_mode.3pcap.html and
try the function.

> In the screenshot I attached, 6 packets were received within 400ms
> but all delivered at the same time.

This list strips non-text attachments (for clarity HTML is considered
not text for this purpose), so the screenshot didn't make it through.

-- 
Denis Ovsienko
--- End Message ---
___
tcpdump-workers mailing list
tcpdump-workers@lists.tcpdump.org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers


[tcpdump-workers] Pcap delivers packets every 200ms

2023-02-02 Thread Paschal Chukwuebuk Amusuo via tcpdump-workers
--- Begin Message ---
Hi,

Please, is there any way to force pcap to deliver packets once it receives the 
packet?
Currently, pcap delivers packets to my application at intervals and it batches 
the packets before delivering them. There are substantial time differences 
between when the packet is received by pcap and when it is finally delivered by 
the application.

In the screenshot I attached, 6 packets were received within 400ms but all 
delivered at the same time.


--- End Message ---
___
tcpdump-workers mailing list
tcpdump-workers@lists.tcpdump.org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers