pcap

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package pcap provides utilities to capture WiFi packets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseProbeReqSSID

func ParseProbeReqSSID(req *layers.Dot11MgmtProbeReq) (string, error)

ParseProbeReqSSID parses the frame body of a probe request packet and returns the SSID in the request.

func ReadPackets

func ReadPackets(pcapFile string, filters ...Filter) ([]gopacket.Packet, error)

ReadPackets reads packets from a pcap file and returns the ones which pass all the filters.

Types

type Capturer

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

Capturer controls a tcpdump process to capture packets on an interface.

func StartCapturer

func StartCapturer(ctx context.Context, host *ssh.Conn, name, iface, workDir string, opts ...Option) (*Capturer, error)

StartCapturer creates and starts a Capturer. After getting a Capturer instance, c, the caller should call c.Close() at the end, and use the shortened ctx (provided by c.ReserveForClose()) before c.Close() to reserve time for it to run.

func (*Capturer) Close

func (c *Capturer) Close(ctx context.Context) error

Close terminates the capturer and downloads the pcap file from host to OutDir.

func (*Capturer) Interface

func (c *Capturer) Interface() string

Interface returns the interface the capturer runs on.

func (*Capturer) PacketPath

func (c *Capturer) PacketPath(ctx context.Context) (string, error)

PacketPath returns the path of the result pcap file so that the tests can verify the content of captured packets. This function should be called after Close (i.e. packet downloaded), otherwise it will return error.

func (*Capturer) ReserveForClose

func (c *Capturer) ReserveForClose(ctx context.Context) (context.Context, context.CancelFunc)

ReserveForClose returns a shortened ctx with cancel function. The shortened ctx is used for running things before c.Close() to reserve time for it to run.

type Filter

type Filter func(gopacket.Packet) bool

Filter is the function type for filtering packets. The packet should be dropped if it returns false.

func Dot11FCSValid

func Dot11FCSValid() Filter

Dot11FCSValid returns a Filter which ensures the frame check sequence of the 802.11 frame is valid. It checks RadioTapFCS and Dot11FCS in sequence. Checking Dot11 FCS after RadioTap.Flags.BadFCS=false is redundant for most cases. But there is still one rare case we need to cover, which is RadioTap integrity checking is malfunctioning.

func RejectLowSignal

func RejectLowSignal() Filter

RejectLowSignal returns a Filter which ensures the signal strength is good enough (greater than -85 dBm).

func TransmitterAddress

func TransmitterAddress(mac net.HardwareAddr) Filter

TransmitterAddress returns a Filter which ensures the Transmitter Address matches the given MAC address.

func TypeFilter

func TypeFilter(t gopacket.LayerType, check func(gopacket.Layer) bool) Filter

TypeFilter returns a Filter which ensures the packet contains a Layer with type t and passes the check function on the layer if check() is given.

type Option

type Option func(*Capturer)

Option is the type of options to start Capturer object.

func Snaplen

func Snaplen(s uint64) Option

Snaplen returns an option which sets a Capturer's snapshot length.

Jump to

Keyboard shortcuts

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