Documentation
¶
Overview ¶
Package lan finds the address a second device on the same network can reach this machine at.
The daemon binds loopback and nothing else unless the user turns LAN access on. When they do, it binds **one named address** rather than `0.0.0.0`. The difference matters: `0.0.0.0` accepts on every interface a machine has now or acquires later — a VPN that comes up, a container bridge, a phone tethered over USB — and none of those were what the user agreed to. A single address is a promise that can be shown on screen and checked.
Nothing here reaches the network. The addresses come from the kernel's own interface list; no name is registered, no discovery packet is sent, and nothing outside the machine learns that Caprock is running until somebody types a code into it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoAddress = errors.New("no private network address on this machine")
ErrNoAddress is returned when the machine has no private IPv4 address — a laptop with wifi off, or a host whose only route is a public address we deliberately will not bind.
Functions ¶
func Address ¶
Address returns the private IPv4 address a device on the same network would use to reach this machine.
IPv4 only, and private only. A link-local address (169.254/16) means the interface never got a lease and nothing can route to it; a public address on an interface would put the dashboard on the internet, which is a different decision from "let my tablet in" and is not one this function will make on anyone's behalf.
A Tailscale address wins when there is one. It is the address that reaches a tablet on mobile data — a LAN address only works on the same network, which is the case the person asking for this usually does not have. Otherwise the first private address in interface order wins, and the rest are returned by Addresses so the user can be shown the choice rather than guessed at.
func Addresses ¶
Addresses returns every private IPv4 address on an interface that is up, in the order the kernel lists them.
func MagicDNSName ¶ added in v0.77.0
MagicDNSName is the MagicDNS name of this machine's Tailscale address ip ("mac.tailnet-1234.ts.net"), or "" when Tailscale's CLI is missing, slow, MagicDNS is off, or the name is not ip's.
Read-only: `tailscale status --json` asks the local tailscaled over its socket and changes nothing. Nothing reaches the network, and Tailscale's own configuration is never written.
func Other ¶ added in v0.77.0
Other returns the first address of the other kind than primary: the Tailscale address when primary is a LAN one, the LAN address when primary is Tailscale's. Nil when there is none.
LAN access listens on both when both exist (WP-15): a phone on the same Wi-Fi uses the LAN address, one on mobile data the Tailscale one, and the pairing panel offers each as a QR. Still named addresses, never 0.0.0.0.
Types ¶
type Interface ¶ added in v0.70.1
Interface is one network interface as Addresses sees it: a name and every address on it. Separate from net.Interface so the choice can be tested against machines this one is not — a laptop behind a carrier's NAT, a host running Tailscale, a VPN that borrows the same range.