pcapfile

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package pcapfile loads an Ethernet capture into a form the transmit loop can replay without allocating.

It uses gopacket's pure-Go pcapgo reader, so Wireblast has no libpcap or cgo dependency and a static binary works anywhere.

The whole file is read and validated before the dataplane starts. A broken or unsupported capture should cost you an error message, never a bounced link and a half-started run.

Index

Constants

View Source
const (
	// MinFrame is the smallest thing that can be an Ethernet frame: two MAC
	// addresses and an EtherType.
	MinFrame = 14
	// MaxFrame is the largest frame that can be transmitted. A UMEM frame is
	// at most a page, so anything above that is chained across several; this
	// stays comfortably inside how many frames one packet may span, and
	// preflight rejects a capture that does not.
	MaxFrame = 16384
	// DefaultMaxBytes is the memory budget a capture may occupy when the
	// caller does not choose one. The whole capture is held in RAM (which this
	// runs as root on), so an unbounded load could OOM the host before the NIC
	// is ever touched; anyone with more memory can raise the budget with
	// --pcap-memory.
	DefaultMaxBytes = 1 << 30 // 1 GiB

)

Limits on what will be loaded.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File is a loaded capture, ready to replay.

Frames live in one contiguous byte slice with an index alongside, so replay is a slice expression and a copy — no per-packet allocation, and the frames stay adjacent in memory for the cache's benefit.

func Load

func Load(path string, lim Limits) (*File, error)

Load reads and validates a capture file.

func (*File) Bytes

func (f *File) Bytes() int

Bytes is the total size of the loaded frames.

func (*File) Describe

func (f *File) Describe() string

Describe summarises the capture for the review screen and the dashboard.

func (*File) Frame

func (f *File) Frame(i int) ([]byte, time.Duration)

Frame returns the i-th frame and the gap the capture recorded before it. The returned slice aliases the backing store and must not be modified.

func (*File) Len

func (f *File) Len() int

Len is how many frames the capture holds.

func (*File) MaxLen

func (f *File) MaxLen() int

MaxLen is the largest frame in the capture, in bytes.

func (*File) MeanLen

func (f *File) MeanLen() int

MeanLen is the mean frame size, used as the rate limiter's estimate.

func (*File) MinLen

func (f *File) MinLen() int

MinLen is the smallest frame in the capture, in bytes.

func (*File) Span

func (f *File) Span() time.Duration

Span is the wall-clock duration the capture covers.

func (*File) Truncated

func (f *File) Truncated() int

Truncated is how many frames were cut short by the capture's snaplen. Those replay as the bytes that were actually captured, which is shorter than what the original host sent.

func (*File) Warnings

func (f *File) Warnings() []string

Warnings lists things about the capture the user should know before replaying it.

type Limits added in v0.4.0

type Limits struct {
	// MaxBytes is the memory budget for the capture, counting frame bytes and
	// the per-frame index. Zero means DefaultMaxBytes.
	MaxBytes uint64
}

Limits is what the caller allows Load to hold in memory. The zero value means the defaults.

Jump to

Keyboard shortcuts

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