Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimal SNAPLEN for PCAP live capture

Tags:

People also ask

What is Snaplen in PCAP?

Snaplen is an abbreviation for snapshot length. Snaplen equals the number of bytes captured for each packet. Having a snaplen smaller than the maximum packet size on the network might allow you to store more packets. However, you are likely limited in your ability to inspect and extract the full packet content.

What is snapshot length in PCAP?

A snapshot length of 65535 should be sufficient, on most if not all networks, to capture all the data available from the packet.

How does Libpcap capture packets?

There are two main techniques for capturing packets. We can either capture a single packet at a time, or we can enter a loop that waits for n number of packets to be sniffed before being done.

How does Libpcap work?

Essentially, the libpcap library grabs packets directly from the network cards, which allowed developers to write programs to decode, display, or log the packets. The TCPDump program did just that.


When using pcap_open_live to sniff from an interface, I have seen a lot of examples using various numbers as SNAPLEN value, ranging from BUFSIZ (<stdio.h>) to "magic numbers".

Wouldn't it make more sense to set as SNAPLEN the MTU of the interface we are capturing from ? In this manner, we could fit more packets at once in PCAP buffer. Is it safe to assume that the MRU is equal to the MTU ?

Otherwise, is there a non-exotic way to set the SNAPLEN value ?

Thanks