Skip to content

Commit

Permalink
Fix packetcapture packets unrecognized issue on osx.
Browse files Browse the repository at this point in the history
By default, gopacket will write snap length=0 in the pcapng file
header, means unlimited snaplen. tcpdump on osx(libpcap version 1.10.1)
cannot recognize this and will report error. This patch will set
a default value(524288) for it.

Signed-off-by: Hang Yan <yhang@vmware.com>
  • Loading branch information
hangyan committed Nov 12, 2024
1 parent b6d4238 commit 0938e84
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/agent/packetcapture/packetcapture_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,14 @@ func (c *Controller) performCapture(
if err != nil {
return false, err
}
pcapngWriter, err := pcapgo.NewNgWriter(file, layers.LinkTypeEthernet)

// set SnapLength here to make tcpdump on Mac OSX works. By default, its value is
// 0 and means unlimited, but tcpdump on Mac OSX will complain:
// 'tcpdump: pcap_loop: invalid packet capture length <len>, bigger than snaplen of 524288'
defaultNgInterface := pcapgo.DefaultNgInterface
defaultNgInterface.SnapLength = 524288
defaultNgInterface.LinkType = layers.LinkTypeEthernet
pcapngWriter, err := pcapgo.NewNgWriterInterface(file, defaultNgInterface, pcapgo.DefaultNgWriterOptions)
if err != nil {
return false, fmt.Errorf("couldn't initialize a pcap writer: %w", err)
}
Expand Down

0 comments on commit 0938e84

Please sign in to comment.