loopback

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 5 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 loopback reports whether the host has loopback addresses beyond 127.0.0.1 (ADR 0005). 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

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

View Source
const Host = "127.0.0.1"

Host is the one loopback address every host has.

View Source
const InstallHint = "sudo gcpemu loopback install"

InstallHint is the command that adds the aliases on a host without them.

Variables

This section is empty.

Functions

func AddrInUse

func AddrInUse(err error) bool

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 BindDenied

func BindDenied(err error) bool

BindDenied reports whether err is a bind refused for lack of permission, such as a privileged port.

func IsLoopback

func IsLoopback(a net.Addr) bool

IsLoopback reports whether a is a loopback TCP address.

func Listen

func Listen(ip string, port int, inUse bool) (ln net.Listener, addr string, err error)

Listen binds ip:port for host clients. 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 LocalFilter

type LocalFilter struct {
	net.Listener
	Allow func(net.Addr) bool
}

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.

func (*LocalFilter) Accept

func (f *LocalFilter) Accept() (net.Conn, error)

Jump to

Keyboard shortcuts

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