iptrie

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 3 Imported by: 0

README

iptrie

a fast ip matcher using trie

Supporting ipv4/ipv6 range, cidr
"192.168.100.2"
"192.168.10.10-192.168.20.9"
"172.16.100.1/24"
"2001:db8::68"
Example
package main

import "github.com/leetjob/iptrie"

func main() {
	ipList := []string{
		"192.168.100.2",
		"192.168.10.10-192.168.20.9",
		"172.16.100.0/24",
		"2001:db8::68",
	}

	ipTrie := NewTrie()
	for _, ip := range ipList {
		ipTrie.InsertIpAddr(NewIpAddr(ip), nil)
	}
	result := ipTrie.FindByIp(net.ParseIP("172.16.100.100"))
	fmt.Printf("result=%v", result)
}

Documentation

Index

Constants

View Source
const (
	IpaddrKindCidr = iota
	IpaddrKindRange
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IpAddr

type IpAddr struct {
	Kind  byte
	Ip    net.IP
	IpNet *net.IPNet
	Ip1   net.IP
	Ip2   net.IP
	// contains filtered or unexported fields
}

func NewIpAddr

func NewIpAddr(s string) *IpAddr

func (*IpAddr) Count

func (o *IpAddr) Count() *big.Int

func (*IpAddr) Mask

func (o *IpAddr) Mask() []byte

func (*IpAddr) String

func (o *IpAddr) String() string

type IpTrie

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

func NewTrie

func NewTrie() *IpTrie

func (*IpTrie) FindByIp

func (o *IpTrie) FindByIp(ip net.IP) bool

func (*IpTrie) FindLowestByIp

func (o *IpTrie) FindLowestByIp(ip net.IP) interface{}

func (*IpTrie) InsertIpAddr

func (o *IpTrie) InsertIpAddr(ipAddr *IpAddr, data interface{})

type IpTrieNode

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

Jump to

Keyboard shortcuts

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