4 releases

0.2.0 Jul 12, 2021
0.1.2 Mar 30, 2020
0.1.1 Jul 8, 2019
0.1.0 May 18, 2019

#1643 in Network programming

Download history 11280/week @ 2023-12-01 16438/week @ 2023-12-08 16757/week @ 2023-12-15 6848/week @ 2023-12-22 12070/week @ 2023-12-29 16634/week @ 2024-01-05 14891/week @ 2024-01-12 16298/week @ 2024-01-19 20223/week @ 2024-01-26 15886/week @ 2024-02-02 17214/week @ 2024-02-09 19351/week @ 2024-02-16 18550/week @ 2024-02-23 29609/week @ 2024-03-01 22085/week @ 2024-03-08 17098/week @ 2024-03-15

90,880 downloads per month
Used in 13 crates (6 directly)

BSD-2-Clause

25KB
263 lines

ip_network_table

IPv4 and IPv6 network fast lookup table.

Documentation Build Status Coverage Status Crates.io

Description

This crate provides storage and retrieval of IPv4 and IPv6 network prefixes.

Currently, it uses ip_network crate, that provides IP network data structure and fork of treebitmap (fork) as backend, that provides fast lookup times, and a small memory footprint. Backend can be changed in future releases.

Usage

Add this to your Cargo.toml:

[dependencies]
ip_network = "0.4"
ip_network_table = "0.2"

this to your crate root (not necessary when your project is Rust 2018 edition):

extern crate ip_network;
extern crate ip_network_table;

and then you can use it like this:

use std::net::{IpAddr, Ipv6Addr};
use ip_network::{IpNetwork, Ipv6Network};
use ip_network_table::IpNetworkTable;

let mut table = IpNetworkTable::new();
let network = IpNetwork::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.clone(), "foo"), None);
// Get value for network from table
assert_eq!(table.longest_match(ip_address), Some((network, &"foo")));

Minimal required version of Rust compiler is 1.31 (because of ip_network crate).

Dependencies

~235KB