예제 #1
0
        private static bool InternalTryParseCIDR(string expression, int sep, ref IPRange range)
        {
            range.format = IPRange.Format.Invalid;
            int length = expression.Length;

            if (sep == 0 || expression[sep] != '/')
            {
                return(false);
            }
            IPvxAddress baseAddress;

            if (!IPvxAddress.TryParse(expression.Substring(0, sep), out baseAddress))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(0, sep));
                return(false);
            }
            short cidrLength = 0;

            if (!short.TryParse(expression.Substring(sep + 1, length - sep - 1), out cidrLength))
            {
                range.exceptionMessage = DataStrings.InvalidCIDRLength(expression.Substring(sep + 1, length - sep - 1));
                return(false);
            }
            if (!range.IsValidCIDRLength(cidrLength, baseAddress.AddressFamily))
            {
                return(false);
            }
            if (!range.SetAddressesFromCIDR(baseAddress, cidrLength))
            {
                return(false);
            }
            range.format = IPRange.Format.CIDR;
            return(true);
        }
예제 #2
0
        private static bool InternalTryParseLoHi(string expression, int sep, ref IPRange range)
        {
            range.format = IPRange.Format.Invalid;
            int length = expression.Length;

            if (sep == 0 || expression[sep] != '-')
            {
                return(false);
            }
            IPvxAddress start;

            if (!IPvxAddress.TryParse(expression.Substring(0, sep), out start))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(0, sep));
                return(false);
            }
            IPvxAddress end;

            if (!IPvxAddress.TryParse(expression.Substring(sep + 1, length - sep - 1), out end))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(sep + 1, length - sep - 1));
                return(false);
            }
            range.SetAddresses(start, end);
            if (!range.ValidateAddressFamily())
            {
                return(false);
            }
            range.format = IPRange.Format.LoHi;
            return(true);
        }
예제 #3
0
        private static bool InternalTryParseSingleIPAddress(string expression, ref IPRange range)
        {
            range.format = IPRange.Format.Invalid;
            IPvxAddress pvxAddress;

            if (!IPvxAddress.TryParse(expression, out pvxAddress))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression);
                return(false);
            }
            range.SetAddresses(pvxAddress, pvxAddress);
            range.format = IPRange.Format.SingleAddress;
            return(true);
        }