public static IPAddress to_ipv6(IPAddress ia) { return(new IPAddress( IpBits.V6, ia.host_address, Prefix128.create(ia.prefix.num).unwrap(), null, IpV6.ipv6_is_private, IpV6.ipv6_is_loopback, IpV6.ipv6_to_ipv6)); }
public static Result <IPAddress> from_int(BigInteger bi, uint prefixNum) { var prefix = Prefix128.create(prefixNum); if (prefix.isErr()) { return(Result <IPAddress> .Err(prefix.unwrapErr())); } return(enhance_if_mapped(new IPAddress( IpBits.V6, bi, prefix.unwrap(), null, ipv6_is_private, ipv6_is_loopback, ipv6_to_ipv6))); }
/// Creates a new 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 new 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" /// public static Result <IPAddress> create(String str) { var splitted = IPAddress.Split_at_slash(str); if (IPAddress.is_valid_ipv6(splitted.addr)) { var o_num = IPAddress.split_to_num(splitted.addr); if (o_num.isErr()) { return(Result <IPAddress> .Err(o_num.unwrapErr())); } var netmask = 128u; if (splitted.netmask != null) { var network = splitted.netmask; var num_mask = IPAddress.parseInt(network, 10); if (!num_mask.HasValue) { return(Result <IPAddress> .Err("Invalid Netmask <<str>>")); } netmask = num_mask.Value; } var prefix = Prefix128.create(netmask); if (prefix.isErr()) { return(Result <IPAddress> .Err(prefix.unwrapErr())); } return(enhance_if_mapped(new IPAddress( IpBits.V6, o_num.unwrap(), prefix.unwrap(), null, ipv6_is_private, ipv6_is_loopback, ipv6_to_ipv6))); } return(Result <IPAddress> .Err("Invalid IP <<str>>")); }