netutils

package
v0.0.0-...-648dfe1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package netutils provides network utility functions for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectTCP

func ConnectTCP(ctx context.Context, ip net.IP, port int, ipv6 bool) error

ConnectTCP connects to the given IP and port from an ephemeral local address.

func FilterAddrs

func FilterAddrs(addrs []string, ipv6 bool) []string

FilterAddrs filters a list of IP addresses and returns only IPv4 or IPv6 addresses.

func GetInterfaceAddrs

func GetInterfaceAddrs(ipv6 bool) ([]net.IP, error)

GetInterfaceAddrs returns a list of IP addresses for the non-loopback interface. When ipv6 is true, only IPv6 addresses are returned.

func GetInterfaceName

func GetInterfaceName() (string, bool)

GetInterfaceName returns the name of the interface other than loopback.

func GetNonLoopbackInterface

func GetNonLoopbackInterface() (net.Interface, bool)

GetNonLoopbackInterface returns a non-loopback interface.

func Htons

func Htons(x uint16) uint16

Htons converts a uint16 from host byte order to network byte order.

func ListenTCP

func ListenTCP(ctx context.Context, port int, ipv6 bool) error

ListenTCP listens for connections on a TCP port, and returns nil if a connection is established.

func ListenTCPFrom

func ListenTCPFrom(ctx context.Context, port int, ipv6 bool) (net.Addr, error)

ListenTCPFrom listens for connections on a TCP port, and returns the remote TCP address if a connection is established.

func ListenUDP

func ListenUDP(ctx context.Context, port int, ipv6 bool) error

ListenUDP listens on a UDP port and returns nil if the first read from that port is successful.

func ListenUDPFrom

func ListenUDPFrom(ctx context.Context, port int, ipv6 bool) (*net.UDPAddr, error)

ListenUDPFrom listens on a UDP port and returns the sender's UDP address if the first read from that port is successful.

func LocalAddrs

func LocalAddrs(ipv6 bool) ([]string, error)

LocalAddrs returns a list of local network interface addresses. When ipv6 is true, only IPv6 addresses are returned. Otherwise only IPv4 addresses are returned.

func LocalIP

func LocalIP(ipv6 bool) string

LocalIP returns the local IP address.

func NowhereIP

func NowhereIP(ipv6 bool) string

NowhereIP returns an IP address that should not be routable.

func SendUDPLoop

func SendUDPLoop(ctx context.Context, ip net.IP, port int, ipv6 bool) error

SendUDPLoop sends 1 byte UDP packets repeatedly to the IP and port specified over a duration.

func TCPNetwork

func TCPNetwork(ipv6 bool) string

TCPNetwork returns an IPv6 or IPv6 TCP network argument to net.Dial.

func UDPNetwork

func UDPNetwork(ipv6 bool) string

UDPNetwork returns an IPv6 or IPv6 UDP network argument to net.Dial.

Types

This section is empty.

Jump to

Keyboard shortcuts

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