ipaddr

package
v0.7.1 Latest Latest
Warning

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

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

Documentation

Overview

Package ipaddr provides typed IP / CIDR helper functions for SQL queries. Pure Go via net/netip; no external dependencies.

Functions

  • ipcontains(prefix, ip) → BOOL: true if prefix contains ip
  • ipoverlaps(prefix1, prefix2) → BOOL: true if the two prefixes overlap
  • ipfamily(ip-or-prefix) → INTEGER (4 or 6)
  • iphost(ip-or-prefix) → TEXT: canonical address form
  • ipmasklen(prefix) → INTEGER: prefix bit count
  • ipnetwork(prefix) → TEXT: the prefix's masked network address

Ported from ncruces/ext/ipaddr with one upstream bug fix: ipoverlaps in ncruces parses arg[0] twice (lines 50-51 of upstream ipaddr.go), effectively comparing prefix1 to itself. Our version reads each prefix from its own argument, matching the function's documented semantics.

Usage

import (
    sqlite "gosqlite.org"
    "gosqlite.org/ext/ipaddr"
)

if err := ipaddr.Register(conn); err != nil { ... }

rows, _ := db.QueryContext(ctx,
    `SELECT ip FROM events WHERE ipcontains('10.0.0.0/8', ip)`)

For pool-wide install via [gosqlite.org.Driver.ConnectHook], blank-import the auto sub-package:

import _ "gosqlite.org/ext/ipaddr/auto"

Index

Constants

View Source
const (
	FuncIPContains = "ipcontains"
	FuncIPOverlaps = "ipoverlaps"
	FuncIPFamily   = "ipfamily"
	FuncIPHost     = "iphost"
	FuncIPMaskLen  = "ipmasklen"
	FuncIPNetwork  = "ipnetwork"
)

Exported names of the SQL functions Register installs.

Variables

This section is empty.

Functions

func Register

func Register(c *sqlite.Conn) error

Register installs all six functions on c.

Types

This section is empty.

Directories

Path Synopsis
Package auto wires the ipaddr extension via a sqlite.Driver.ConnectHook so every new connection registers the IP / CIDR helpers.
Package auto wires the ipaddr extension via a sqlite.Driver.ConnectHook so every new connection registers the IP / CIDR helpers.

Jump to

Keyboard shortcuts

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