iputil

package
v2.32.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4BitSize = 32
	IPv6BitSize = 128

	IPv4DefaultMaskingBitSize = 24
	IPv6DefaultMaskingBitSize = 56
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IPValidator

type IPValidator interface {
	// IsValid returns true when an IP address is determined to be valid.
	IsValid(net.IP, IPVersion) bool
}

IPValidator is the interface for validating an ip address and version.

type IPVersion

type IPVersion int

IPVersion is the numerical version of the IP address spec (4 or 6).

const (
	IPvUnknown IPVersion = 0
	IPv4       IPVersion = 4
	IPv6       IPVersion = 6
)

IP address versions.

func ParseIP

func ParseIP(v string) (net.IP, IPVersion)

ParseIP parses v as an ip address returning the result and version, or nil and unknown if invalid.

type PublicNetworkIPValidator

type PublicNetworkIPValidator struct {
	IPv4PrivateNetworks []net.IPNet
	IPv6PrivateNetworks []net.IPNet
}

PublicNetworkIPValidator validates an ip address which is not contained in the list of known private networks.

func (PublicNetworkIPValidator) IsValid

func (v PublicNetworkIPValidator) IsValid(ip net.IP, ver IPVersion) bool

IsValid implements the IPValidator interface.

type VersionIPValidator

type VersionIPValidator struct {
	Version IPVersion
}

VersionIPValidator validates an ip address based on the desired ip version.

func (VersionIPValidator) IsValid

func (v VersionIPValidator) IsValid(ip net.IP, ver IPVersion) bool

IsValid implements the IPValidator interface.

Jump to

Keyboard shortcuts

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