ipcodec

package
v0.0.0-...-6169d9b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Key prefixes for LevelDB
	PrefixRangeV4 = "R4:"
	PrefixRangeV6 = "R6:"
	PrefixMeta    = "meta:"
	PrefixCache   = "cache:"
)

Variables

This section is empty.

Functions

func BytesToIP

func BytesToIP(b []byte) (netip.Addr, error)

BytesToIP converts big-endian bytes to an IP address

func CIDRToRange

func CIDRToRange(cidr string) (start, end netip.Addr, err error)

CIDRToRange converts a CIDR string to start and end IP addresses

func CacheKey

func CacheKey(category, key string) []byte

CacheKey creates a cache key

func CompareIPs

func CompareIPs(a, b netip.Addr) int

CompareIPs compares two IP addresses (-1 if a < b, 0 if a == b, 1 if a > b)

func DecodeRangeKey

func DecodeRangeKey(key []byte) (netip.Addr, error)

DecodeRangeKey extracts the IP address from a range key

func EncodeRangeKey

func EncodeRangeKey(ip netip.Addr) []byte

EncodeRangeKey creates a LevelDB key for an IP range start Format: "R4:" + 4-byte big-endian IP (IPv4) or "R6:" + 16-byte big-endian IP (IPv6)

func IPNetToPrefix

func IPNetToPrefix(ipnet *net.IPNet) (netip.Prefix, error)

IPNetToPrefix converts net.IPNet to netip.Prefix

func IPToBytes

func IPToBytes(ip netip.Addr) []byte

IPToBytes converts an IP address to big-endian bytes

func IPv4ToInt32

func IPv4ToInt32(ip netip.Addr) uint32

IPv4ToInt32 converts an IPv4 address to uint32

func Int32ToIPv4

func Int32ToIPv4(n uint32) netip.Addr

Int32ToIPv4 converts a uint32 to an IPv4 address

func IsInRange

func IsInRange(ip, start, end netip.Addr) bool

IsInRange checks if an IP is within a range [start, end] inclusive

func MetaKey

func MetaKey(suffix string) []byte

MetaKey creates a metadata key

func NormalizePrefix

func NormalizePrefix(cidr string) (string, error)

NormalizePrefix normalizes a CIDR prefix string

func ParseIP

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

ParseIP parses an IP address string

func PrefixToIPNet

func PrefixToIPNet(prefix netip.Prefix) *net.IPNet

PrefixToIPNet converts netip.Prefix to net.IPNet

func RepresentativeIP

func RepresentativeIP(cidr string) (netip.Addr, error)

RepresentativeIP returns the first usable IP in a CIDR range For use with RDAP queries (typically the first IP)

Types

This section is empty.

Jump to

Keyboard shortcuts

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