netutil

package
v1.8.70 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 19 Imported by: 6

Documentation

Overview

Utilities for working with networks and network accessories.

Utilities for working with networks and network accessories.

Index

Constants

This section is empty.

Variables

View Source
var DefaultWaitForOpenConnectionTimeout = 5 * time.Second
View Source
var WaitForOpenCheckInterval = time.Second
View Source
var WaitForPingCheckInterval = time.Second
View Source
var WaitForPingReply = 5 * time.Second

Functions

func DefaultGateway added in v1.6.12

func DefaultGateway() (net.IP, error)

Retrieves the default gateway interface.

func EphemeralPort added in v1.5.56

func EphemeralPort() (int, error)

Retrieve an open ephemeral port.

func ExpandPort added in v1.5.57

func ExpandPort(address string) string

Takes an address in the form of "host:port", looks for port zero (e.g: ":0"), and gets an ephemeral local port and returns that address (e.g.: ":41327").

func FQDN added in v1.7.37

func FQDN() string

Return the current machine's Fully-qualified domain name,

func HasRoutableIP added in v1.6.9

func HasRoutableIP(network string, ifi *net.Interface) (net.IP, bool)

Returns the first routable address on the given interface.

func IsMulticastCapable added in v1.6.9

func IsMulticastCapable(network string, ifi *net.Interface) (net.IP, bool)

IsMulticastCapable reports whether ifi is an IP multicast-capable network interface. Network must be "ip", "ip4" or "ip6".

func IsRoutableIP added in v1.6.9

func IsRoutableIP(network string, ip net.IP) net.IP

Returns true when the given address is unicast routable beyond the current machine.

func OnePingOnly added in v1.8.12

func OnePingOnly(dest net.IP, source *IPAddress, timeout time.Duration) error

Send a single ICMP ECHO request packet to the given address on the given interface and wait for up to timeout for a reply.

func RoutedInterface added in v1.6.9

func RoutedInterface(network string, flags net.Flags) *net.Interface

RoutedInterface returns a network interface that can route IP traffic and satisfies flags. It returns nil when an appropriate network interface is not found. Network must be "ip", "ip4" or "ip6".

func WaitForGatewayPing added in v1.8.12

func WaitForGatewayPing(totaltime time.Duration) error

Like WaitForPing, but will identify the default gateway and ping that address.

func WaitForGatewayPing6 added in v1.8.12

func WaitForGatewayPing6(totaltime time.Duration) error

Like WaitForGatewayPing, but specifically pings an IPv6 gateway

func WaitForOpen

func WaitForOpen(network string, address string, totaltime time.Duration, timeouts ...time.Duration) error

Periodically attempts to open a TCP socket to the given address, up to totaltime. Returns nil if the socket was opened successfully (which will then immediately be closed), or an error if the function timed out. The check interval can be configured using the WaitForOpenCheckInterval package variable.

func WaitForPing added in v1.8.12

func WaitForPing(addr interface{}, totaltime time.Duration) error

Periodically attempts to send an ICMP ECHO request (a "ping") to the given IP address, up to totaltime. Returns nil if an ECHO reply was received, or an error if the function timed out. The check interval can be configured using the WaitForPingCheckInterval package variable.

func ZeroconfDiscover added in v1.7.33

func ZeroconfDiscover(options *ZeroconfOptions, fn ServiceFunc) error

Perform Multicast DNS discovery on the local network, calling the fn callback for each discovered service.

func ZeroconfRegister added in v1.7.33

func ZeroconfRegister(svc *Service) (string, error)

Register the given service in Multicast DNS. Returns an ID that can be used to unregister the service later.

func ZeroconfUnregister added in v1.7.33

func ZeroconfUnregister(id string)

Unregister a previously-registered service.

func ZeroconfUnregisterAll added in v1.7.33

func ZeroconfUnregisterAll()

Unregister all Multicast DNS services.

Types

type IPAddress added in v1.6.12

type IPAddress struct {
	IP        net.IP
	Mask      net.IPMask
	Interface net.Interface
	Gateway   net.IP
}

func DefaultAddress added in v1.6.12

func DefaultAddress() *IPAddress

Retrieves the first routable IP address on any interface that falls inside of the system's default gateway network. Will return nil if no IP could be found.

func DefaultAddress6 added in v1.8.12

func DefaultAddress6() *IPAddress

Like DefaultAddress, but specifically filters on IPv6 addresses. If no routable IPv6 address is found, returns nil.

func GetRoutableAddresses added in v1.8.12

func GetRoutableAddresses(gateway net.IP, iface *net.Interface) ([]*IPAddress, error)

Returns all addresses on the given interface that can route to the given gateway. If gateway is nil, the default gateway will be attempted.

func RoutableAddresses added in v1.6.12

func RoutableAddresses() ([]*IPAddress, error)

Return a list of routable IP addresses, along with their associated gateways and interfaces.

type Service added in v1.7.33

type Service struct {
	Hostname   string          `json:"hostname"`
	Instance   string          `json:"instance"`
	Service    string          `json:"service"`
	Domain     string          `json:"domain"`
	Port       int             `json:"port"`
	Text       []string        `json:"txt"`
	Address    string          `json:"address"`
	Addresses  []net.IP        `json:"addresses,omitempty"`
	Interfaces []net.Interface `json:"interfaces,omitempty"`
}

func (*Service) String added in v1.7.33

func (self *Service) String() string

type ServiceFunc added in v1.7.33

type ServiceFunc func(*Service) bool

type ZeroconfOptions added in v1.7.33

type ZeroconfOptions struct {
	Context       context.Context
	Limit         int
	Timeout       time.Duration `default:"30s"`
	Service       string        `default:"_http._tcp"`
	Domain        string        `default:".local"`
	CheckInterval time.Duration `default:"100ms"`
	MatchInstance string
	MatchPort     string
	MatchHostname string
	MatchAddress  string
}

Jump to

Keyboard shortcuts

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