network

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package network provides IP address and network utilities for MMDB processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPv4ToUint32

func IPv4ToUint32(addr netip.Addr) uint32

IPv4ToUint32 converts an IPv4 address to uint32.

func IPv6BucketToInt64 added in v0.2.0

func IPv6BucketToInt64(addr netip.Addr) (int64, error)

IPv6BucketToInt64 converts the first 60 bits of an IPv6 address to int64.

NOTE: The address must already be masked to the appropriate bucket (i.e., if you have a bucket size of /16, you must provide 2001:: as opposed to something like 2001:abcd::).

We use 60 bits (not 64) because 60-bit values always fit in a positive int64, which simplifies queries (no two's complement handling needed).

We use 60 bits in particular as that is what 15 hex characters provides. This is already more bits than we'd typically need.

In BigQuery, you can compute the same value using:

CAST(CONCAT('0x', SUBSTR(
  TO_HEX(NET.IP_TRUNC(NET.IP_FROM_STRING(ip), bucket_size)), 1, 15
)) AS INT64)

where bucket_size is the prefix length used for bucketing.

func IsAdjacent

func IsAdjacent(endIP, startIP netip.Addr) bool

IsAdjacent checks if two IP addresses are consecutive (no gap between them).

func SmallestNetwork

func SmallestNetwork(a, b netip.Prefix) netip.Prefix

SmallestNetwork returns the smaller (more specific) of two overlapping network prefixes.

func SplitPrefix added in v0.2.0

func SplitPrefix(prefix netip.Prefix, prefixSize int) ([]netip.Prefix, error)

SplitPrefix splits a prefix into multiple prefixes of the desired size. If the prefix is already the requested size or smaller, it is returned as-is.

Types

This section is empty.

Jump to

Keyboard shortcuts

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