Documentation
¶
Overview ¶
Package netutils provides network utility functions for tests.
Index ¶
- func ConnectTCP(ctx context.Context, ip net.IP, port int, ipv6 bool) error
- func FilterAddrs(addrs []string, ipv6 bool) []string
- func GetInterfaceAddrs(ipv6 bool) ([]net.IP, error)
- func GetInterfaceName() (string, bool)
- func GetNonLoopbackInterface() (net.Interface, bool)
- func Htons(x uint16) uint16
- func ListenTCP(ctx context.Context, port int, ipv6 bool) error
- func ListenTCPFrom(ctx context.Context, port int, ipv6 bool) (net.Addr, error)
- func ListenUDP(ctx context.Context, port int, ipv6 bool) error
- func ListenUDPFrom(ctx context.Context, port int, ipv6 bool) (*net.UDPAddr, error)
- func LocalAddrs(ipv6 bool) ([]string, error)
- func LocalIP(ipv6 bool) string
- func NowhereIP(ipv6 bool) string
- func SendUDPLoop(ctx context.Context, ip net.IP, port int, ipv6 bool) error
- func TCPNetwork(ipv6 bool) string
- func UDPNetwork(ipv6 bool) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectTCP ¶
ConnectTCP connects to the given IP and port from an ephemeral local address.
func FilterAddrs ¶
FilterAddrs filters a list of IP addresses and returns only IPv4 or IPv6 addresses.
func GetInterfaceAddrs ¶
GetInterfaceAddrs returns a list of IP addresses for the non-loopback interface. When ipv6 is true, only IPv6 addresses are returned.
func GetInterfaceName ¶
GetInterfaceName returns the name of the interface other than loopback.
func GetNonLoopbackInterface ¶
GetNonLoopbackInterface returns a non-loopback interface.
func ListenTCP ¶
ListenTCP listens for connections on a TCP port, and returns nil if a connection is established.
func ListenTCPFrom ¶
ListenTCPFrom listens for connections on a TCP port, and returns the remote TCP address if a connection is established.
func ListenUDP ¶
ListenUDP listens on a UDP port and returns nil if the first read from that port is successful.
func ListenUDPFrom ¶
ListenUDPFrom listens on a UDP port and returns the sender's UDP address if the first read from that port is successful.
func LocalAddrs ¶
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 SendUDPLoop ¶
SendUDPLoop sends 1 byte UDP packets repeatedly to the IP and port specified over a duration.
func TCPNetwork ¶
TCPNetwork returns an IPv6 or IPv6 TCP network argument to net.Dial.
func UDPNetwork ¶
UDPNetwork returns an IPv6 or IPv6 UDP network argument to net.Dial.
Types ¶
This section is empty.