lan

package
v0.189.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 10 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 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

View Source
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

func Address() (net.IP, error)

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

func Addresses() ([]net.IP, error)

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

func MagicDNSName(ctx context.Context, ip net.IP) string

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

func Other(primary net.IP) net.IP

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.

func TailscaleUp added in v0.116.0

func TailscaleUp() bool

TailscaleUp reports whether this machine has a Tailscale address right now, listened on or not. The pairing panel asks it every few seconds while it is open, so a person who installs Tailscale sees "works anywhere" without a restart; it reads the kernel's interface list and nothing else.

func Tunnelled added in v0.50.0

func Tunnelled(ip net.IP) bool

Tunnelled reports whether ip is a Tailscale address rather than a LAN one. The dashboard says which, because they answer different questions: a LAN address works at home and nowhere else; a tunnel address works anywhere the other device has the tunnel too.

Types

type Interface added in v0.70.1

type Interface struct {
	Name string
	IPs  []net.IP
}

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.

Jump to

Keyboard shortcuts

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