cidr

package
v0.0.11-alpha Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

RFC-4632 Classless Inter-domain Routing notation handling https://www.rfc-editor.org/rfc/rfc4632

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse[A ip.Address[A]](f ip.Family[A], notation string) (network.Block[A], error)

Parses CIDR notation

Example
reservedForDocumentation, _ := cidr.Parse(ip.V6(), "2001:db8::/32")
printRangeDetails(reservedForDocumentation)
Output:

func ParseUnknown

func ParseUnknown(notation string) (any, error)

Parses CIDR notation where IP address family is unknown. Returns error if operand is not valid CIDR notation. Returns network.Block when oprand is valid.

Example
reservedForDocumentation := []string{
	"192.0.2.0/24",
	"198.51.100.0/24",
	"203.0.113.0/24",
	"2001:db8::/32",
}
for _, notation := range reservedForDocumentation {
	block, err := cidr.ParseUnknown(notation)
	if err != nil {
		panic(err)
	}
	switch addresses := block.(type) {
	case network.Block[ip.Addr4]:
		printRangeDetails(addresses)
	case network.Block[ip.Addr6]:
		printRangeDetails(addresses)
	}
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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