networking

package
v0.22.10 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IpVersionPreferenceNone IpVersionPreference = "None"
	IpVersionPreference4    IpVersionPreference = "IPv4"
	IpVersionPreference6    IpVersionPreference = "IPv6"

	Localhost                   = "localhost"
	IPv4LocalhostDefaultAddress = "127.0.0.1"
	IPv6LocalhostDefaultAddress = "[::1]"
	IPv4AllInterfaceAddress     = "0.0.0.0" // Equivalent to net.IPv4zero
	IPv6AllInterfaceAddress     = "[::]"    // Equivalent to net.IPv6zero

	InvalidPort = 0

	// Use a relatively short timeout for network operations such as IP lookup or socket open
	// because we are only interested in local addresses and ports, so the operation should be fast.
	NetworkOpTimeout = 2 * time.Second

	DCP_INSTANCE_ID_PREFIX = "DCP_INSTANCE_ID_PREFIX"
)
View Source
const (
	// Default ephemeral port range on Linux is 32768-60999.
	DefaultEphemeralPortRangeStart = 32768
	DefaultEphemeralPortRangeEnd   = 60999
)

Variables

This section is empty.

Functions

func AddressAndPort

func AddressAndPort(address string, port int32) string

func CheckPortAvailable

func CheckPortAvailable(protocol apiv1.PortProtocol, address string, port int32, log logr.Logger) error

func EnableStrictMruPortHandling

func EnableStrictMruPortHandling(log logr.Logger)

Used by tests, makes the use of the most recently used ports file mandatory

func GetEphemeralPortRange

func GetEphemeralPortRange() (int, int, bool)

func GetFreePort

func GetFreePort(protocol apiv1.PortProtocol, address string, log logr.Logger) (int32, error)

Gets a free TCP or UDP port for a given address (defaults to localhost). Even if this method is called twice in a row, it should not return the same port.

func GetPreferredHostIps

func GetPreferredHostIps(host string) ([]net.IP, error)

func GetProgramInstanceID

func GetProgramInstanceID() string

func Hostname

func Hostname() (string, error)

func IpToString

func IpToString(ip net.IP) string

func IsBindablePort

func IsBindablePort(port int) bool

func IsEphemeralPort

func IsEphemeralPort(port int32) bool

func IsIPv4

func IsIPv4(address string) bool

func IsIPv6

func IsIPv6(address string) bool

func IsValidIP

func IsValidIP(ip net.IP) bool

func IsValidIPv4

func IsValidIPv4(ip net.IP) bool

func IsValidIPv6

func IsValidIPv6(ip net.IP) bool

func IsValidPort

func IsValidPort(port int) bool

func LookupIP

func LookupIP(host string) ([]net.IP, error)

Wrap the standard net.LookupIP method to filter for supported IP address types

func ToStandaloneAddress

func ToStandaloneAddress(address string) string

Removes the brackets from an IPv6 address if they are present.

Note: in most cases an IPv6 address needs to be enclosed in brackets for disambiguation (e.g. inside URLs, whenever a port number follows). This is why inside DCP we mostly stick to bracketed IPv6 addresses. But certain APIs require a standalone address, i.e. without brackets.

Types

type IpVersionPreference

type IpVersionPreference string

func GetIpVersionPreference

func GetIpVersionPreference() IpVersionPreference

Jump to

Keyboard shortcuts

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