Help us shape the future of Go! Take the 2026 Go Developer Survey

net

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MPL-2.0 Imports: 7 Imported by: 17

README

github.com/siderolabs/net

PkgGoDev

Package github.com/siderolabs/net provides functions extending standard library package net.

Documentation

Overview

Package net provides functions extending standard library package `net`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressContainsPort

func AddressContainsPort(addr string) bool

AddressContainsPort checks to see if the supplied address contains both an address and a port. This will not catch every possible permutation, but it is a best-effort routine suitable for prechecking human-interactive parameters.

func DNSNames

func DNSNames() (dnsNames []string, err error)

DNSNames returns a default set of machine names. It includes the hostname, and FQDN if the kernel domain name is set. If the kernel domain name is not set, only the hostname is included in the set.

func DomainName

func DomainName() (domainname string, err error)

DomainName returns the kernel domain name. If a domain name is not found, an empty string is returned.

func FilterIPs

func FilterIPs(ips []net.IP, cidrs []string) ([]net.IP, error)

FilterIPs filters list of IPs with the list of subnets.

Each subnet can be either regular match or negative match (if prefixed with '!').

func FormatAddress

func FormatAddress(addr string) string

FormatAddress checks that the address has a consistent format.

func FormatCIDR

func FormatCIDR(ip net.IP, network net.IPNet) string

FormatCIDR formats IP from the network as CIDR notation.

func IPAddrs

func IPAddrs() (ips []net.IP, err error)

IPAddrs finds and returns a list of non-loopback IP addresses of the current machine.

func IPFilter

func IPFilter(addrs []net.IP, filters ...IPFilterFunc) (result []net.IP)

IPFilter filters list of IP addresses by applying sequence of filters.

If any of the filters returns false, address is skipped.

func IsIPv6

func IsIPv6(addrs ...net.IP) bool

IsIPv6 indicates whether any IP address within the provided set is an IPv6 address.

func IsNonLocalIPv6

func IsNonLocalIPv6(in net.IP) bool

IsNonLocalIPv6 indicates whether provided address is non-local IPv6 address.

func NthIPInCIDRSet

func NthIPInCIDRSet(cidrList []*net.IPNet, offset int) (out []net.IP, err error)

NthIPInCIDRSet returns nth IP for each CIDR in the list.

func NthIPInNetwork

func NthIPInNetwork(network *net.IPNet, n int) (net.IP, error)

NthIPInNetwork takes an IPNet and returns the nth IP in it.

func ParseCIDR

func ParseCIDR(in string) (*net.IPNet, error)

ParseCIDR parses a CIDR-formatted IP address. Unlike the standard library version, this will return the IP address itself, rather than the bare IP and the network address. If no CIDR notation is supplied, the address is presumed to be on a solo network (/32 for IPv4 or /128 for IPv6). NOTE: Unlike rtnl.ParseCIDR, this allows network addresses, since in many places in the kubernetes ecosystem, the functionality of a "network address" is not used and improperly prevents the use of an entire range of IP addresses.

func SplitCIDRs

func SplitCIDRs(cidrList string) (out []*net.IPNet, err error)

SplitCIDRs parses list of CIDRs in a string separated by commas.

func ValidateEndpointURI

func ValidateEndpointURI(ep string) error

ValidateEndpointURI checks that an endpoint is valid. This is a more strict check that merely `url.Parse`, in that it requires such things as properly-ranged numeric ports and bracket-enclosed IPv6 addresses.

Types

type IPFilterFunc

type IPFilterFunc func(ip net.IP) bool

IPFilterFunc filters IP addresses.

List of IPFilterFuncs is applied with AND logic: all filters should return true for the IP address to be included in the response.

Jump to

Keyboard shortcuts

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