netmon

package
v0.0.0-...-4087627 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Redefine constant to avoid import of gopacket/pcap which requires CGO
	// https://github.com/google/gopacket/blob/v1.1.19/pcap/pcap.go#L124
	BlockForever     time.Duration = -time.Millisecond * 10
	OperationTimeout time.Duration = 3 * time.Second
	SnapLen          int32         = 64
)

Variables

View Source
var (
	// ErrEmptyPacket is returned when a packet of 0 bytes has been received
	ErrEmptyPacket = errors.New("received an empty packet")
	// ErrPacketCaptureClosed is returned when the packet capture channel
	// has been closed unexpectedly
	ErrPacketCaptureClosed = errors.New("packet capture channel closed")
)

Functions

func Scan

func Scan(ctx context.Context, ips []netip.Addr) (map[netip.Addr]net.HardwareAddr, error)

Scan sends ICMP Echo requests to provided IP addresses.

Types

type Binding

type Binding struct {
	// VID is the associated VLAN ID, if one exists
	VID *uint16
	// Time is the time the packet creating / updating the binding
	// was observed
	Time time.Time
	// IP is the IP a binding is tracking
	IP netip.Addr
	// MAC is the MAC address the IP is currently bound to
	MAC net.HardwareAddr
}

Binding represents the binding between an IP address and MAC address

type Event

type Event uint8

Event is an enum value for the type of event observed

const (
	// EventNew is the Event value for a new Result
	EventNew Event = iota + 1
	// EventRefreshed is the Event value for a Result that is for
	// refreshed ARP values
	EventRefreshed
	// EventMoved is the Event value for a Result where the IP has
	// changed its MAC address
	EventMoved
)

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Event

func (Event) String

func (e Event) String() string

String returns the string version of the Event

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler for Event

func (Event) ValidString

func (e Event) ValidString() (string, error)

ValidString returns the string version of the Event and errors if a non-valid one was given

type IPHwAddressPair

type IPHwAddressPair struct {
	IP        netip.Addr
	HwAddress net.HardwareAddr
}

type Result

type Result struct {
	// VID is the VLAN ID if one exists
	VID *uint16 `json:"vid"`
	// IP is the presentation format of an observed IP
	IP string `json:"ip"`
	// MAC is the presentation format of an observed MAC
	MAC string `json:"mac"`
	// Previous MAC is the presentation format of a previous MAC if
	// an EventMoved was observed
	PreviousMAC string `json:"previous_mac,omitempty"`
	// Time is the time the packet creating the Result was observed
	Time int64 `json:"time"`
	// Event is the type of event the Result is
	Event Event `json:"event"`
}

Result is the result of observed ARP packets

type Service

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

Service is responsible for starting packet capture and converting observed ARP packets into discovered Results

func NewService

func NewService(iface string) *Service

NewService returns a pointer to a Service. It takes the desired interface to observe's name as an argument

func (*Service) Start

func (s *Service) Start(ctx context.Context, resultC chan<- Result) error

Start will start packet capture and send results to a channel

Jump to

Keyboard shortcuts

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