net

package module
v0.4.0 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: 11

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 FilterIPs

func FilterIPs(ips []netip.Addr, cidrs []string) ([]netip.Addr, 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 netip.Addr, network netip.Prefix) string

FormatCIDR formats IP from the network as CIDR notation.

func NthIPInCIDRSet

func NthIPInCIDRSet(cidrList []netip.Prefix, offset int) (out []netip.Addr, err error)

NthIPInCIDRSet returns nth IP for each CIDR in the list.

func NthIPInNetwork

func NthIPInNetwork(network netip.Prefix, n int) (netip.Addr, error)

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

func ParseSubnetOrAddress added in v0.4.0

func ParseSubnetOrAddress(subnet string) (netip.Prefix, error)

ParseSubnetOrAddress parses a CIDR or an IP address, returning a netip.Prefix.

If a bare IP address is passed, it's treated as a CIDR with either /32 or /128 prefix.

func SplitCIDRs

func SplitCIDRs(cidrList string) (out []netip.Prefix, 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

This section is empty.

Jump to

Keyboard shortcuts

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