Skip to main content

Module scope

Module scope 

Available on crate feature net only.
Expand description

Classify IP addresses into special-use IpScopes and enumerate the CIDR ranges that make up a scope.

super::private::is_private_ip collapses every non-global range into a single bool. ip_scope keeps the categories apart, so callers can compose them with ordinary set algebra — the “a / b / a+b” question:

use rama_net::address::ip::scope::{ip_scope, IpScopes};

let ip = [127, 0, 0, 1];
// loopback only
assert_eq!(ip_scope(ip), IpScopes::LOOPBACK);
// "private but not loopback" — PRIVATE and LOOPBACK are distinct bits
assert!(!ip_scope(ip).contains(IpScopes::PRIVATE));
// "private OR loopback"
assert!(ip_scope(ip).intersects(IpScopes::PRIVATE | IpScopes::LOOPBACK));

References:

Structs§

IpScopes
Special-use scope an IP address belongs to.

Functions§

ip_scope
Classify addr into the special-use IpScopes it belongs to.
ipv4_scope
Classify an IPv4 address. See ip_scope.
ipv6_scope
Classify an IPv6 address. See ip_scope.
scope_cidrs
The CIDR ranges that make up the given scopes mask, across IPv4 and IPv6.