Expand description
This crate provides storage and retrieval of IPv4 and IPv6 network prefixes.
Currently, it uses ipnet crate, that provides IP network data structure and
prefix-trie as backend, that provides fast lookup times, and a small memory footprint.
Backend can be changed in future releases.
§Examples
use std::net::{IpAddr, Ipv6Addr};
use ipnet::{IpNet, Ipv6Net};
use ipnet_trie::IpnetTrie;
let mut table = IpnetTrie::new();
let network = IpNet::from(Ipv6Net::new(Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0, 0, 0, 0), 64).unwrap());
let ip_address = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0, 0, 0, 0x1);
assert_eq!(table.insert(network, "foo"), None);
// Get value for network from table
assert_eq!(table.longest_match(&IpNet::from(ip_address.to_canonical())), Some((network, &"foo")));Structs§
- Ipnet
Trie - Table holding IPv4 and IPv6 network prefixes with value.
Functions§
- exclude_
prefix - Splits a source IP network into multiple IP networks based on a target IP network.