pub struct Ipv4Addr(/* private fields */);
Expand description
An IPv4 address.
§Layout
Ipv4Addr
has the same layout as [u8; 4]
, which is the layout that most
protocols use to represent an IPv4 address in their packet formats. This can
be useful when parsing an IPv4 address from a packet. For example:
/// An ICMPv4 Redirect Message header.
///
/// `Icmpv4RedirectHeader` has the same layout as the header of an ICMPv4
/// Redirect Message.
#[repr(C)]
struct Icmpv4RedirectHeader {
typ: u8,
code: u8,
checksum: [u8; 2],
gateway: Ipv4Addr,
}
Implementations§
source§impl Ipv4Addr
impl Ipv4Addr
sourcepub const fn ipv4_bytes(self) -> [u8; 4]
pub const fn ipv4_bytes(self) -> [u8; 4]
Gets the bytes of the IPv4 address.
sourcepub fn is_limited_broadcast(self) -> bool
pub fn is_limited_broadcast(self) -> bool
Is this the limited broadcast address?
is_limited_broadcast
is a shorthand for comparing against
Ipv4::LIMITED_BROADCAST_ADDRESS
.
sourcepub fn is_class_e(self) -> bool
pub fn is_class_e(self) -> bool
Is this a Class E address?
is_class_e
is a shorthand for checking membership in
Ipv4::CLASS_E_SUBNET
.
sourcepub fn to_ipv6_compatible(self) -> Ipv6Addr
pub fn to_ipv6_compatible(self) -> Ipv6Addr
Converts the address to an IPv4-compatible IPv6 address according to RFC 4291 Section 2.5.5.1.
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 |
+--------------------------------------+----+---------------------+
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_ipv6_mapped
.
sourcepub fn to_ipv6_mapped(self) -> SpecifiedAddr<Ipv6Addr>
pub fn to_ipv6_mapped(self) -> SpecifiedAddr<Ipv6Addr>
Converts the address to an IPv4-mapped IPv6 address according to RFC 4291 Section 2.5.5.2.
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 |
+--------------------------------------+----+---------------------+
sourcepub fn class(&self) -> Ipv4AddressClass
pub fn class(&self) -> Ipv4AddressClass
Returns the address’s class according to the obsoleted classful addressing architecture.
Trait Implementations§
source§impl From<Ipv4Addr> for Ipv6Addr
impl From<Ipv4Addr> for Ipv6Addr
Ipv4Addr
is convertible into Ipv6Addr
through
Ipv4Addr::to_ipv6_mapped
.
source§impl<A: Into<Ipv4Addr> + LinkLocalAddress + Copy> From<LinkLocalAddr<A>> for Ipv4Addr
impl<A: Into<Ipv4Addr> + LinkLocalAddress + Copy> From<LinkLocalAddr<A>> for Ipv4Addr
source§fn from(addr: LinkLocalAddr<A>) -> Ipv4Addr
fn from(addr: LinkLocalAddr<A>) -> Ipv4Addr
source§impl<A: Into<Ipv4Addr> + MulticastAddress + Copy> From<MulticastAddr<A>> for Ipv4Addr
impl<A: Into<Ipv4Addr> + MulticastAddress + Copy> From<MulticastAddr<A>> for Ipv4Addr
source§fn from(addr: MulticastAddr<A>) -> Ipv4Addr
fn from(addr: MulticastAddr<A>) -> Ipv4Addr
source§impl<A: Into<Ipv4Addr> + MappedAddress + Copy> From<NonMappedAddr<A>> for Ipv4Addr
impl<A: Into<Ipv4Addr> + MappedAddress + Copy> From<NonMappedAddr<A>> for Ipv4Addr
source§fn from(addr: NonMappedAddr<A>) -> Ipv4Addr
fn from(addr: NonMappedAddr<A>) -> Ipv4Addr
source§impl<A: Into<Ipv4Addr> + SpecifiedAddress + Copy> From<SpecifiedAddr<A>> for Ipv4Addr
impl<A: Into<Ipv4Addr> + SpecifiedAddress + Copy> From<SpecifiedAddr<A>> for Ipv4Addr
source§fn from(addr: SpecifiedAddr<A>) -> Ipv4Addr
fn from(addr: SpecifiedAddr<A>) -> Ipv4Addr
source§impl FromBytes for Ipv4Addr
impl FromBytes for Ipv4Addr
§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 Ipv4Addr
impl<I: Ip> GenericOverIp<I> for Ipv4Addr
source§impl IntoBytes for Ipv4Addr
impl IntoBytes for Ipv4Addr
§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 Ipv4Addr
impl IpAddress for Ipv4Addr
source§fn to_ip_addr(&self) -> IpAddr
fn to_ip_addr(&self) -> IpAddr
source§fn common_prefix_len(&self, other: &Ipv4Addr) -> u8
fn common_prefix_len(&self, other: &Ipv4Addr) -> 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 Ipv4Addrwhere
Self: Sized,
impl KnownLayout for Ipv4Addrwhere
Self: Sized,
§type PointerMetadata = ()
type PointerMetadata = ()
Self
. Read moresource§impl LinkLocalAddress for Ipv4Addr
impl LinkLocalAddress for Ipv4Addr
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
Ipv4::LINK_LOCAL_UNICAST_SUBNET
or
Ipv4::LINK_LOCAL_MULTICAST_SUBNET
.
source§impl Ord for Ipv4Addr
impl Ord for Ipv4Addr
source§impl PartialEq for Ipv4Addr
impl PartialEq for Ipv4Addr
source§impl PartialOrd for Ipv4Addr
impl PartialOrd for Ipv4Addr
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 Ipv4Addr
impl ScopeableAddress for Ipv4Addr
source§impl TryFromBytes for Ipv4Addr
impl TryFromBytes for Ipv4Addr
§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,
impl Copy for Ipv4Addr
impl Eq for Ipv4Addr
impl Immutable for Ipv4Addr
impl StructuralPartialEq for Ipv4Addr
impl Unaligned for Ipv4Addr
Auto Trait Implementations§
impl Freeze for Ipv4Addr
impl RefUnwindSafe for Ipv4Addr
impl Send for Ipv4Addr
impl Sync for Ipv4Addr
impl Unpin for Ipv4Addr
impl UnwindSafe for Ipv4Addr
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
.