Filament::Capture::PcapWriter
Inherits Reference < Object
Creates new PCAP capture files. Writes the global header on initialization, then individual packets as they come in.
writer = Filament::Capture::PcapWriter.new("output.pcap")
writer.write_packet(packet_bytes, Time.utc)
writer.close
Constructors
Opens a new PCAP file for writing. Creates the file and writes the global header immediately.
Creates a writer from an existing IO and header. Writes the global header to the IO immediately.
Class methods
Opens a PCAP file for writing, yields writer to block, and guarantees closure
Instance methods
Flushes the underlying IO buffer to disk. Call this periodically during long captures so you don't lose data on a crash.
Writes a single packet to the file. The data is the raw packet bytes (starting with the link-layer header), and timestamp is when the packet was captured.
If the data is longer than the snap length, it gets truncated in the file but the original length is preserved in the header.
Writes a RawPacket struct to the file. Convenience wrapper around the bytes-based write_packet method.