achanda / ipnetwork

A library to work with CIDRs in rust
Apache License 2.0
121 stars 38 forks source link

is_supernet_of does not work properly #152

Open mbasunov opened 2 years ago

mbasunov commented 2 years ago

Hi

use ipnetwork::Ipv4Network;
let net: Ipv4Network = "10.1.0.0/16".parse().unwrap();
let net2: Ipv4Network = "10.1.0.0/15".parse().unwrap();
println!("{:?} {} {}", net2, net.is_supernet_of(net2),
    net.is_supernet_of(Ipv4Network::new(net2.network(), net2.prefix()).unwrap()));

Output: Ipv4Network { addr: 10.1.0.0, prefix: 15 } true false

So, is_supernet_of accidentally thinks that /16 is a supernet of /15 if network address is the same.

PS: Prefix "X/Y" consists of network address X and bits Y. So, function prefix which return bits confuses any network engineer.

ctrlcctrlv commented 1 year ago

Confirmed.