/extnetip

Package extnetip extends the stdlib with a few missing but important auxiliary functions for converting IP-prefixes to IP-ranges and vice versa.

Primary LanguageGoMIT LicenseMIT

package extnetip

Go Reference GitHub release (latest SemVer) CI Go Report Card Coverage Status License: MIT Stand With Ukraine

Package extnetip is an extension to net/netip with a few missing but important auxiliary functions for converting IP-prefixes to IP-ranges and vice versa.

With these extensions to net/netip, third-party IP-range libraries become easily possible.

API

import "github.com/gaissmai/extnetip"

func Range(p netip.Prefix) (first, last netip.Addr)
func Prefix(first, last netip.Addr) (prefix netip.Prefix, ok bool)
func All(first, last netip.Addr) iter.Seq[netip.Prefix]

// Deprecated: func Prefixes(first, last netip.Addr) []netip.Prefix
// Deprecated: func PrefixesAppend(dst []netip.Prefix, first, last netip.Addr) []netip.Prefix

Future

Hopefully some day these needed helper functions are added to netip by the stdlib maintainers.