capture

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package capture turns raw packets into attributed flows. The decoding logic here is pure (no libpcap dependency) so it can be unit tested with crafted or replayed packets; the live/offline pcap plumbing lives in source.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FriendlyName added in v0.12.0

func FriendlyName(bsd string) (string, bool)

FriendlyName returns the interface name as-is on Linux (no SystemConfiguration).

func LocalIPs

func LocalIPs() []string

LocalIPs returns every unicast address configured on the host's interfaces.

Types

type Decoder

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

Decoder converts gopacket packets into types.Flow, attributing direction against the set of local interface addresses and feeding observed DNS answers into the supplied cache.

func NewDecoder

func NewDecoder(localIPs []string, dns *dnscache.Cache) *Decoder

NewDecoder builds a Decoder. localIPs is the set of addresses belonging to this host (used to decide upload vs download); dns may be nil to skip DNS learning.

func (*Decoder) Decode

func (d *Decoder) Decode(pkt gopacket.Packet) (types.Flow, bool)

Decode reduces a packet to a Flow. The bool is false when the packet is not an attributable IP/TCP/UDP packet (e.g. ARP, loopback chatter) or when it is purely intra-host traffic we choose to ignore.

type LiveSupervisor added in v0.14.0

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

LiveSupervisor keeps capture running on the active network interface, re-opening when the default route changes (e.g. Wi-Fi <-> Ethernet).

func NewLiveSupervisor added in v0.5.0

func NewLiveSupervisor(iface string, dns *dnscache.Cache, prefPath string) *LiveSupervisor

func (*LiveSupervisor) ListInterfaces added in v0.14.0

func (ls *LiveSupervisor) ListInterfaces() []types.NetIface

func (*LiveSupervisor) Name added in v0.14.0

func (ls *LiveSupervisor) Name() string

func (*LiveSupervisor) Paused added in v0.14.0

func (ls *LiveSupervisor) Paused() bool

func (*LiveSupervisor) PreferredInterface added in v0.14.0

func (ls *LiveSupervisor) PreferredInterface() string

func (*LiveSupervisor) Run added in v0.14.0

func (ls *LiveSupervisor) Run(ctx context.Context, out chan<- types.Flow) error

func (*LiveSupervisor) SetOnInterface added in v0.14.0

func (ls *LiveSupervisor) SetOnInterface(fn func(string))

func (*LiveSupervisor) SetOnLive added in v0.22.0

func (ls *LiveSupervisor) SetOnLive(fn func(bool))

SetOnLive registers a callback invoked with true when a capture source opens and false when one ends, so the UI can tell an idle link from a gap in capture. Wired here as well as on darwin: a flag that is always true would be exactly the unearned reassurance it exists to remove.

func (*LiveSupervisor) SetPaused added in v0.14.0

func (ls *LiveSupervisor) SetPaused(p bool)

func (*LiveSupervisor) SetPreferredInterface added in v0.14.0

func (ls *LiveSupervisor) SetPreferredInterface(name string) error

type Source

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

Source wraps a pcap handle and decoder, yielding attributed flows.

func OpenLive

func OpenLive(iface string, dns *dnscache.Cache) (*Source, error)

OpenLive starts live capture on iface (empty = auto-detect) and returns a Source that reads packets via libpcap.

func OpenOffline

func OpenOffline(path string, localIPs []string, dns *dnscache.Cache) (*Source, error)

OpenOffline replays a pcap file.

func (*Source) Name

func (s *Source) Name() string

func (*Source) Run

func (s *Source) Run(ctx context.Context, out chan<- types.Flow) error

Jump to

Keyboard shortcuts

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