ip

package module
v0.0.0-...-0b0b0e4 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

ip is an extension of net/netip that handles IP/Prefix addresses as one Addr value despite notation and IP version (v4/v6) differences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr

type Addr struct {
	// contains filtered or unexported fields
}

Addr contains IP/CIDR addresses.

func Invalid

func Invalid() Addr

Invalid returns an invalid Addr.

func MustParse

func MustParse(addr string) Addr

MustParse returns an invalid Addr if addr input is invalid.

func Parse

func Parse(addr string) (Addr, error)

Parse creates Addr values of a string.

func UnspecifiedIPv4

func UnspecifiedIPv4() Addr

UnspecifiedIPv4 returns an unspecified IPv4 Addr.

func UnspecifiedIPv6

func UnspecifiedIPv6() Addr

UnspecifiedIPv6 returns an unspecified IPv6 Addr.

func (Addr) Addr

func (a Addr) Addr() string

Addr returns the network address or single IP value as string.

Format: ip[%zone]

func (Addr) Bits

func (a Addr) Bits() int

Bits returns the CIDR mask value as int.

func (Addr) CIDR

func (a Addr) CIDR() string

CIDR returns the CIDR value as string.

Format: ip/cidr

func (Addr) IP

func (a Addr) IP() netip.Addr

IP returns the network address or single IP value as netip.Addr.

func (Addr) Is

func (a Addr) Is() Version

Is returns the IP version of Addr as Version.

func (Addr) Is4

func (a Addr) Is4() bool

Is4 returns a boolean true if Addr is an IPv4 address.

func (Addr) Is6

func (a Addr) Is6() bool

Is6 returns a boolean true if Addr is an IPv6 address.

func (Addr) IsInverted

func (a Addr) IsInverted() bool

IsInverted returns a boolean value for Addr state.

func (Addr) IsSingle

func (a Addr) IsSingle() bool

IsSingle check if Addr is a single IP value.

func (Addr) IsUnspecified

func (a Addr) IsUnspecified() bool

IsUnspecified checks if Addr is unspecified.

func (Addr) IsValid

func (a Addr) IsValid() bool

IsValid checks if Addr is valid.

func (Addr) Prefix

func (a Addr) Prefix() netip.Prefix

Prefix returns the value as netip.Prefix.

func (Addr) String

func (a Addr) String() string

String returns Addr value as string.

Format: [!]ip[%zone]/cidr

func (Addr) Zone

func (a Addr) Zone() string

Zone returns the zone value of Addr.

type Union

type Union struct {
	// contains filtered or unexported fields
}

Union combines multiple Addr values.

func New

func New(addrs ...Addr) *Union

New creates a pointer to a Union containing all Addr values given.

func (*Union) Consent

func (u *Union) Consent(a Addr) bool

Consent returns a boolean of true if the given Addr is not specifically excluded, but included in that Union.

This is not a policy based allow-/blocklist order. It returns false for everything not explicitly included. Priority is set on excludes, not on positions. If you add !0.0.0.0/0 you will deny all IPv4 even if you explicitly added 192.168.1.2 before.

It is an allowlist with excludes approach. Think explicitly of what you want and not want to return true. This enables you to allow 10.0.0.0/8 and deny a host !10.10.10.10 or a subnet !10.10.0.0/16.

Zone value is not part of testing.

func (*Union) Excludes

func (u *Union) Excludes() []Addr

Excludes returns all inverted Addr values (IPv4/IPv6) of that Union.

func (*Union) IPv4

func (u *Union) IPv4() []Addr

IPv4 returns all IPv4 values of that Union.

func (*Union) IPv6

func (u *Union) IPv6() []Addr

IPv6 returns all IPv6 values of that Union.

func (*Union) Includes

func (u *Union) Includes() []Addr

Includes returns all non-inverted Addr values (IPv4/IPv6) of that Union.

type Version

type Version uint8

Version (IPv4/IPv6)

const (
	Unknown Version = 0
	IPv4    Version = 4
	IPv6    Version = 6
)

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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