tiborschneider / prefix-trie

Apache License 2.0
20 stars 4 forks source link

Correctly handle blocks containing all IP addresses (0.0.0.0/0) #8

Closed edigaryev closed 4 months ago

edigaryev commented 4 months ago

The following code works as expected and prints Some(192.168.0.0/23) Some(192.168.0.0/24):

#[test]
fn test_spm_vs_lpm() {
    let prefix_set = PrefixSet::from_iter(vec![
        Ipv4Net::from_str("192.168.0.0/23").unwrap(),
        Ipv4Net::from_str("192.168.0.0/24").unwrap(),
    ]);

    let prefix = Ipv4Net::from_str("192.168.0.1/32").unwrap();

    println!("{:?} {:?}", prefix_set.get_spm(&prefix), prefix_set.get_lpm(&prefix));
}

However, if we replace the 192.168.0.0/23 with 0.0.0.0/0, the code above will print Some(192.168.0.0/24) Some(192.168.0.0/24) instead of the expected Some(0.0.0.0/0) Some(192.168.0.0/24).

tiborschneider commented 4 months ago

Thanks for reporting. Fixed in #9.

I will update the crates.io version soon.

Edit: published under version 0.4.2