Beispiel #1
0
        public static Result <IPAddress> from_u32(UInt32 addr, uint _prefix)
        {
            var prefix = Prefix32.create(_prefix);

            if (prefix.isErr())
            {
                return(Result <IPAddress> .Err(prefix.unwrapErr()));
            }
            return(Result <IPAddress> .Ok(new IPAddress(
                                              IpBits.v4(),
                                              new BigInteger(addr),
                                              prefix.unwrap(),
                                              null,
                                              ipv4_is_private,
                                              ipv4_is_loopback,
                                              to_ipv6
                                              )));
        }
Beispiel #2
0
        public static Result <IPAddress> create(string str)
        {
            var splitted = IPAddress.Split_at_slash(str);

            if (!IPAddress.is_valid_ipv4(splitted.addr))
            {
                return(Result <IPAddress> .Err("Invalid IP <<str>>"));
            }
            var ip_prefix_num = Result <uint> .Ok(32);

            if (splitted.netmask != null)
            {
                //  netmask is defined
                ip_prefix_num = IPAddress.parse_netmask_to_prefix(splitted.netmask);
                if (ip_prefix_num.isErr())
                {
                    return(Result <IPAddress> .Err(ip_prefix_num.unwrapErr()));
                }
                //if ip_prefix.ip_bits.version
            }
            var ip_prefix = Prefix32.create(ip_prefix_num.unwrap());

            if (ip_prefix.isErr())
            {
                return(Result <IPAddress> .Err(ip_prefix.unwrapErr()));
            }
            var split_u32 = IPAddress.split_to_u32(splitted.addr);

            if (split_u32.isErr())
            {
                return(Result <IPAddress> .Err(split_u32.unwrapErr()));
            }
            return(Result <IPAddress> .Ok(new IPAddress(IpBits.V4,
                                                        new BigInteger(split_u32.unwrap()),
                                                        ip_prefix.unwrap(),
                                                        null,
                                                        ipv4_is_private, ipv4_is_loopback, to_ipv6)));
        }