netkit

package
v0.296.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFreePort

func GetFreePort() (int, error)

GetFreePort opens a TCP listener on a randomly selected available port. It returns the listener and the selected port number.

func IsPortFree

func IsPortFree(network Network, port int) (ok bool, returnErr error)

IsPortFree checks if a given TCP port is free to bind to. It takes into account specifics of

MacOS behavior where multiple IP versions (IPv4 and IPv6) may be bound to the same port, which can lead to false positives in port availability checking. IsPortFree able to work this around by checking both ip versions for the port, to give a unified behaviour across different platforms.

If you wish to check both TCP and UDP networks, then give a zero value to the Network argument.

Types

type Network added in v0.175.0

type Network string
const (
	TCP  Network = "tcp"
	TCP4 Network = "tcp4"
	TCP6 Network = "tcp6"
)
const (
	UDP  Network = "udp"
	UDP4 Network = "udp4"
	UDP6 Network = "udp6"
)

Jump to

Keyboard shortcuts

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