net

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	IPv4len = net.IPv4len
	IPv6len = net.IPv6len

	FlagUp           = net.FlagUp
	FlagBroadcast    = net.FlagBroadcast
	FlagLoopback     = net.FlagLoopback
	FlagPointToPoint = net.FlagPointToPoint
	FlagMulticast    = net.FlagMulticast
	FlagRunning      = net.FlagRunning
)

Variables

View Source
var (
	JoinHostPort  = net.JoinHostPort
	ParseCIDR     = net.ParseCIDR
	Pipe          = net.Pipe
	SplitHostPort = net.SplitHostPort
)
View Source
var (
	IPv4bcast     = net.IPv4bcast
	IPv4allsys    = net.IPv4allsys
	IPv4allrouter = net.IPv4allrouter
	IPv4zero      = net.IPv4zero

	IPv6zero                   = net.IPv6zero
	IPv6unspecified            = net.IPv6unspecified
	IPv6loopback               = net.IPv6loopback
	IPv6interfacelocalallnodes = net.IPv6interfacelocalallnodes
	IPv6linklocalallnodes      = net.IPv6linklocalallnodes
	IPv6linklocalallrouters    = net.IPv6linklocalallrouters

	DefaultResolver = wrapResolver(net.DefaultResolver)

	ErrClosed           = net.ErrClosed
	ErrWriteToConnected = net.ErrWriteToConnected
)

Functions

func NewNet

func NewNet() netFacade

Types

type Addr

type Addr = net.Addr

type AddrError

type AddrError = net.AddrError

type Buffers

type Buffers = net.Buffers

type Conn

type Conn = net.Conn

type DNSConfigError

type DNSConfigError = net.DNSConfigError

type DNSError

type DNSError = net.DNSError

type Dialer

type Dialer interface {
	Dial(network, address string) (Conn, error)
	DialContext(ctx context.Context, network, address string) (Conn, error)
	MultipathTCP() bool
}

type DialerOption

type DialerOption func(*net.Dialer)

func WithCancel

func WithCancel(c <-chan struct{}) DialerOption

func WithControl

func WithControl(f func(string, string, syscall.RawConn) error) DialerOption

func WithControlContext

func WithControlContext(f func(context.Context, string, string, syscall.RawConn) error) DialerOption

func WithDeadline

func WithDeadline(t time.Time) DialerOption

func WithDualStack

func WithDualStack() DialerOption

func WithFallbackDelay

func WithFallbackDelay(d time.Duration) DialerOption

func WithKeepAlive

func WithKeepAlive(d time.Duration) DialerOption

func WithKeepAliveConfig

func WithKeepAliveConfig(cfg KeepAliveConfig) DialerOption

func WithLocalAddr

func WithLocalAddr(addr Addr) DialerOption

func WithResolver

func WithResolver(r Resolver) DialerOption

func WithSetMultipathTCP

func WithSetMultipathTCP(b bool) DialerOption

func WithTimeout

func WithTimeout(d time.Duration) DialerOption

type Error

type Error = net.Error

type Flags

type Flags = net.Flags

type IP

type IP = net.IP

type IPAddr

type IPAddr = net.IPAddr

type IPConn

type IPConn interface {
	Close() error
	File() (f *os.File, err error)
	LocalAddr() Addr
	Read(b []byte) (int, error)
	ReadFrom(b []byte) (int, Addr, error)
	ReadFromIP(b []byte) (int, *IPAddr, error)
	ReadMsgIP(b, oob []byte) (n, oobn, flags int, addr *IPAddr, err error)
	RemoteAddr() Addr
	SetDeadline(t time.Time) error
	SetReadBuffer(bytes int) error
	SetReadDeadline(t time.Time) error
	SetWriteBuffer(bytes int) error
	SetWriteDeadline(t time.Time) error
	SyscallConn() (syscall.RawConn, error)
	Write(b []byte) (int, error)
	WriteMsgIP(b, oob []byte, addr *IPAddr) (n, oobn int, err error)
	WriteTo(b []byte, addr Addr) (int, error)
	WriteToIP(b []byte, addr *IPAddr) (int, error)
}

type IPMask

type IPMask = net.IPMask

type IPNet

type IPNet = net.IPNet

type Interface

type Interface = net.Interface

type InvalidAddrError

type InvalidAddrError = net.InvalidAddrError

type KeepAliveConfig

type KeepAliveConfig = net.KeepAliveConfig

type ListenConfig

type ListenConfig interface {
	Listen(ctx context.Context, network, address string) (Listener, error)
	ListenPacket(ctx context.Context, network, address string) (PacketConn, error)
	MultipathTCP() bool
}

type ListenConfigOption

type ListenConfigOption func(*net.ListenConfig)

func WithControlLC

func WithControlLC(f func(string, string, syscall.RawConn) error) ListenConfigOption

func WithKeepAliveConfigLC

func WithKeepAliveConfigLC(kac KeepAliveConfig) ListenConfigOption

func WithKeepAliveLC

func WithKeepAliveLC(d time.Duration) ListenConfigOption

type Listener

type Listener = net.Listener

type MX

type MX = net.MX

type NS

type NS = net.NS

type Net

type Net interface {
	JoinHostPort(host, port string) string
	LookupAddr(addr string) (names []string, err error)
	LookupCNAME(host string) (cname string, err error)
	LookupHost(host string) (addrs []string, err error)
	LookupPort(network, service string) (port int, err error)
	LookupTXT(name string) ([]string, error)
	ParseCIDR(s string) (IP, *IPNet, error)
	Pipe() (Conn, Conn)
	SplitHostPort(hostport string) (host, port string, err error)

	// Constructors:
	InterfaceAddrs() ([]Addr, error)
	Dial(network, address string) (Conn, error)
	DialTimeout(network, address string, timeout time.Duration) (Conn, error)
	FileConn(f *os.File) (Conn, error)
	IPv4(a, b, c, d byte) IP
	LookupIP(host string) ([]IP, error)
	ParseIP(s string) IP
	ResolveIPAddr(network, address string) (*IPAddr, error)
	DialIP(network string, laddr, raddr *IPAddr) (IPConn, error)
	ListenIP(network string, laddr *IPAddr) (IPConn, error)
	CIDRMask(ones, bits int) IPMask
	IPv4Mask(a, b, c, d byte) IPMask
	InterfaceByIndex(index int) (*Interface, error)
	InterfaceByName(name string) (*Interface, error)
	Interfaces() ([]Interface, error)
	FileListener(f *os.File) (Listener, error)
	Listen(network, address string) (Listener, error)
	LookupMX(name string) ([]*MX, error)
	LookupNS(name string) ([]*NS, error)
	FilePacketConn(f *os.File) (PacketConn, error)
	ListenPacket(network, address string) (PacketConn, error)
	LookupSRV(service, proto, name string) (string, []*SRV, error)
	ResolveTCPAddr(network, address string) (*TCPAddr, error)
	TCPAddrFromAddrPort(addr netip.AddrPort) *TCPAddr
	DialTCP(network string, laddr, raddr *TCPAddr) (TCPConn, error)
	ListenTCP(network string, laddr *TCPAddr) (TCPListener, error)
	ResolveUDPAddr(network, address string) (*UDPAddr, error)
	DialUDP(network string, laddr, raddr *UDPAddr) (UDPConn, error)
	ListenMulticastUDP(network string, ifi *Interface, gaddr *UDPAddr) (UDPConn, error)
	ListenUDP(network string, laddr *UDPAddr) (UDPConn, error)
	ResolveUnixAddr(network, address string) (*UnixAddr, error)
	DialUnix(network string, laddr, raddr *UnixAddr) (UnixConn, error)
	ListenUnixgram(network string, laddr *UnixAddr) (UnixConn, error)
	ListenUnix(network string, laddr *UnixAddr) (UnixListener, error)

	NewDialer(options ...DialerOption) Dialer
	NewListenConfig(options ...ListenConfigOption) ListenConfig
	NewResolver(options ...ResolverOption) Resolver
}

type OpError

type OpError = net.OpError

type PacketConn

type PacketConn = net.PacketConn

type ParseError

type ParseError = net.ParseError

type Resolver

type Resolver interface {
	LookupAddr(ctx context.Context, addr string) ([]string, error)
	LookupCNAME(ctx context.Context, host string) (string, error)
	LookupHost(ctx context.Context, host string) (addrs []string, err error)
	LookupIP(ctx context.Context, network, host string) ([]IP, error)
	LookupIPAddr(ctx context.Context, host string) ([]IPAddr, error)
	LookupMX(ctx context.Context, name string) ([]*MX, error)
	LookupNS(ctx context.Context, name string) ([]*NS, error)
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
	LookupPort(ctx context.Context, network, service string) (port int, err error)
	LookupSRV(ctx context.Context, service, port, name string) (string, []*SRV, error)
	LookupTXT(ctx context.Context, name string) ([]string, error)

	GetUnderlyingResolver() *net.Resolver
}

type ResolverOption

type ResolverOption func(res *net.Resolver)

func WithDialFunc

func WithDialFunc(fn func(context.Context, string, string) (Conn, error)) ResolverOption

func WithPreferGo

func WithPreferGo() ResolverOption

func WithStrictErrors

func WithStrictErrors() ResolverOption

type SRV

type SRV = net.SRV

type TCPAddr

type TCPAddr = net.TCPAddr

type TCPConn

type TCPConn interface {
	Close() error
	CloseRead() error
	CloseWrite() error
	File() (*os.File, error)
	LocalAddr() Addr
	MultipathTCP() (bool, error)
	Read(b []byte) (int, error)
	ReadFrom(r io.Reader) (int64, error)
	RemoteAddr() Addr
	SetDeadline(t time.Time) error
	SetKeepAlive(keepalive bool) error
	SetKeepAliveConfig(config KeepAliveConfig) error
	SetKeepAlivePeriod(d time.Duration) error
	SetLinger(sec int) error
	SetNoDelay(noDelay bool) error
	SetReadBuffer(bytes int) error
	SetReadDeadline(t time.Time) error
	SetWriteBuffer(bytes int) error
	SetWriteDeadline(t time.Time) error
	SyscallConn() (syscall.RawConn, error)
	Write(b []byte) (int, error)
	WriteTo(w io.Writer) (int64, error)
}

type TCPListener

type TCPListener interface {
	Accept() (Conn, error)
	AcceptTCP() (TCPConn, error)
	Addr() Addr
	Close() error
	File() (*os.File, error)
	SetDeadline(t time.Time) error
	SyscallConn() (syscall.RawConn, error)
}

type UDPAddr

type UDPAddr = net.UDPAddr

type UDPConn

type UDPConn interface {
	Close() error
	File() (*os.File, error)
	LocalAddr() Addr
	Read(b []byte) (int, error)
	ReadFrom(b []byte) (int, Addr, error)
	ReadFromUDP(b []byte) (int, *UDPAddr, error)
	ReadFromUDPAddrPort(b []byte) (int, netip.AddrPort, error)
	ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *UDPAddr, err error)
	ReadMsgUDPAddrPort(b, oob []byte) (n, oobn, flags int, addr netip.AddrPort, err error)
	RemoteAddr() Addr
	SetDeadline(t time.Time) error
	SetReadBuffer(bytes int) error
	SetReadDeadline(t time.Time) error
	SetWriteBuffer(bytes int) error
	SetWriteDeadline(t time.Time) error
	SyscallConn() (syscall.RawConn, error)
	Write(b []byte) (int, error)
	WriteMsgUDP(b, oob []byte, addr *UDPAddr) (n, oobn int, err error)
	WriteMsgUDPAddrPort(b, oob []byte, addr netip.AddrPort) (n, oobn int, err error)
	WriteTo(b []byte, addr Addr) (int, error)
	WriteToUDP(b []byte, addr *UDPAddr) (int, error)
	WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (int, error)
}

type UnixAddr

type UnixAddr = net.UnixAddr

type UnixConn

type UnixConn interface {
	Close() error
	CloseRead() error
	CloseWrite() error
	File() (*os.File, error)
	LocalAddr() Addr
	Read(b []byte) (int, error)
	ReadFrom(b []byte) (int, Addr, error)
	ReadFromUnix(b []byte) (int, *UnixAddr, error)
	ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err error)
	RemoteAddr() Addr
	SetDeadline(t time.Time) error
	SetReadBuffer(bytes int) error
	SetReadDeadline(t time.Time) error
	SetWriteBuffer(bytes int) error
	SetWriteDeadline(t time.Time) error
	SyscallConn() (syscall.RawConn, error)
	Write(b []byte) (int, error)
	WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err error)
	WriteTo(b []byte, addr Addr) (int, error)
	WriteToUnix(b []byte, addr *UnixAddr) (int, error)
}

type UnixListener

type UnixListener interface {
	Accept() (Conn, error)
	AcceptUnix() (UnixConn, error)
	Addr() Addr
	Close() error
	File() (*os.File, error)
	SetDeadline(t time.Time) error
	SetUnlinkOnClose(unlink bool)
	SyscallConn() (syscall.RawConn, error)
}

type UnknownNetworkError

type UnknownNetworkError = net.UnknownNetworkError

Directories

Path Synopsis
http
client
This package provides an interface to functions and structs in the standard net/http package when using it as an http client to facilitate mocking.
This package provides an interface to functions and structs in the standard net/http package when using it as an http client to facilitate mocking.
server
This package provides an interface to functions and structs in the standard net/http package used for servers to facilitate mocking.
This package provides an interface to functions and structs in the standard net/http package used for servers to facilitate mocking.

Jump to

Keyboard shortcuts

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