Documentation
¶
Overview ¶
Package active sends ARP requests to every IP in a CIDR and feeds observed replies into a callback.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sweep ¶
func Sweep(ctx context.Context, ifaceName string, srcMAC net.HardwareAddr, srcIP net.IP, cidr *net.IPNet, window time.Duration, onObs func(devicestore.Observation)) error
Sweep sends ARP requests for every host in cidr from the operator's (srcMAC, srcIP) on the given iface, listens for replies for window, and invokes onObs for each reply.
onObs is invoked from a dedicated listener goroutine; it must be safe for concurrent use. Sweep returns only after the listener goroutine has exited, so onObs is never called after Sweep returns.
Opens its own read+write pcap handle. Callers that already have a long-lived write handle (the daemon's arpengine) should prefer SweepWithWriter to share that handle and avoid a second pcap_activate on the same iface.
func SweepWithWriter ¶
func SweepWithWriter(ctx context.Context, ifaceName string, srcMAC net.HardwareAddr, srcIP net.IP, cidr *net.IPNet, window time.Duration, writer FrameWriter, onObs func(devicestore.Observation)) error
SweepWithWriter is Sweep with an injected FrameWriter for the send path. When writer != nil:
- the read handle is opened with promisc=false (we only need replies to our own ARP, which arrive at our MAC regardless of promisc — dropping promisc avoids the driver's monitor-adjacent state on Wi-Fi and removes a class of per-frame kernel work)
- frames are sent through writer.WriteFrame (the engine's shared handle) instead of the local read-handle's WritePacketData
When writer is nil: behaves identically to v1 Sweep — opens a single promiscuous handle and uses it for both directions. This preserves the standalone-test path where there is no arpengine to inject.
Types ¶
type FrameWriter ¶
FrameWriter is the minimal interface Sweep needs for the send side. Implemented by arpengine.Engine.WriteFrame so the daemon can reuse the engine's long-lived pcap handle instead of having Sweep open a second write capacity on the same iface (saves one pcap_activate per scan and lets the read handle drop promisc mode — see Sweep docstring).
nil is an acceptable value: Sweep then opens its own read+write handle as the v1 code did, preserving the standalone-test path where there's no arpengine instance to inject.