create static method
Creates a IPv6 address object.
An IPv6 address can be expressed in any of the following forms:
- "2001:0db8:0000:0000:0008:0800:200C:417A": IPv6 address with no compression
- "2001:db8:0:0:8:800:200C:417A": IPv6 address with leading zeros compression
- "2001:db8::8:800:200C:417A": IPv6 address with full compression
In all these 3 cases, a IPv6 address object will be created, using the default subnet mask /128
You can also specify the subnet mask as with IPv4 addresses:
ip6 = IPAddress "2001:db8::8:800:200c:417a/64"
Implementation
/// An IPv6 address can be expressed in any of the following forms:
///
/// * "2001:0db8:0000:0000:0008:0800:200C:417A": IPv6 address with no compression
/// * "2001:db8:0:0:8:800:200C:417A": IPv6 address with leading zeros compression
/// * "2001:db8::8:800:200C:417A": IPv6 address with full compression
///
/// In all these 3 cases, a IPv6 address object will be created, using the default
/// subnet mask /128
///
/// You can also specify the subnet mask as with IPv4 addresses:
///
/// ip6 = IPAddress "2001:db8::8:800:200c:417a/64"
///
static Result<IPAddress, String> create(String str) {
final splitted = IPAddress.split_at_slash(str);
if (IPAddress.is_valid_ipv6(splitted.addr)) {
final o_num = IPAddress.split_to_num(splitted.addr);
if (o_num.isFailure) {
return Result.error(o_num.error);
}
var netmask = 128;
if (splitted.netmask != null) {
final network = splitted.netmask;
final num_mask = IPAddress.parseInt(network!, 10);
if (num_mask == null) {
return Result.error("Invalid Netmask ${str}");
}
netmask = num_mask.toInt();
}
final prefix = Prefix128.create(netmask);
if (prefix.isFailure) {
return Result.error(prefix.error);
}
return enhance_if_mapped(IPAddress(IpBits.V6, o_num.value, prefix.value,
null, ipv6_is_private, ipv6_is_loopback, ipv6_to_ipv6));
} else {
return Result.error("Invalid IP ${str}");
}
}