Struct kaspa_utils::networking::IpAddress
source · #[repr(transparent)]pub struct IpAddress(pub IpAddr);Expand description
An IP address, newtype of IpAddr.
Tuple Fields§
§0: IpAddrImplementations§
source§impl IpAddress
impl IpAddress
pub fn new(ip: IpAddr) -> Self
pub fn is_publicly_routable(&self) -> bool
pub fn prefix_bucket(&self) -> PrefixBucket
Methods from Deref<Target = IpAddr>§
1.12.0 · sourcepub fn is_unspecified(&self) -> bool
pub fn is_unspecified(&self) -> bool
Returns true for the special ‘unspecified’ address.
See the documentation for Ipv4Addr::is_unspecified() and
Ipv6Addr::is_unspecified() for more details.
§Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)).is_unspecified(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)).is_unspecified(), true);1.12.0 · sourcepub fn is_loopback(&self) -> bool
pub fn is_loopback(&self) -> bool
Returns true if this is a loopback address.
See the documentation for Ipv4Addr::is_loopback() and
Ipv6Addr::is_loopback() for more details.
§Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).is_loopback(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1)).is_loopback(), true);sourcepub fn is_global(&self) -> bool
🔬This is a nightly-only experimental API. (ip)
pub fn is_global(&self) -> bool
ip)Returns true if the address appears to be globally routable.
See the documentation for Ipv4Addr::is_global() and
Ipv6Addr::is_global() for more details.
§Examples
#![feature(ip)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(80, 9, 12, 3)).is_global(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1)).is_global(), true);1.12.0 · sourcepub fn is_multicast(&self) -> bool
pub fn is_multicast(&self) -> bool
Returns true if this is a multicast address.
See the documentation for Ipv4Addr::is_multicast() and
Ipv6Addr::is_multicast() for more details.
§Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(224, 254, 0, 0)).is_multicast(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0)).is_multicast(), true);sourcepub fn is_documentation(&self) -> bool
🔬This is a nightly-only experimental API. (ip)
pub fn is_documentation(&self) -> bool
ip)Returns true if this address is in a range designated for documentation.
See the documentation for Ipv4Addr::is_documentation() and
Ipv6Addr::is_documentation() for more details.
§Examples
#![feature(ip)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_documentation(), true);
assert_eq!(
IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_documentation(),
true
);sourcepub fn is_benchmarking(&self) -> bool
🔬This is a nightly-only experimental API. (ip)
pub fn is_benchmarking(&self) -> bool
ip)Returns true if this address is in a range designated for benchmarking.
See the documentation for Ipv4Addr::is_benchmarking() and
Ipv6Addr::is_benchmarking() for more details.
§Examples
#![feature(ip)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(198, 19, 255, 255)).is_benchmarking(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);1.16.0 · sourcepub fn is_ipv4(&self) -> bool
pub fn is_ipv4(&self) -> bool
Returns true if this address is an IPv4 address, and false
otherwise.
§Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false);1.16.0 · sourcepub fn is_ipv6(&self) -> bool
pub fn is_ipv6(&self) -> bool
Returns true if this address is an IPv6 address, and false
otherwise.
§Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true);1.75.0 · sourcepub fn to_canonical(&self) -> IpAddr
pub fn to_canonical(&self) -> IpAddr
Converts this address to an IpAddr::V4 if it is an IPv4-mapped IPv6 addresses, otherwise it
returns self as-is.
§Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
let localhost_v4 = Ipv4Addr::new(127, 0, 0, 1);
assert_eq!(IpAddr::V4(localhost_v4).to_canonical(), localhost_v4);
assert_eq!(IpAddr::V6(localhost_v4.to_ipv6_mapped()).to_canonical(), localhost_v4);
assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).to_canonical().is_loopback(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).is_loopback(), false);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true);