netbind

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package netbind ties sockets to a network interface or a local address: listeners that accept on chosen interfaces only, and outgoing connections that leave through a chosen interface.

An interface is bound to as a device where the system can (Linux: SO_BINDTODEVICE, macOS: IP_BOUND_IF), so routing cannot send the packets elsewhere, and a connection accepted on it answers through it. Elsewhere, the interface's addresses stand for it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dialer

func Dialer(source string, timeout time.Duration, control func(network, address string, c syscall.RawConn) error) *net.Dialer

Dialer returns a dialer whose connections leave from source: an interface name, an IP address, or empty for wherever routing says. control, if not nil, also runs on each socket. The interface is looked up at each dial, so it may come up after the dialer is made.

func FastOpenHint added in v0.0.4

func FastOpenHint() string

FastOpenHint returns what the system needs for clients' TCP Fast Open, "" for nothing.

func Interface

func Interface(name string) *net.Interface

Interface returns the interface named name, nil if name is an IP address, a host name or empty.

func Listen

func Listen(ctx context.Context, addr string) (net.Listener, error)

Listen listens for TCP on addr, host:port, where host is an IP address, a host name, an interface name, or empty for every address. Clients that have Multipath TCP or TCP Fast Open get them where the system does (Linux).

func Multi

func Multi(ls []net.Listener) net.Listener

Multi accepts on several listeners as one. Its Addr is the first's.

Types

type Spread added in v0.0.4

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

Spread dials from several sources in turn, so connections to a server share them: a server that caps the connections from one address allows more over several. A dial that fails is tried from the next source.

func NewSpread added in v0.0.4

func NewSpread(sources []string, timeout time.Duration, control func(network, address string, c syscall.RawConn) error) *Spread

NewSpread returns a Spread over sources (interface names or local IP addresses; none for wherever routing says), starting at a random one. control is as for Dialer.

func (*Spread) DialContext added in v0.0.4

func (s *Spread) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext dials address from the next source.

Jump to

Keyboard shortcuts

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