krisprice / ipnet

IpNet, Ipv4Net, and Ipv6Net types and methods for Rust
Apache License 2.0
122 stars 26 forks source link

Enhancement: Allow parsing of abbreviated IPv4 CIDR addresses #22

Open darrinsmart opened 4 years ago

darrinsmart commented 4 years ago

This works: let net4 = Ipv4Net::from_str("10.1.1.0/24").unwrap();

But this doesn't: let net4 = Ipv4Net::from_str("10.1.1/24").unwrap();

This abbreviated form of IPv4 CIDR - omitting trailing 0 octets, is fairly common, it would be great if ipnet could accept these.

krisprice commented 4 years ago

HI @darrinsmart -- I'll keep this issue around to track and when I have time implement this. Thanks 👍

benmaddison commented 2 years ago

@krisprice although I can appreciate that this might be useful in some applications, it will break others if it's done silently in the FromStr impls. There are plenty of places (e.g. most vendor config syntaxes, RPSL) were the abbreviated form is not legal. I'd suggest a separate constructor for this.