internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < MinimumLength)
            {
                return(null);
            }

            byte prefixLength = dns[offsetInDns + Offset.PrefixLength];

            if (prefixLength > MaxPrefixLength)
            {
                return(null);
            }
            offsetInDns += ConstantPartLength;
            length      -= ConstantPartLength;

            int addressSuffixLength = CalculateAddressSuffixLength(prefixLength);

            if (length < addressSuffixLength)
            {
                return(null);
            }
            IpV6Address addressSuffix = new IpV6Address((UInt128)dns.ReadUnsignedBigInteger(offsetInDns, addressSuffixLength, Endianity.Big));

            offsetInDns += addressSuffixLength;
            length      -= addressSuffixLength;

            if (IsAddressSuffixTooSmall(prefixLength, addressSuffix) || IsAddressSuffixTooBig(prefixLength, addressSuffix))
            {
                return(null);
            }

            DnsDomainName prefixName;
            int           prefixNameLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out prefixName, out prefixNameLength))
            {
                return(null);
            }
            if (prefixNameLength != length)
            {
                return(null);
            }

            return(new DnsResourceDataA6(prefixLength, addressSuffix, prefixName));
        }
Esempio n. 2
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 2)
            {
                return((DnsResourceData)null);
            }
            byte prefixLength = dns[offsetInDns];

            if ((int)prefixLength > 128)
            {
                return((DnsResourceData)null);
            }
            ++offsetInDns;
            --length;
            int length1 = DnsResourceDataA6.CalculateAddressSuffixLength(prefixLength);

            if (length < length1)
            {
                return((DnsResourceData)null);
            }
            IpV6Address addressSuffix = new IpV6Address((UInt128)dns.ReadUnsignedBigInteger(offsetInDns, length1, Endianity.Big));

            offsetInDns += length1;
            length      -= length1;
            if (DnsResourceDataA6.IsAddressSuffixTooSmall(prefixLength, addressSuffix) || DnsResourceDataA6.IsAddressSuffixTooBig(prefixLength, addressSuffix))
            {
                return((DnsResourceData)null);
            }
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            if (numBytesRead != length)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataA6(prefixLength, addressSuffix, domainName));
        }