netutil

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

package netutil provides common utility functions for networking.

Index

Constants

View Source
const (
	// DefaultULABits are the default bits used for the IPv6 address
	// space of the network.
	DefaultULABits = 48
	// DefaultNodeBits are the default bits used for the IPv6 address
	// space of each node.
	DefaultNodeBits = 112
)

Variables

This section is empty.

Functions

func AssignToPrefix

func AssignToPrefix(prefix netip.Prefix, publicKey crypto.PublicKey) netip.Prefix

AssignToPrefix assigns a /112 prefix within a /48 prefix using a public key. It does not check that the given prefix is a valid /48 prefix.

func GenerateULA

func GenerateULA() (netip.Prefix, error)

GenerateULA generates a unique local address with a /48 prefix according to RFC 4193. The network is returned as a netip.Prefix.

func GenerateULAWithKey

func GenerateULAWithKey(key crypto.PublicKey) (netip.Prefix, netip.Addr)

GenerateULAWithKey generates a unique local address with a /48 prefix using the key bytes as a seed. The network is returned as a netip.Prefix. It then computes another /112 prefix for the given public key's wireguard key. It returns the /112 prefix as the first /128 address within it.

func GenerateULAWithSeed

func GenerateULAWithSeed(psk []byte) netip.Prefix

GenerateULAWithSeed generates a unique local address with a /48 prefix using a seed value. The network is returned as a netip.Prefix.

func ParsePortRange

func ParsePortRange(s string) (start int, end int, err error)

ParsePortRange parses a port range string.

func Ping

func Ping(ctx context.Context, addr netip.Addr) error

Ping sends ICMP echo requests to the given address. The context must have a timeout set and is used for the duration of the ping. The function returns an error if no replies were received.

func ResolveTCPAddr

func ResolveTCPAddr(ctx context.Context, lookup string, maxRetries int) (net.Addr, error)

ResolveTCPAddr resolves a TCP address with retries and context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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