Documentation
¶
Overview ¶
Package loopback reports whether the host has loopback addresses beyond 127.0.0.1 (ADR 0005), and on macOS whether each is a /32. Linux routes all of 127.0.0.0/8 to loopback; a macOS host has only 127.0.0.1 on lo0 until `gcpemu loopback install` adds aliases for 127.0.0.2 to 127.0.0.254.
Index ¶
Constants ¶
const DarwinPorts = goruntime.GOOS == "darwin"
DarwinPorts is set on macOS, which lets an unprivileged process bind a port below 1024 only on the wildcard address.
const Host = "127.0.0.1"
Host is the one loopback address every host has.
const InstallHint = "sudo gcpemu loopback install"
InstallHint is the command that adds the aliases on a host without them.
const WideHint = "a /8 loopback alias keeps mDNSResponder at 100% CPU on macOS 27 and slows every DNS lookup"
WideHint names the harm of AliasesWide.
Variables ¶
This section is empty.
Functions ¶
func AddrInUse ¶
AddrInUse reports whether err is a bind failing because another socket holds the address.
func Aliases ¶
func Aliases() bool
Aliases reports whether 127.0.0.x addresses other than 127.0.0.1 can be bound, by binding 127.0.0.2:0.
func ExcludedError ¶ added in v0.9.0
ExcludedError wraps err, a bind refused as Excluded, with the command that lists the excluded ranges of network ("tcp" or "udp").
func IsLoopback ¶
IsLoopback reports whether a is a loopback TCP address.
func Listen ¶
Listen binds ip:port for host clients. When the port is in a Windows excluded range, it fails. When the host refuses the port as privileged, it binds the wildcard address on the port on macOS, serving only connections to a loopback address, and otherwise (or when another socket holds the wildcard) a free port on ip. When another socket holds ip:port, it binds a free port on ip if inUse is set, and fails otherwise. addr is the address clients use: ip and the port served.
Types ¶
type AliasState ¶ added in v0.12.0
type AliasState int
AliasState is what lo0's addresses say about the aliases on macOS.
const ( // AliasesMissing: lo0 has no 127.0.0.x address other than 127.0.0.1. AliasesMissing AliasState = iota // AliasesNarrow: every loopback alias is a /32. AliasesNarrow // AliasesWide: some loopback alias has another netmask. `ifconfig lo0 alias` // without one gives the classful /8, and 253 overlapping // 127.0.0.0/8s keep mDNSResponder at 100% CPU on macOS 27 (#677). AliasesWide )
func CheckAliases ¶ added in v0.12.0
func CheckAliases(addrs []net.Addr) AliasState
CheckAliases reads the aliases from addrs, lo0's addresses.
func Lo0Aliases ¶ added in v0.12.0
func Lo0Aliases() AliasState
Lo0Aliases is CheckAliases of the host's lo0, AliasesMissing when lo0 can't be read.
func (AliasState) String ¶ added in v0.12.0
func (s AliasState) String() string
type LocalFilter ¶
LocalFilter serves only the connections whose local address Allow accepts, and closes the others unserved. It keeps a wildcard listener from serving clients on other hosts.
type PortRange ¶ added in v0.9.0
type PortRange struct{ Start, End int }
PortRange is one of Windows' excluded port ranges, Start to End inclusive.
func ExcludedPort ¶ added in v0.9.0
ExcludedPort returns the range of ranges that holds port, if any.
func ExcludedRanges ¶ added in v0.9.0
ExcludedRanges reads Windows' excluded port ranges of network ("tcp" or "udp") with netsh.
func ParseExcludedRanges ¶ added in v0.9.0
ParseExcludedRanges reads the output of `netsh int ipv4 show excludedportrange`: its rows are a start and an end port, and a "*" on administered exclusions. The headings, which Windows translates, are skipped.
type Refusal ¶ added in v0.9.0
type Refusal int
Refusal is what a bind refused for lack of permission means.
const ( // NotRefused: the bind succeeded, or failed for another reason. NotRefused Refusal = iota // Privileged: a privileged port, which only a privileged process // binds. Privileged // PrivilegedWildcard: a privileged port on macOS, which an // unprivileged process binds only on the wildcard address. PrivilegedWildcard // Excluded: a port in one of Windows' excluded port ranges, which // Hyper-V, WSL and others reserve. Windows has no privileged ports, and // no address or relay binds an excluded one (ADR 0015). Excluded )
func RefusalOn ¶ added in v0.9.0
RefusalOn is what a bind refused for lack of permission means on goos.