netbind

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 8 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 netbind keeps sockets on one network interface, such as a VPN's wg0, so their traffic can't take another route when the interface goes away: connecting fails instead. It sets SO_BINDTODEVICE on Linux and IP_BOUND_IF on macOS.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("binding to a network interface is supported on Linux and macOS only")

ErrUnsupported is returned on platforms that can't bind to an interface.

Functions

This section is empty.

Types

type Binder

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

Binder binds sockets to an interface. A nil Binder binds nothing.

func New

func New(name string) (*Binder, error)

New returns a Binder for the interface name, or nil for "".

func (*Binder) Control

func (b *Binder) Control(network, _ string, c syscall.RawConn) error

Control binds a socket to the interface; it is a net.Dialer's and a net.ListenConfig's Control. It fails when the interface doesn't exist.

func (*Binder) DialContext

func (b *Binder) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext connects through the interface.

func (*Binder) Dialer

func (b *Binder) Dialer() *net.Dialer

Dialer returns a dialer bound to the interface.

func (*Binder) ListenPacket

func (b *Binder) ListenPacket(network, addr string) (net.PacketConn, error)

ListenPacket opens a UDP socket bound to the interface.

func (*Binder) Name

func (b *Binder) Name() string

Name is the interface's name.

func (*Binder) Resolver

func (b *Binder) Resolver() *net.Resolver

Resolver looks names up through the interface. A name server on loopback, such as Docker's or systemd-resolved's stub, is asked directly, since a bound socket can't reach it; where it sends the query on is up to it.

func (*Binder) State

func (b *Binder) State() State

State reports the interface's state now.

type State

type State struct {
	Up    bool
	Index int
}

State is whether the interface exists and is up, and its index, which changes when the interface is created again.

Jump to

Keyboard shortcuts

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