netutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrivate

func IsPrivate(ip netip.Addr) bool

Whether the address lies in a block the IANA special-purpose registries mark not globally reachable (RFC 1918, unique local, loopback, link local, this network, protocol assignments, documentation, benchmarking, 6a44 relay, 6to4, Teredo, local NAT64, discard, dummy prefix, SRv6, reserved and broadcast space), the IPv6 protocol assignments block 2001::/23 counted whole apart from its PCP, TURN, AMT, AS112, ORCHIDv2 and drone ID entries; an IPv4-mapped address, and one in the NAT64 well-known prefix 64:ff9b::/96 or the IPv4-translated prefix ::ffff:0:0:0/96, is judged by the IPv4 address it reaches, a zone is ignored, shared space 100.64.0.0/10 is left to IsShared

func IsReserved

func IsReserved(ip netip.Addr) bool

Whether the address lies in space the IETF holds in reserve: IPv4 240.0.0.0/4 with the broadcast address, IPv6 outside global unicast 2000::/3, unique local, link local, site local and multicast space; an IPv4-mapped address is judged by its IPv4 address

func IsShared

func IsShared(ip netip.Addr) bool

Whether the address lies in the shared address space 100.64.0.0/10 of carrier-grade NAT, an IPv4-mapped, NAT64 well-known prefix or IPv4-translated address judged by the IPv4 address it reaches

func ParseLenientIPv4

func ParseLenientIPv4(s string) (netip.Addr, error)

IPv4 address of a numeric host in the lenient spellings name resolvers and browsers accept: one to four dot separated parts, each decimal, octal after a leading 0 or hex after 0x, the last part filling the bytes left; the C library form may be followed by whitespace and anything after it, the browser form may end in one dot and write zero as a bare 0x

func ParseNetwork

func ParseNetwork(s string) (netip.Prefix, error)

Network of an address with an optional /length, for IPv4 also a dotted /netmask or /hostmask, a bare address standing for itself alone; leading zeros in the length are accepted, host bits cleared and an IPv6 zone dropped

Types

type ParseError

type ParseError struct {
	Input  string
	Reason string
}

Error of text that names no address or network, carrying the text and what is wrong with it

func (*ParseError) Error

func (e *ParseError) Error() string

The quoted input followed by the reason

Jump to

Keyboard shortcuts

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