range2cidr

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 4 Imported by: 1

README

range2cidr

GoDoc

Aggregate() merges a list of IP ranges into a minimal set of covering ranges.

Deaggregate() breaks a single IP range into a list of covering network prefixes.

A number of address helper functions are exposed for convenience.

This library usually operates on addresses as [16]byte values, as returned by netip.Addr.As16().

To convert a netip.Addr into [16]byte:

addr.As16()

To unmap an address back into IPv4 format:

if addr.Is4In6() {
	return addr.Unmap()
}

The last step is crucial if you want results in v4 format instead of 4in6.

Documentation

Overview

Aggregate() merges a list of IP ranges into a minimal set of covering ranges.

Deaggregate() breaks a single IP range into a list of covering network prefixes.

A number of address helper functions are exposed for convenience.

This library usually operates on addresses as [16]byte values, as returned by netip.Addr.As16().

To convert a netip.Addr into [16]byte:

addr.As16()

To unmap an address back into IPv4 format:

if addr.Is4In6() {
	return addr.Unmap()
}

The last step is crucial if you want results in v4 format instead of 4in6.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add added in v0.0.2

func Add(a, b *[16]byte) (ret [16]byte, carry int)

returns sum of a and b, and carry bit.

func Cmp added in v0.0.2

func Cmp(a, b *[16]byte) int

compare two IPs. the result will be 0 if (a == b), -1 if (a < b), and +1 if (a > b).

func GetBit added in v0.0.2

func GetBit(a *[16]byte, n uint) bool

get n-th bit in a. returns true if set, false if not.

func SetBit added in v0.0.2

func SetBit(a *[16]byte, n uint, bSet bool)

set/clear n-th bit in a.

func ToBig

func ToBig(addr netip.Addr) *big.Int

func Uint32ToV4

func Uint32ToV4(n32 uint32) netip.Addr

func V4ToUint32

func V4ToUint32(ipaddr netip.Addr) (uint32, bool)

Types

type Range added in v0.0.2

type Range struct {
	A, Z [16]byte
}

func Aggregate added in v0.0.2

func Aggregate(sR []Range) []Range

aggregate (merge) adjacent and contained ranges.

NOTE: mutates sR.

func RangeFromAddrs added in v0.0.2

func RangeFromAddrs(first, last netip.Addr) Range

convert first, last addresses to a Range struct

func RangeFromPrefix added in v0.0.2

func RangeFromPrefix(pfx netip.Prefix) Range

convert network prefix to a Range struct

func (Range) Deaggregate added in v0.0.2

func (v Range) Deaggregate() []netip.Prefix

de-aggregate a range of IP addresses into a list of covering network prefixes.

func (*Range) Normalize added in v0.0.3

func (v *Range) Normalize()

sort range to ensure that A <= Z.

Jump to

Keyboard shortcuts

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