ipnet

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ipnet contains utility functions for IPv4 and IPv6 networks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v1.14.1

func All(yield func(Type) bool)

All enumerates IP4 and then IP6.

func Bindings added in v1.14.1

func Bindings[V any](m map[Type]V) iter.Seq2[Type, V]

Bindings enumerates the key IP4 and then IP6 for a map.

func DescribePrefixOrIP added in v1.14.0

func DescribePrefixOrIP(p netip.Prefix) string

DescribePrefixOrIP is similar to netip.Prefix.String but prints out the IP directly if the input range only contains one IP.

func ParsePrefixOrIP added in v1.14.0

func ParsePrefixOrIP(ppfmt pp.PP, s string) (netip.Prefix, bool)

ParsePrefixOrIP parses a prefix or an IP.

Types

type Type

type Type int

Type is the type of IP networks.

const (
	// IP4 is IP version 4.
	IP4 Type = 4

	// IP6 is IP version 6.
	IP6 Type = 6
)

func (Type) Describe

func (t Type) Describe() string

Describe returns a human-readable description of the IP network.

func (Type) Int

func (t Type) Int() int

Int returns the version of the IP networks. It is either 4 or 6.

func (Type) Matches added in v1.14.0

func (t Type) Matches(ip netip.Addr) bool

Matches checks whether an IP belongs to it.

func (Type) NormalizeDetectedIP added in v1.8.0

func (t Type) NormalizeDetectedIP(ppfmt pp.PP, ip netip.Addr) (netip.Addr, bool)

NormalizeDetectedIP normalizes an IP into an IPv4 or IPv6 address.

func (Type) RecordType

func (t Type) RecordType() string

RecordType prints out the type of DNS records for the IP network. For IPv4, it is A; for IPv6, it is AAAA.

func (Type) UDPNetwork

func (t Type) UDPNetwork() string

UDPNetwork gives the network name for net.Dial.

Jump to

Keyboard shortcuts

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