Enum ipnet::IpNet
[−]
[src]
pub enum IpNet { V4(Ipv4Net), V6(Ipv6Net), }
An IP network address, either IPv4 or IPv6.
This enum can contain either an Ipv4Net
or an Ipv6Net
, see their
respective documentation for more details.
Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use std::str::FromStr; use ipnet::{IpNet, Ipv4Net, Ipv6Net}; let net_v4 = IpNet::from_str("10.1.1.0/24").unwrap(); let net_v6 = IpNet::from_str("fd00::/32").unwrap(); assert_eq!("10.1.1.0".parse(), Ok(net_v4.network())); assert_eq!("fd00::".parse(), Ok(net_v6.network()));
Variants
V4(Ipv4Net)
V6(Ipv6Net)
Methods
impl IpNet
[src]
fn netmask(&self) -> IpAddr
[src]
Returns the network mask.
Examples
let net = IpNet::from_str("10.1.0.0/20").unwrap(); assert_eq!(net.netmask(), IpAddr::from_str("255.255.240.0").unwrap()); let net = IpNet::from_str("fd00::/24").unwrap(); assert_eq!(net.netmask(), IpAddr::from_str("ffff:ff00::").unwrap());
fn hostmask(&self) -> IpAddr
[src]
Returns the host mask.
Examples
let net = IpNet::from_str("10.1.0.0/20").unwrap(); assert_eq!(net.hostmask(), IpAddr::from_str("0.0.15.255").unwrap()); let net = IpNet::from_str("fd00::/24").unwrap(); assert_eq!(net.hostmask(), IpAddr::from_str("::ff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap());
fn network(&self) -> IpAddr
[src]
Returns the network address.
Examples
let net = IpNet::from_str("172.16.123.123/16").unwrap(); assert_eq!(net.network(), IpAddr::from_str("172.16.0.0").unwrap()); let net = IpNet::from_str("fd00:1234:5678::/24").unwrap(); assert_eq!(net.network(), IpAddr::from_str("fd00:1200::").unwrap());
fn broadcast(&self) -> IpAddr
[src]
Returns the broadcast address.
Examples
let net = IpNet::from_str("172.16.0.0/22").unwrap(); assert_eq!(net.broadcast(), IpAddr::from_str("172.16.3.255").unwrap()); let net = IpNet::from_str("fd00:1234:5678::/24").unwrap(); assert_eq!(net.broadcast(), IpAddr::from_str("fd00:12ff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap());
fn supernet(&self) -> IpNet
[src]
Returns the IpNet
that contains this one.
Examples
let net = IpNet::from_str("172.16.1.0/24").unwrap(); assert_eq!(net.supernet().network(), IpAddr::from_str("172.16.0.0").unwrap()); let net = IpNet::from_str("fd00:ff00::/24").unwrap(); assert_eq!(net.supernet().network(), IpAddr::from_str("fd00:fe00::").unwrap());
fn subnets(&self, new_prefix_len: u8) -> IpNetIter<IpNet>
[src]
Returns an Iterator
over the subnets of this network with the
given prefix length.
If new_prefix_len
is less than the current prefix length or
greater than the bit width of the underlying IP address type it
will be clamped to both respectively.
Examples
let net = IpNet::from_str("10.0.0.0/24").unwrap(); assert_eq!(net.subnets(26).collect::<Vec<IpNet>>(), vec![ IpNet::from_str("10.0.0.0/26").unwrap(), IpNet::from_str("10.0.0.64/26").unwrap(), IpNet::from_str("10.0.0.128/26").unwrap(), IpNet::from_str("10.0.0.192/26").unwrap(), ]); let net = IpNet::from_str("fd00::/16").unwrap(); assert_eq!(net.subnets(18).collect::<Vec<IpNet>>(), vec![ IpNet::from_str("fd00::/18").unwrap(), IpNet::from_str("fd00:4000::/18").unwrap(), IpNet::from_str("fd00:8000::/18").unwrap(), IpNet::from_str("fd00:c000::/18").unwrap(), ]);
fn sibling_of(&self, other: &IpNet) -> bool
[src]
Returns true
if this network and the given network are both in
the same supernet.
Examples
let net1 = IpNet::from_str("10.1.0.0/24").unwrap(); let net2 = IpNet::from_str("10.1.1.0/24").unwrap(); let net3 = IpNet::from_str("10.1.2.0/24").unwrap(); assert!(net1.sibling_of(&net2)); assert!(!net2.sibling_of(&net3)); let net61 = IpNet::from_str("fd00::/18").unwrap(); let net62 = IpNet::from_str("fd00:4000::/18").unwrap(); let net63 = IpNet::from_str("fd00:8000::/18").unwrap(); assert!(net61.sibling_of(&net62)); assert!(!net62.sibling_of(&net63)); assert!(!net1.sibling_of(&net62));
fn aggregate(networks: &Vec<IpNet>) -> Vec<IpNet>
[src]
Trait Implementations
impl Copy for IpNet
[src]
impl Clone for IpNet
[src]
fn clone(&self) -> IpNet
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for IpNet
[src]
impl PartialEq for IpNet
[src]
fn eq(&self, __arg_0: &IpNet) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &IpNet) -> bool
[src]
This method tests for !=
.
impl Hash for IpNet
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialOrd for IpNet
[src]
fn partial_cmp(&self, __arg_0: &IpNet) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &IpNet) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &IpNet) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &IpNet) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &IpNet) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for IpNet
[src]
fn cmp(&self, __arg_0: &IpNet) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
[src]
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
[src]
ord_max_min
)Compares and returns the minimum of two values. Read more
impl Debug for IpNet
[src]
impl Display for IpNet
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl From<Ipv4Net> for IpNet
[src]
impl From<Ipv6Net> for IpNet
[src]
impl<'a> Contains<&'a IpNet> for IpNet
[src]
fn contains(&self, other: &IpNet) -> bool
[src]
Returns true
if this network contains the given network or address. Read more
impl<'a> Contains<&'a IpAddr> for IpNet
[src]
fn contains(&self, other: &IpAddr) -> bool
[src]
Returns true
if this network contains the given network or address. Read more
impl FromStr for IpNet
[src]
type Err = AddrParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<IpNet, AddrParseError>
[src]
Parses a string s
to return a value of this type. Read more