iputils

package
v0.1.0-latest-stable Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(addr netip.Addr, offset *big.Int) (result netip.Addr, ok bool)

Add adds a non-negative offset to an address. ok is false on invalid input or family overflow.

func Distance

func Distance(start, end netip.Addr) (distance *big.Int, ok bool)

Distance returns end-start. ok is false for mixed families or end before start.

func ParseAddr

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

ParseAddr parses an IPv4 or IPv6 address. IPv4-mapped IPv6 representations are rejected so callers cannot accidentally change address families through netip.Addr.Unmap.

func PrefixAddressCount

func PrefixAddressCount(addressBits, prefixLen int) *big.Int

PrefixAddressCount returns the number of IP addresses in a prefix.

Types

type IPRange

type IPRange struct {
	Start netip.Addr
	End   netip.Addr
}

IPRange is the internal representation of a contiguous IPv4 or IPv6 address range. Start and End must always belong to the same address family.

func ExcludeRanges

func ExcludeRanges(parent IPRange, allocated []IPRange) []IPRange

ExcludeRanges returns all sub-ranges of parent that are not covered by any range in allocated.

func MergeRanges

func MergeRanges(ranges []IPRange) []IPRange

MergeRanges merges overlapping/adjacent IP ranges into a minimal set. Mixed families remain separate.

func RangeFromPrefix

func RangeFromPrefix(prefix netip.Prefix) (IPRange, error)

RangeFromPrefix returns the inclusive address range covered by prefix.

func SortRanges

func SortRanges(ranges []IPRange) []IPRange

SortRanges returns a copy of the ranges sorted by family, start address, then end address.

func SubtractRange

func SubtractRange(ranges []IPRange, sub IPRange) []IPRange

SubtractRange returns ranges with sub removed, splitting any overlapping range around it.

func (IPRange) In

func (r IPRange) In(other IPRange) bool

In reports whether r is fully contained within other.

func (IPRange) InAny

func (r IPRange) InAny(ranges []IPRange) bool

InAny reports whether r is fully contained within any of the given ranges.

func (IPRange) Overlaps

func (r IPRange) Overlaps(other IPRange) bool

Overlaps reports whether r shares at least one IP with other.

Jump to

Keyboard shortcuts

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