iptable

Crates.ioiptable
lib.rsiptable
version
sourcesrc
created_at2024-10-17 00:37:20.171957
updated_at2024-10-24 14:58:40.012167
descriptionDatastructure for efficient IP address lookup
homepagehttps://github.com/jelmer/iptable-rs
repositoryhttps://github.com/jelmer/iptable-rs
max_upload_size
id1412478
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Jelmer Vernooij (jelmer)

documentation

README

IPTable

This crate contains an efficient data structure for storing and querying values by CIDR.

Examples

use iptable::Ipv4Table;
use ipnetwork::Ipv4Network;

let mut table = Ipv4Table::new();
table.insert("192.168.2.0/24".parse::<Ipv4Network>().unwrap(), 42);
table.insert("192.168.1.0/24".parse::<Ipv4Network>().unwrap(), 43);

assert_eq!(table.get("192.168.2.0/24".parse::<Ipv4Network>().unwrap()), Some(&42));

// Iterate over the prefixes under a given prefix
let ipnet: Ipv4Network = "192.168.0.0/16".parse().unwrap();
let relevant = table.iter_prefix(ipnet).collect::<Vec<_>>();
assert_eq!(2, relevant.len());

// Merge entries with longer prefixes
let merged_table = table.merge_longer_prefixes(16, |a, b| a + b);
assert_eq!(
    merged_table.iter().collect::<Vec<_>>(),
    vec![(&"192.168.0.0/16".parse().unwrap(), &85)]
);
Commit count: 40

cargo fmt