devices

package
v0.0.0-...-5929559 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindDeviceByName

func FindDeviceByName(name string) (string, error)

FindDeviceByName returns the device with the provided name.

func ListDeviceNames

func ListDeviceNames(printDescription, printIP bool) ([]string, error)

ListDeviceNames returns a list of available network adapters. The printDescription parameter will include the adapter name and printIP will include the IP assigned to it.

func OpenFile

func OpenFile(file, filter string) (*pcap.Handle, error)

OpenFile opens a DeviceHandle for an offline PCAP session with a given input file.

func OpenPcap

func OpenPcap(device, filter string, timeout time.Duration) (*pcap.Handle, error)

OpenPcap opens a DeviceHandle for a live PCAP session on a given interface.

Types

type AFPacketHandle

type AFPacketHandle struct {
	TPacket *afpacket.TPacket
}

AFPacketHandle is an implementation of a gopacket PacketSource.

func OpenAFPacket

func OpenAFPacket(device, filter string, bufferSize int, timeout time.Duration) (*AFPacketHandle, error)

OpenAFPacket opens a DeviceHandle for live capture via AF_Packet on a given interface. The buffer size depends on system memory, with frame and block sizes calculated from the size of the buffer, system page size, and a default snaplen of 1600. Generally multiples of 25MB are a good size, since 1600 bytes is an even multiple when page sizes are in powers of 2. By default, 128 blocks can fit in 25MB. AF_Packet is only available on Linux systems.

func (*AFPacketHandle) Close

func (h *AFPacketHandle) Close()

Close is an implementation of a gopacket PacketSource's Close method.

func (*AFPacketHandle) LinkType

func (h *AFPacketHandle) LinkType() layers.LinkType

LinkType is an implementation of a gopacket PacketSource's LinkType method.

func (*AFPacketHandle) ReadPacketData

func (h *AFPacketHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err error)

ReadPacketData is an implementation of a gopacket PacketSource's ReadPacketData method.

func (*AFPacketHandle) SetBPFFilter

func (h *AFPacketHandle) SetBPFFilter(filter string, frameSize int) (_ error)

SetBPFFilter is an implementation of a gopacket PacketSource's SetBPFFilter method.

type DeviceHandle

type DeviceHandle interface {
	gopacket.PacketDataSource

	LinkType() layers.LinkType
	Close()
}

DeviceHandle is an implementation of the gopacket PacketDataSource. A custom handle is used so that we can stub out different device types across platforms.

Jump to

Keyboard shortcuts

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