pcap

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MagicNumber  = 0xa1b2c3d4
	VersionMajor = 2
	VersionMinor = 4

	TimestampCorrection = 0
	TimestampAccuracy   = 0

	DefaultSnapLen = 65535
)
View Source
const (
	GlobalHeaderByteLen = 24
	RecordHeaderByteLen = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Datalink uint32

Datalink defines the type of the first layer of the captured packet

var (
	Null     Datalink = 0
	Ethernet Datalink = 1
)
type Header struct {
	// SnapshotLength is the maximum length of captured packets
	SnapshotLength uint32
	// Datalink is the type of header at the beginning of the packet
	Datalink Datalink
}

Header contains the configurable parameters for the global pcap header

func (*Header) Bytes

func (h *Header) Bytes() []byte

Bytes returns the byte representation of the global pcap header

type Record

type Record struct {
	// Timestamp is the time the packet was captured
	Timestamp time.Time
	// CaptureLength is the size of the captured packet
	CaptureLength uint32
	// OriginalLength is the size of the original packet
	OriginalLength uint32
}

Record contains the configurable parameters for a record header

func (*Record) Bytes

func (r *Record) Bytes() []byte

Bytes returns the byte representation of the per-record pcap header

type RecordWriter

type RecordWriter interface {
	// WriteHeader writes the global pcap header. This must be invoked before
	// WriteRecord is called.
	WriteHeader(header Header) error
	// WriteRecord writes a pcap record to the underlying stream.
	WriteRecord(record Record, packet []byte) error
	io.Closer
}

RecordWriter defines the interface for pcap writers

type Writer

type Writer struct {
	io.WriteCloser
}

Writer wraps a io.WriteCloser to implement RecordWriter

func NewWriter

func NewWriter(w io.WriteCloser) *Writer

NewWriter wraps a io.WriteCloser

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(header Header) error

WriteHeader implements RecordWriter

func (*Writer) WriteRecord

func (w *Writer) WriteRecord(record Record, packet []byte) error

WriteRecord implements RecordWriter

Jump to

Keyboard shortcuts

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