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. This is represented using the FromStr implementation for Ipv6Addr followed by a / character and the prefix length in decimal. See IETF RFC 4632 for the CIDR notation.

Examples

use std::net::Ipv6Addr;
use std::str::FromStr;
use ipnet::Ipv6Net;

let net_v6 = Ipv6Net::from_str("fd00::/32").unwrap();
assert_eq!("fd00::".parse(), Ok(net_v6.network()));

Methods

impl Ipv6Net
[src]

[src]

Creates a new IPv4 network address from an Ipv4Addr and prefix length.

If prefix_len is greater than 128 it will be clamped to 128.

Examples

let net = Ipv6Net::new(Ipv6Addr::from_str("fd00::").unwrap(), 24);

[src]

Returns the prefix length.

[src]

Experimental.

[src]

Returns the network mask.

Examples

let net = Ipv6Net::from_str("fd00::/24").unwrap();
assert_eq!(net.netmask(), Ipv6Addr::from_str("ffff:ff00::").unwrap());

[src]

Returns the host mask.

Examples

let net = Ipv6Net::from_str("fd00::/24").unwrap();
assert_eq!(net.hostmask(), Ipv6Addr::from_str("::ff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap());

[src]

Returns the network address. Truncates the provided Ipv6Addr to the prefix length.

Examples

let net = Ipv6Net::from_str("fd00:1234:5678::/24").unwrap();
assert_eq!(net.network(), Ipv6Addr::from_str("fd00:1200::").unwrap());

[src]

Returns the broadcast address. Returns the provided Ipv6Addr with all bits after the prefix length set.

  • Technically there is no such thing as a broadcast address in in IPv6. Perhaps we should change the methods to first() and last() or start() and end().

Examples

let net = Ipv6Net::from_str("fd00:1234:5678::/24").unwrap();
assert_eq!(net.broadcast(), Ipv6Addr::from_str("fd00:12ff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap());

[src]

Returns the Ipv6Net that contains this one.

Examples

let net = Ipv6Net::from_str("fd00:ff00::/24").unwrap();
assert_eq!(net.supernet().network(), Ipv6Addr::from_str("fd00:fe00::").unwrap());

[src]

Returns the subnets of this network at the given prefix length.

If new_prefix_len is greater than 128 it will be clamped to 128.

Examples

let net = Ipv6Net::from_str("fd00::/16").unwrap();
assert_eq!(net.subnets(18), vec![
    Ipv6Net::from_str("fd00::/18").unwrap(),
    Ipv6Net::from_str("fd00:4000::/18").unwrap(),
    Ipv6Net::from_str("fd00:8000::/18").unwrap(),
    Ipv6Net::from_str("fd00:c000::/18").unwrap(),
]);

[src]

Returns an Iterator over the subnets.

This might be deprecated and replaced with a generic implementation of Range when Range and it's required traits are stablized.

Examples

let i6 = Ipv6Net::from_str("fd00::/16").unwrap().iter_subnets(18);
let v6 = vec![
    Ipv6Net::from_str("fd00::/18").unwrap(),
    Ipv6Net::from_str("fd00:4000::/18").unwrap(),
    Ipv6Net::from_str("fd00:8000::/18").unwrap(),
    Ipv6Net::from_str("fd00:c000::/18").unwrap(),
];

assert_eq!(i6.collect::<Vec<Ipv6Net>>(), v6);

[src]

Return an Iterator over the host addresses in this network.

[src]

Returns true if this network and the given network are both in the same supernet.

Examples

let net1 = Ipv6Net::from_str("fd00::/18").unwrap();
let net2 = Ipv6Net::from_str("fd00:4000::/18").unwrap();
let net3 = Ipv6Net::from_str("fd00:8000::/18").unwrap();
assert!(net1.sibling_of(&net2));
assert!(!net2.sibling_of(&net3));

[src]

Experimental.

Methods from Deref<Target = Ipv6Addr>

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]);

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);

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);

[src]

🔬 This is a nightly-only experimental API. (ip)

extra functionality has not been scrutinized to the level that it should 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);
}

[src]

🔬 This is a nightly-only experimental API. (ip)

extra functionality has not been scrutinized to the level that it should 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);
}
🔬 This is a nightly-only experimental API. (ip)

extra functionality has not been scrutinized to the level that it should 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);
}

[src]

🔬 This is a nightly-only experimental API. (ip)

extra functionality has not been scrutinized to the level that it should 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);
}

[src]

🔬 This is a nightly-only experimental API. (ip)

extra functionality has not been scrutinized to the level that it should 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);
}

[src]

🔬 This is a nightly-only experimental API. (ip)

extra functionality has not been scrutinized to the level that it should 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);
}

[src]

🔬 This is a nightly-only experimental API. (ip)

extra functionality has not been scrutinized to the level that it should 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);
}

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);

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)));

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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for Ipv6Net
[src]

impl PartialEq for Ipv6Net
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Hash for Ipv6Net
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialOrd for Ipv6Net
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for Ipv6Net
[src]

[src]

This method returns an Ordering between self and other. Read more

[src]

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the maximum of two values. Read more

[src]

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the minimum of two values. Read more

impl Deref for Ipv6Net
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl<'a> Contains<&'a Ipv6Net> for Ipv6Net
[src]

[src]

Returns true if this network contains the given network or address. Read more

impl<'a> Contains<&'a Ipv6Addr> for Ipv6Net
[src]

[src]

Returns true if this network contains the given network or address. Read more

impl Debug for Ipv6Net
[src]

[src]

Formats the value using the given formatter.

impl Display for Ipv6Net
[src]

[src]

Formats the value using the given formatter. Read more

impl FromStr for Ipv6Net
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more