Struct ipnet::Ipv6Net
[−]
[src]
pub struct Ipv6Net { /* fields omitted */ }
An IPv6 network address.
See IpNet
for a type encompassing both IPv4 and IPv6 network
addresses.
Textual representation
Ipv6Net
provides a FromStr
implementation for parsing network
addresses represented in CIDR notation. See IETF RFC 4632 for the
CIDR notation.
Examples
use std::net::Ipv6Addr; use ipnet::Ipv6Net; let net: Ipv6Net = "fd00::/32".parse().unwrap(); assert_eq!(Ok(net.network()), "fd00::".parse());
Methods
impl Ipv6Net
[src]
pub fn new(ip: Ipv6Addr, prefix_len: u8) -> Result<Ipv6Net, PrefixLenError>
[src]
Creates a new IPv6 network address from an Ipv6Addr
and prefix
length.
Examples
use std::net::Ipv6Addr; use ipnet::{Ipv6Net, PrefixLenError}; let net = Ipv6Net::new(Ipv6Addr::new(0xfd, 0, 0, 0, 0, 0, 0, 0), 24); assert!(net.is_ok()); let bad_prefix_len = Ipv6Net::new(Ipv6Addr::new(0xfd, 0, 0, 0, 0, 0, 0, 0), 129); assert_eq!(bad_prefix_len, Err(PrefixLenError));
pub fn trunc(&self) -> Ipv6Net
[src]
Returns a copy of the network with the address truncated to the prefix length.
Examples
assert_eq!( "fd00::1:2:3:4/16".parse::<Ipv6Net>().unwrap().trunc(), "fd00::/16".parse().unwrap() );
pub fn addr(&self) -> Ipv6Addr
[src]
Returns the address.
pub fn prefix_len(&self) -> u8
[src]
Returns the prefix length.
pub fn max_prefix_len(&self) -> u8
[src]
Returns the maximum valid prefix length.
pub fn netmask(&self) -> Ipv6Addr
[src]
Returns the network mask.
Examples
let net: Ipv6Net = "fd00::/24".parse().unwrap(); assert_eq!(Ok(net.netmask()), "ffff:ff00::".parse());
pub fn hostmask(&self) -> Ipv6Addr
[src]
Returns the host mask.
Examples
let net: Ipv6Net = "fd00::/24".parse().unwrap(); assert_eq!(Ok(net.hostmask()), "::ff:ffff:ffff:ffff:ffff:ffff:ffff".parse());
pub fn network(&self) -> Ipv6Addr
[src]
Returns the network address.
Examples
let net: Ipv6Net = "fd00:1234:5678::/24".parse().unwrap(); assert_eq!(Ok(net.network()), "fd00:1200::".parse());
pub fn broadcast(&self) -> Ipv6Addr
[src]
Returns the last address.
Technically there is no such thing as a broadcast address for IPv6. The name is used for consistency with colloquial usage.
Examples
let net: Ipv6Net = "fd00:1234:5678::/24".parse().unwrap(); assert_eq!(Ok(net.broadcast()), "fd00:12ff:ffff:ffff:ffff:ffff:ffff:ffff".parse());
pub fn supernet(&self) -> Option<Ipv6Net>
[src]
Returns the Ipv6Net
that contains this one.
Examples
let n1: Ipv6Net = "fd00:ff00::/24".parse().unwrap(); let n2: Ipv6Net = "fd00:fe00::/23".parse().unwrap(); let n3: Ipv6Net = "fd00:fe00::/0".parse().unwrap(); assert_eq!(n1.supernet().unwrap(), n2); assert_eq!(n3.supernet(), None);
pub fn is_sibling(&self, other: &Ipv6Net) -> bool
[src]
Returns true
if this network and the given network are
children of the same supernet.
Examples
let n1: Ipv6Net = "fd00::/18".parse().unwrap(); let n2: Ipv6Net = "fd00:4000::/18".parse().unwrap(); let n3: Ipv6Net = "fd00:8000::/18".parse().unwrap(); assert!(n1.is_sibling(&n2)); assert!(!n2.is_sibling(&n3));
ⓘImportant traits for Ipv6AddrRangepub fn hosts(&self) -> Ipv6AddrRange
[src]
Return an Iterator
over the host addresses in this network.
Examples
let net: Ipv6Net = "fd00::/126".parse().unwrap(); assert_eq!(net.hosts().collect::<Vec<Ipv6Addr>>(), vec![ "fd00::".parse::<Ipv6Addr>().unwrap(), "fd00::1".parse().unwrap(), "fd00::2".parse().unwrap(), "fd00::3".parse().unwrap(), ]);
pub fn subnets(&self, new_prefix_len: u8) -> Result<Ipv6Subnets, PrefixLenError>
[src]
Returns an Iterator
over the subnets of this network with the
given prefix length.
Examples
let net: Ipv6Net = "fd00::/16".parse().unwrap(); assert_eq!(net.subnets(18).unwrap().collect::<Vec<Ipv6Net>>(), vec![ "fd00::/18".parse::<Ipv6Net>().unwrap(), "fd00:4000::/18".parse().unwrap(), "fd00:8000::/18".parse().unwrap(), "fd00:c000::/18".parse().unwrap(), ]); let net: Ipv6Net = "fd00::/126".parse().unwrap(); assert_eq!(net.subnets(128).unwrap().collect::<Vec<Ipv6Net>>(), vec![ "fd00::/128".parse::<Ipv6Net>().unwrap(), "fd00::1/128".parse().unwrap(), "fd00::2/128".parse().unwrap(), "fd00::3/128".parse().unwrap(), ]); let net: Ipv6Net = "fd00::/16".parse().unwrap(); assert_eq!(net.subnets(15), Err(PrefixLenError)); let net: Ipv6Net = "fd00::/16".parse().unwrap(); assert_eq!(net.subnets(129), Err(PrefixLenError));
pub fn aggregate(networks: &Vec<Ipv6Net>) -> Vec<Ipv6Net>
[src]
Aggregate a Vec
of Ipv6Net
s and return the result as a new
Vec
.
Examples
let nets = vec![ "fd00::/18".parse::<Ipv6Net>().unwrap(), "fd00:4000::/18".parse().unwrap(), "fd00:8000::/18".parse().unwrap(), ]; assert_eq!(Ipv6Net::aggregate(&nets), vec![ "fd00::/17".parse::<Ipv6Net>().unwrap(), "fd00:8000::/18".parse().unwrap(), ]);
Methods from Deref<Target = Ipv6Addr>
pub fn segments(&self) -> [u16; 8]
1.0.0[src]
Returns the eight 16-bit segments that make up this address.
Examples
use std::net::Ipv6Addr; assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).segments(), [0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff]);
pub fn is_unspecified(&self) -> bool
1.7.0[src]
Returns true
for the special 'unspecified' address (::).
This property is defined in IETF RFC 4291.
Examples
use std::net::Ipv6Addr; assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unspecified(), false); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).is_unspecified(), true);
pub fn is_loopback(&self) -> bool
1.7.0[src]
Returns true
if this is a loopback address (::1).
This property is defined in IETF RFC 4291.
Examples
use std::net::Ipv6Addr; assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_loopback(), false); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_loopback(), true);
pub fn is_global(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
extra functionality has not been scrutinized to the level that it should be to be stable
Returns true
if the address appears to be globally routable.
The following return false
:
- the loopback address
- link-local, site-local, and unique local unicast addresses
- interface-, link-, realm-, admin- and site-local multicast addresses
Examples
#![feature(ip)] use std::net::Ipv6Addr; fn main() { assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_global(), true); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_global(), false); assert_eq!(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1).is_global(), true); }
pub fn is_unique_local(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
extra functionality has not been scrutinized to the level that it should be to be stable
Returns true
if this is a unique local address (fc00::/7).
This property is defined in IETF RFC 4193.
Examples
#![feature(ip)] use std::net::Ipv6Addr; fn main() { assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(), false); assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true); }
pub fn is_unicast_link_local(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
extra functionality has not been scrutinized to the level that it should be to be stable
Returns true
if the address is unicast and link-local (fe80::/10).
This property is defined in IETF RFC 4291.
Examples
#![feature(ip)] use std::net::Ipv6Addr; fn main() { assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_link_local(), false); assert_eq!(Ipv6Addr::new(0xfe8a, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true); }
pub fn is_unicast_site_local(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
extra functionality has not been scrutinized to the level that it should be to be stable
Returns true
if this is a deprecated unicast site-local address
(fec0::/10).
Examples
#![feature(ip)] use std::net::Ipv6Addr; fn main() { assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_site_local(), false); assert_eq!(Ipv6Addr::new(0xfec2, 0, 0, 0, 0, 0, 0, 0).is_unicast_site_local(), true); }
pub fn is_documentation(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
extra functionality has not been scrutinized to the level that it should be to be stable
Returns true
if this is an address reserved for documentation
(2001:db8::/32).
This property is defined in IETF RFC 3849.
Examples
#![feature(ip)] use std::net::Ipv6Addr; fn main() { assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false); assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true); }
pub fn is_unicast_global(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
extra functionality has not been scrutinized to the level that it should be to be stable
Returns true
if the address is a globally routable unicast address.
The following return false:
- the loopback address
- the link-local addresses
- the (deprecated) site-local addresses
- unique local addresses
- the unspecified address
- the address range reserved for documentation
Examples
#![feature(ip)] use std::net::Ipv6Addr; fn main() { assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast_global(), false); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_global(), true); }
pub fn multicast_scope(&self) -> Option<Ipv6MulticastScope>
[src]
🔬 This is a nightly-only experimental API. (ip
)
extra functionality has not been scrutinized to the level that it should be to be stable
Returns the address's multicast scope if the address is multicast.
Examples
#![feature(ip)] use std::net::{Ipv6Addr, Ipv6MulticastScope}; fn main() { assert_eq!(Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0).multicast_scope(), Some(Ipv6MulticastScope::Global)); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).multicast_scope(), None); }
pub fn is_multicast(&self) -> bool
1.7.0[src]
Returns true
if this is a multicast address (ff00::/8).
This property is defined by IETF RFC 4291.
Examples
use std::net::Ipv6Addr; assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).is_multicast(), true); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_multicast(), false);
pub fn to_ipv4(&self) -> Option<Ipv4Addr>
1.0.0[src]
Converts this address to an IPv4 address. Returns None
if this address is
neither IPv4-compatible or IPv4-mapped.
::a.b.c.d and ::ffff:a.b.c.d become a.b.c.d
Examples
use std::net::{Ipv4Addr, Ipv6Addr}; assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4(), None); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(), Some(Ipv4Addr::new(192, 10, 2, 255))); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(), Some(Ipv4Addr::new(0, 0, 0, 1)));
pub fn octets(&self) -> [u8; 16]
1.12.0[src]
Returns the sixteen eight-bit integers the IPv6 address consists of.
use std::net::Ipv6Addr; assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).octets(), [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
Trait Implementations
impl Copy for Ipv6Net
[src]
impl Clone for Ipv6Net
[src]
fn clone(&self) -> Ipv6Net
[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 Ipv6Net
[src]
impl PartialEq for Ipv6Net
[src]
fn eq(&self, __arg_0: &Ipv6Net) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Ipv6Net) -> bool
[src]
This method tests for !=
.
impl Ord for Ipv6Net
[src]
fn cmp(&self, __arg_0: &Ipv6Net) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl PartialOrd for Ipv6Net
[src]
fn partial_cmp(&self, __arg_0: &Ipv6Net) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Ipv6Net) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Ipv6Net) -> 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: &Ipv6Net) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Ipv6Net) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Hash for Ipv6Net
[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 Deref for Ipv6Net
[src]
type Target = Ipv6Addr
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Dereferences the value.
impl From<Ipv6Net> for IpNet
[src]
impl Debug for Ipv6Net
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Display for Ipv6Net
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<'a> Contains<&'a Ipv6Net> for Ipv6Net
[src]
impl<'a> Contains<&'a Ipv6Addr> for Ipv6Net
[src]
impl FromStr for Ipv6Net
[src]
type Err = AddrParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Ipv6Net, AddrParseError>
[src]
Parses a string s
to return a value of this type. Read more