pub struct Ipv6Addr(/* private fields */);
Expand description
An IPv6 address.
§Layout
Ipv6Addr
has the same layout as [u8; 16]
, which is the layout that most
protocols use to represent an IPv6 address in their packet formats. This can
be useful when parsing an IPv6 address from a packet. For example:
/// The fixed part of an IPv6 packet header.
///
/// `FixedHeader` has the same layout as the fixed part of an IPv6 packet
/// header.
#[repr(C)]
pub struct FixedHeader {
version_tc_flowlabel: [u8; 4],
payload_len: [u8; 2],
next_hdr: u8,
hop_limit: u8,
src_ip: Ipv6Addr,
dst_ip: Ipv6Addr,
}
§Display
The Display
impl for Ipv6Addr
formats according to RFC 5952.
Where RFC 5952 leaves decisions up to the implementation, Ipv6Addr
matches
the behavior of std::net::Ipv6Addr
- all IPv6 addresses are formatted
the same by Ipv6Addr
as by <std::net::Ipv6Addr as Display>::fmt
.
Implementations§
source§impl Ipv6Addr
impl Ipv6Addr
sourcepub const fn new(segments: [u16; 8]) -> Ipv6Addr
pub const fn new(segments: [u16; 8]) -> Ipv6Addr
Creates a new IPv6 address from 16-bit segments.
sourcepub const fn from_bytes(bytes: [u8; 16]) -> Ipv6Addr
pub const fn from_bytes(bytes: [u8; 16]) -> Ipv6Addr
Creates a new IPv6 address from bytes.
sourcepub const fn ipv6_bytes(&self) -> [u8; 16]
pub const fn ipv6_bytes(&self) -> [u8; 16]
Gets the bytes of the IPv6 address.
sourcepub const fn to_solicited_node_address(&self) -> MulticastAddr<Ipv6Addr>
pub const fn to_solicited_node_address(&self) -> MulticastAddr<Ipv6Addr>
Converts this Ipv6Addr
to the IPv6 Solicited-Node Address, used in
Neighbor Discovery, defined in RFC 4291 Section 2.7.1.
sourcepub fn is_valid_unicast(&self) -> bool
pub fn is_valid_unicast(&self) -> bool
Is this a valid unicast address?
A valid unicast address is any unicast address that can be bound to an
interface (not the unspecified or loopback addresses).
addr.is_valid_unicast()
is equivalent to !(addr.is_loopback() || !addr.is_specified() || addr.is_multicast())
.
sourcepub fn is_site_local(&self) -> bool
pub fn is_site_local(&self) -> bool
Is this address in the (deprecated) site-local unicast subnet?
is_site_local
returns true if self
is in the (deprecated)
Ipv6::SITE_LOCAL_UNICAST_SUBNET
. See that constant’s documentation
for more details on deprecation and how the subnet should be used in
light of deprecation.
sourcepub fn is_unicast_link_local(&self) -> bool
pub fn is_unicast_link_local(&self) -> bool
Is this a unicast link-local address?
addr.is_unicast_link_local()
is equivalent to
addr.is_unicast_in_subnet(&Ipv6::LINK_LOCAL_UNICAST_SUBNET)
.
sourcepub fn to_ipv4_compatible(&self) -> Option<Ipv4Addr>
pub fn to_ipv4_compatible(&self) -> Option<Ipv4Addr>
Tries to extract the IPv4 address from an IPv4-compatible IPv6 address.
IPv4-compatible IPv6 addresses were defined to assist in the IPv6 transition, and are now specified in RFC 4291 Section 2.5.5.1. The lowest-order 32 bits carry an IPv4 address, while the highest-order 96 bits are all set to 0 as in this diagram from the RFC:
| 80 bits | 16 | 32 bits |
+--------------------------------------+--------------------------+
|0000..............................0000|0000| IPv4 address |
+--------------------------------------+----+---------------------+
to_ipv4_compatible
checks to see if self
is an IPv4-compatible
IPv6 address. If it is, the IPv4 address is extracted and returned.
Per RFC 4291:
The ‘IPv4-Compatible IPv6 address’ is now deprecated because the current IPv6 transition mechanisms no longer use these addresses. New or updated implementations are not required to support this address type.
The more modern embedding format is IPv4-mapped IPv6 addressing - see
to_ipv4_mapped
.
sourcepub fn to_ipv4_mapped(&self) -> Option<Ipv4Addr>
pub fn to_ipv4_mapped(&self) -> Option<Ipv4Addr>
Tries to extract the IPv4 address from an IPv4-mapped IPv6 address.
IPv4-mapped IPv6 addresses are used to represent the addresses of IPv4 nodes as IPv6 addresses, and are defined in RFC 4291 Section 2.5.5.2. The lowest-order 32 bits carry an IPv4 address, the middle order 16 bits carry the literal 0xFFFF, and the highest order 80 bits are set to 0 as in this diagram from the RFC:
| 80 bits | 16 | 32 bits |
+--------------------------------------+--------------------------+
|0000..............................0000|FFFF| IPv4 address |
+--------------------------------------+----+---------------------+
to_ipv4_mapped
checks to see if self
is an IPv4-mapped
IPv6 address. If it is, the IPv4 address is extracted and returned.
Trait Implementations§
source§impl AsRef<Ipv6Addr> for Ipv6SourceAddr
impl AsRef<Ipv6Addr> for Ipv6SourceAddr
source§impl AsRef<Ipv6Addr> for UnicastOrMulticastIpv6Addr
impl AsRef<Ipv6Addr> for UnicastOrMulticastIpv6Addr
source§impl Display for Ipv6Addr
impl Display for Ipv6Addr
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Formats an IPv6 address according to RFC 5952.
Where RFC 5952 leaves decisions up to the implementation, this function
matches the behavior of std::net::Ipv6Addr
- all IPv6 addresses are
formatted the same by this function as by <std::net::Ipv6Addr as Display>::fmt
.
source§impl From<&Ipv6SourceAddr> for Ipv6Addr
impl From<&Ipv6SourceAddr> for Ipv6Addr
source§fn from(addr: &Ipv6SourceAddr) -> Ipv6Addr
fn from(addr: &Ipv6SourceAddr) -> Ipv6Addr
source§impl From<&UnicastOrMulticastIpv6Addr> for Ipv6Addr
impl From<&UnicastOrMulticastIpv6Addr> for Ipv6Addr
source§fn from(addr: &UnicastOrMulticastIpv6Addr) -> Ipv6Addr
fn from(addr: &UnicastOrMulticastIpv6Addr) -> Ipv6Addr
source§impl From<Ipv4Addr> for Ipv6Addr
impl From<Ipv4Addr> for Ipv6Addr
Ipv4Addr
is convertible into Ipv6Addr
through
Ipv4Addr::to_ipv6_mapped
.
source§impl From<Ipv6SourceAddr> for Ipv6Addr
impl From<Ipv6SourceAddr> for Ipv6Addr
source§fn from(addr: Ipv6SourceAddr) -> Ipv6Addr
fn from(addr: Ipv6SourceAddr) -> Ipv6Addr
source§impl<A: Into<Ipv6Addr> + LinkLocalAddress + Copy> From<LinkLocalAddr<A>> for Ipv6Addr
impl<A: Into<Ipv6Addr> + LinkLocalAddress + Copy> From<LinkLocalAddr<A>> for Ipv6Addr
source§fn from(addr: LinkLocalAddr<A>) -> Ipv6Addr
fn from(addr: LinkLocalAddr<A>) -> Ipv6Addr
source§impl<A: Into<Ipv6Addr> + MulticastAddress + Copy> From<MulticastAddr<A>> for Ipv6Addr
impl<A: Into<Ipv6Addr> + MulticastAddress + Copy> From<MulticastAddr<A>> for Ipv6Addr
source§fn from(addr: MulticastAddr<A>) -> Ipv6Addr
fn from(addr: MulticastAddr<A>) -> Ipv6Addr
source§impl<A: Into<Ipv6Addr> + MappedAddress + Copy> From<NonMappedAddr<A>> for Ipv6Addr
impl<A: Into<Ipv6Addr> + MappedAddress + Copy> From<NonMappedAddr<A>> for Ipv6Addr
source§fn from(addr: NonMappedAddr<A>) -> Ipv6Addr
fn from(addr: NonMappedAddr<A>) -> Ipv6Addr
source§impl<A: Into<Ipv6Addr> + SpecifiedAddress + Copy> From<SpecifiedAddr<A>> for Ipv6Addr
impl<A: Into<Ipv6Addr> + SpecifiedAddress + Copy> From<SpecifiedAddr<A>> for Ipv6Addr
source§fn from(addr: SpecifiedAddr<A>) -> Ipv6Addr
fn from(addr: SpecifiedAddr<A>) -> Ipv6Addr
source§impl<A: Into<Ipv6Addr> + UnicastAddress + Copy> From<UnicastAddr<A>> for Ipv6Addr
impl<A: Into<Ipv6Addr> + UnicastAddress + Copy> From<UnicastAddr<A>> for Ipv6Addr
source§fn from(addr: UnicastAddr<A>) -> Ipv6Addr
fn from(addr: UnicastAddr<A>) -> Ipv6Addr
source§impl From<UnicastOrMulticastIpv6Addr> for Ipv6Addr
impl From<UnicastOrMulticastIpv6Addr> for Ipv6Addr
source§fn from(addr: UnicastOrMulticastIpv6Addr) -> Ipv6Addr
fn from(addr: UnicastOrMulticastIpv6Addr) -> Ipv6Addr
source§impl FromBytes for Ipv6Addr
impl FromBytes for Ipv6Addr
§fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
§fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
§fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
&Self
. Read more§fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
source§impl<I: Ip> GenericOverIp<I> for Ipv6Addr
impl<I: Ip> GenericOverIp<I> for Ipv6Addr
source§impl IntoBytes for Ipv6Addr
impl IntoBytes for Ipv6Addr
§fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
§fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
source§impl IpAddress for Ipv6Addr
impl IpAddress for Ipv6Addr
source§fn to_ip_addr(&self) -> IpAddr
fn to_ip_addr(&self) -> IpAddr
source§fn common_prefix_len(&self, other: &Ipv6Addr) -> u8
fn common_prefix_len(&self, other: &Ipv6Addr) -> u8
other
.source§fn is_unicast_in_subnet(&self, subnet: &Subnet<Self>) -> bool
fn is_unicast_in_subnet(&self, subnet: &Subnet<Self>) -> bool
source§fn is_loopback(&self) -> bool
fn is_loopback(&self) -> bool
source§impl KnownLayout for Ipv6Addrwhere
Self: Sized,
impl KnownLayout for Ipv6Addrwhere
Self: Sized,
§type PointerMetadata = ()
type PointerMetadata = ()
Self
. Read moresource§impl LinkLocalAddress for Ipv6Addr
impl LinkLocalAddress for Ipv6Addr
source§fn is_link_local(&self) -> bool
fn is_link_local(&self) -> bool
Is this address in the link-local subnet?
is_link_local
returns true if self
is in
Ipv6::LINK_LOCAL_UNICAST_SUBNET
, is a multicast address whose scope
is link-local, or is the address Ipv6::LOOPBACK_ADDRESS
(per RFC
4291 Section 2.5.3, the loopback address is considered to have
link-local scope).
source§impl Ord for Ipv6Addr
impl Ord for Ipv6Addr
source§impl PartialEq for Ipv6Addr
impl PartialEq for Ipv6Addr
source§impl PartialOrd for Ipv6Addr
impl PartialOrd for Ipv6Addr
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl ScopeableAddress for Ipv6Addr
impl ScopeableAddress for Ipv6Addr
source§impl TryFrom<Ipv6Addr> for Ipv6SourceAddr
impl TryFrom<Ipv6Addr> for Ipv6SourceAddr
source§impl TryFrom<Ipv6Addr> for UnicastOrMulticastIpv6Addr
impl TryFrom<Ipv6Addr> for UnicastOrMulticastIpv6Addr
source§impl TryFromBytes for Ipv6Addr
impl TryFromBytes for Ipv6Addr
§fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_mut_from_bytes(
bytes: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
fn try_mut_from_bytes(
bytes: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
§fn try_mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
fn try_mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
§fn try_mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
fn try_mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
§fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
§fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
§fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
source§impl UnicastAddress for Ipv6Addr
impl UnicastAddress for Ipv6Addr
source§fn is_unicast(&self) -> bool
fn is_unicast(&self) -> bool
Is this a unicast address?
addr.is_unicast()
is equivalent to !addr.is_multicast() && addr.is_specified()
.
source§impl Witness<Ipv6Addr> for Ipv6SourceAddr
impl Witness<Ipv6Addr> for Ipv6SourceAddr
source§unsafe fn new_unchecked(addr: Ipv6Addr) -> Ipv6SourceAddr
unsafe fn new_unchecked(addr: Ipv6Addr) -> Ipv6SourceAddr
addr
actually
satisfies the required property. Read moresource§impl Witness<Ipv6Addr> for UnicastOrMulticastIpv6Addr
impl Witness<Ipv6Addr> for UnicastOrMulticastIpv6Addr
source§fn new(addr: Ipv6Addr) -> Option<UnicastOrMulticastIpv6Addr>
fn new(addr: Ipv6Addr) -> Option<UnicastOrMulticastIpv6Addr>
source§unsafe fn new_unchecked(addr: Ipv6Addr) -> UnicastOrMulticastIpv6Addr
unsafe fn new_unchecked(addr: Ipv6Addr) -> UnicastOrMulticastIpv6Addr
addr
actually
satisfies the required property. Read moreimpl Copy for Ipv6Addr
impl Eq for Ipv6Addr
impl Immutable for Ipv6Addr
impl StructuralPartialEq for Ipv6Addr
impl Unaligned for Ipv6Addr
Auto Trait Implementations§
impl Freeze for Ipv6Addr
impl RefUnwindSafe for Ipv6Addr
impl Send for Ipv6Addr
impl Sync for Ipv6Addr
impl Unpin for Ipv6Addr
impl UnwindSafe for Ipv6Addr
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<A> MappedAddress for Awhere
A: IpAddress,
impl<A> MappedAddress for Awhere
A: IpAddress,
source§fn is_non_mapped(&self) -> bool
fn is_non_mapped(&self) -> bool
Is this address non-mapped?
For IPv4 addresses, this always returns true because they do not have a mapped address space.
For Ipv6 addresses, this returns true if self
is outside of the IPv4
mapped Ipv6 address subnet, as defined in RFC 4291 Section 2.5.5.2
(e.g. ::FFFF:0:0/96
).
source§impl<A> MulticastAddress for Awhere
A: IpAddress,
impl<A> MulticastAddress for Awhere
A: IpAddress,
source§fn is_multicast(&self) -> bool
fn is_multicast(&self) -> bool
Is this address in the multicast subnet?
is_multicast
returns true if self
is in
A::Version::MULTICAST_SUBNET
.
source§fn is_non_multicast(&self) -> bool
fn is_non_multicast(&self) -> bool
is_multicast()
.source§impl<A> SpecifiedAddress for Awhere
A: IpAddress,
impl<A> SpecifiedAddress for Awhere
A: IpAddress,
source§fn is_specified(&self) -> bool
fn is_specified(&self) -> bool
Is this an address other than the unspecified address?
is_specified
returns true if self
is not equal to
A::Version::UNSPECIFIED_ADDRESS
.