lanaddr

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lanaddr finds the address a LAN relay advertises (R74 PP2, docs/76 §6.1 item 4): the IPv4 address of the interface that holds the default route, with loopback, link-local, container and virtual bridges, VPN tunnels and every non-private address (CGNAT and public ones included) excluded. The host can pick another candidate in the console; a DHCP change is picked up by the Watcher.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Addr    netip.Addr
	Iface   string
	Primary bool
}

Candidate is one advertisable address.

func Detect

func Detect() ([]Candidate, error)

Detect enumerates the host's interfaces and returns Filter's candidates.

func Filter

func Filter(ifs []Iface, defaultRouteIface string) []Candidate

Filter is the pure half of Detect: the candidates among ifs, primary first. Only private addresses are kept (RFC 1918, and unique-local IPv6), because the pinned join link is accepted only for private literals (docs/76 §6.1 item 5). The primary is the first IPv4 address on defaultRouteIface; without one (no default route, as at a LAN party with no internet, or a route over a VPN), the first IPv4 candidate in interface-name order.

type Iface

type Iface struct {
	Name  string
	Flags net.Flags
	Addrs []netip.Prefix
}

Iface is the slice of a network interface Filter looks at.

type Watcher

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

Watcher tracks the advertised address: the host's override when set, otherwise the primary candidate, re-detected every period.

func NewWatcher

func NewWatcher(override string, every time.Duration) *Watcher

NewWatcher returns a watcher; override is -lan-address ("auto", "" or an IP literal). It detects nothing until Refresh or Run.

func (*Watcher) Candidates

func (w *Watcher) Candidates() []Candidate

Candidates is the last detection, primary first.

func (*Watcher) Current

func (w *Watcher) Current() netip.Addr

Current is the address to advertise; the zero Addr when there is none.

func (*Watcher) Refresh

func (w *Watcher) Refresh()

Refresh re-detects now. A detection error keeps the previous candidates.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

Run refreshes immediately and then every period until ctx ends. It returns nil on cancellation, so it can ride serve.Options.Extra.

func (*Watcher) SetOverride

func (w *Watcher) SetOverride(a netip.Addr)

SetOverride pins the advertised address (the console's pick); the zero Addr goes back to detection.

func (*Watcher) Subscribe

func (w *Watcher) Subscribe(fn func(netip.Addr)) (cancel func())

Subscribe runs fn with the new address whenever Current changes.

Jump to

Keyboard shortcuts

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