
我想知道為什麼 tcpdump 將幻數262144
作為預設快照長度?
--snapshot-length=snaplen Snarf 每個資料包中的 snaplen 位元組數據,而不是預設的 262144 位元組。由於有限快照而被截斷的資料包在輸出中以「[|proto]」指示,其中 proto 是發生截斷的協定層級的名稱。請注意,拍攝較大的快照不僅會增加處理資料包所需的時間,而且會有效減少資料包緩衝量。這可能會導致資料包遺失。另請注意,拍攝較小的快照將丟棄傳輸層之上的協定中的數據,這會丟失可能重要的資訊。例如,NFS 和 AFS 請求和回覆非常大,如果選擇的快照長度太短,則許多詳細資訊將不可用。如果您需要將快照大小減少到預設值以下,則應將snaplen 限制為能夠捕獲您感興趣的協定資訊的最小數字。版本tcpdump 的版本。
參考:手冊頁
答案1
https://github.com/the-tcpdump-group/tcpdump/blob/tcpdump-4.9/netdissect.h
/*
* Maximum snapshot length. This should be enough to capture the full
* packet on most network interfaces.
*
*
* Somewhat arbitrary, but chosen to be:
*
* 1) big enough for maximum-size Linux loopback packets (65549)
* and some USB packets captured with USBPcap:
*
* http://desowin.org/usbpcap/
*
* (> 131072, < 262144)
*
* and
*
* 2) small enough not to cause attempts to allocate huge amounts of
* memory; some applications might use the snapshot length in a
* savefile header to control the size of the buffer they allocate,
* so a size of, say, 2^31-1 might not work well.
*
* XXX - does it need to be bigger still?
*/
#define MAXIMUM_SNAPLEN 262144
沒什麼太多的。 Linux 環回不受硬體幀的限制,因此具有相當大的最大大小(64k)。其他資料包可能更大,例如 2 的幾次方到 256k。