mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-16 08:48:51 +00:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2812a91a8 | |||
e1d3ac6de1 |
@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.21.1](https://github.com/achanda/ipnetwork/compare/v0.21.0...v0.21.1) - 2025-01-07
|
||||
|
||||
### Other
|
||||
|
||||
- Fix for 0::/0 network ([#205](https://github.com/achanda/ipnetwork/pull/205))
|
||||
|
||||
## [0.21.0](https://github.com/achanda/ipnetwork/compare/v0.20.0...v0.21.0) - 2025-01-06
|
||||
|
||||
### Fixed
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ipnetwork"
|
||||
version = "0.21.0"
|
||||
version = "0.21.1"
|
||||
authors = ["Abhishek Chanda <abhishek.becs@gmail.com>", "Linus Färnstrand <faern@faern.net>"]
|
||||
description = "A library to work with IP CIDRs in Rust"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
20
src/ipv6.rs
20
src/ipv6.rs
@ -203,6 +203,9 @@ impl Ipv6Network {
|
||||
pub fn mask(&self) -> Ipv6Addr {
|
||||
debug_assert!(self.prefix <= IPV6_BITS);
|
||||
|
||||
if self.prefix == 0 {
|
||||
return Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
let mask = u128::MAX << (IPV6_BITS - self.prefix);
|
||||
Ipv6Addr::from(mask)
|
||||
}
|
||||
@ -279,6 +282,10 @@ impl Ipv6Network {
|
||||
/// ```
|
||||
pub fn size(&self) -> u128 {
|
||||
debug_assert!(self.prefix <= IPV6_BITS);
|
||||
|
||||
if self.prefix == 0 {
|
||||
return u128::MAX;
|
||||
}
|
||||
1 << (IPV6_BITS - self.prefix)
|
||||
}
|
||||
|
||||
@ -757,4 +764,17 @@ mod test {
|
||||
);
|
||||
assert_eq!(net.nth(net.size()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mask_with_prefix_0() {
|
||||
let network: Ipv6Network = "0::/0".parse().unwrap();
|
||||
let mask = network.mask();
|
||||
assert_eq!(mask, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_size_with_prefix_0() {
|
||||
let network: Ipv6Network = "0::/0".parse().unwrap();
|
||||
assert_eq!(network.size(), u128::MAX);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user