-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
632 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use core::net::{Ipv4Addr, Ipv6Addr}; | ||
|
||
use cidrs::{Ipv4Cidr, Ipv6Cidr}; | ||
#[test] | ||
fn ipv4_basic() { | ||
let cidr = Ipv4Cidr::new([192, 168, 0, 0], 24).unwrap(); | ||
|
||
// Test addresses within the CIDR block | ||
assert!(cidr.contains(Ipv4Addr::new(192, 168, 0, 1))); | ||
assert!(cidr.contains(Ipv4Addr::new(192, 168, 0, 254))); | ||
|
||
// Test the network address and broadcast address | ||
assert!(cidr.contains(Ipv4Addr::new(192, 168, 0, 0))); | ||
assert!(cidr.contains(Ipv4Addr::new(192, 168, 0, 255))); | ||
|
||
// Test addresses outside the CIDR block | ||
assert!(!cidr.contains(Ipv4Addr::new(192, 168, 1, 0))); | ||
assert!(!cidr.contains(Ipv4Addr::new(192, 167, 255, 255))); | ||
} | ||
|
||
#[test] | ||
fn ipv6_basic() { | ||
let cidr = Ipv6Cidr::new([0x2001, 0xdb8, 0, 0, 0, 0, 0, 0], 48).unwrap(); | ||
|
||
// Test addresses within the CIDR block | ||
assert!(cidr.contains(Ipv6Addr::new(0x2001, 0xdb8, 0, 1, 0, 0, 0, 1))); | ||
assert!(cidr.contains(Ipv6Addr::new( | ||
0x2001, 0xdb8, 0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff | ||
))); | ||
|
||
// Test the network address | ||
assert!(cidr.contains(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0))); | ||
|
||
// Test addresses outside the CIDR block | ||
assert!(!cidr.contains(Ipv6Addr::new(0x2001, 0xdb9, 0, 0, 0, 0, 0, 0))); | ||
assert!(!cidr.contains(Ipv6Addr::new( | ||
0x2001, 0xdb7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff | ||
))); | ||
} |
Oops, something went wrong.