pcap

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LinkTypeEthernet uint32 = 1
)

Common link-layer (DLT) identifiers used in pcap global headers. The values match the tcpdump/libpcap definitions.

Variables

View Source
var (
	// ErrHeaderAlreadyWritten indicates the global header has already been
	// emitted for this writer instance.
	ErrHeaderAlreadyWritten = errors.New("pcap: file header already written")
	// ErrHeaderNotWritten indicates a packet was written before the global header.
	ErrHeaderNotWritten = errors.New("pcap: file header not written")
)

Functions

This section is empty.

Types

type CaptureInfo

type CaptureInfo struct {
	Timestamp     time.Time
	CaptureLength int
	Length        int
}

CaptureInfo describes metadata associated with a captured packet. Timestamp uses microsecond resolution when serialized into the pcap record.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer emits classic libpcap-formatted streams.

func NewWriter

func NewWriter(out io.Writer) *Writer

NewWriter wraps the supplied io.Writer. The caller must invoke WriteFileHeader once before any packets are written.

func (*Writer) WriteFileHeader

func (w *Writer) WriteFileHeader(snapLen uint32, linkType uint32) error

WriteFileHeader writes the 24-byte global pcap header. It must be called exactly once per Writer instance before WritePacket is used.

func (*Writer) WritePacket

func (w *Writer) WritePacket(ci CaptureInfo, data []byte) error

WritePacket appends a captured packet record to the stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL