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

            DnsType      typeCovered         = (DnsType)dns.ReadUShort(offsetInDns + Offset.TypeCovered, Endianity.Big);
            DnsAlgorithm algorithm           = (DnsAlgorithm)dns[offsetInDns + Offset.Algorithm];
            byte         labels              = dns[offsetInDns + Offset.Labels];
            uint         originalTtl         = dns.ReadUInt(offsetInDns + Offset.OriginalTtl, Endianity.Big);
            uint         signatureExpiration = dns.ReadUInt(offsetInDns + Offset.SignatureExpiration, Endianity.Big);
            uint         signatureInception  = dns.ReadUInt(offsetInDns + Offset.SignatureInception, Endianity.Big);
            ushort       keyTag              = dns.ReadUShort(offsetInDns + Offset.KeyTag, Endianity.Big);

            offsetInDns += ConstantPartLength;
            length      -= ConstantPartLength;

            DnsDomainName signersName;
            int           signersNameLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out signersName, out signersNameLength))
            {
                return(null);
            }
            offsetInDns += signersNameLength;
            length      -= signersNameLength;

            DataSegment signature = dns.Subsegment(offsetInDns, length);

            return(new DnsResourceDataSignature(typeCovered, algorithm, labels, originalTtl, signatureExpiration, signatureInception, keyTag, signersName, signature));
        }
Ejemplo n.º 2
0
        internal static bool TryRead(out ushort value, out DnsDomainName domainName,
                                     DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstantPartLength)
            {
                value      = 0;
                domainName = null;
                return(false);
            }
            value   = dns.ReadUShort(offsetInDns + Offset.Value, Endianity.Big);
            length -= ConstantPartLength;

            int domainNameLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns + Offset.DomainName, length, out domainName, out domainNameLength))
            {
                return(false);
            }
            length -= domainNameLength;

            if (length != 0)
            {
                return(false);
            }

            return(true);
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            DnsDomainName mainNameServer;
            int           domainNameLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out mainNameServer, out domainNameLength))
            {
                return(null);
            }
            offsetInDns += domainNameLength;
            length      -= domainNameLength;

            DnsDomainName responsibleMailbox;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out responsibleMailbox, out domainNameLength))
            {
                return(null);
            }
            offsetInDns += domainNameLength;
            length      -= domainNameLength;

            if (length != ConstantPartLength)
            {
                return(null);
            }

            uint serial     = dns.ReadUInt(offsetInDns + Offset.Serial, Endianity.Big);;
            uint refresh    = dns.ReadUInt(offsetInDns + Offset.Refresh, Endianity.Big);;
            uint retry      = dns.ReadUInt(offsetInDns + Offset.Retry, Endianity.Big);;
            uint expire     = dns.ReadUInt(offsetInDns + Offset.Expire, Endianity.Big);;
            uint minimumTtl = dns.ReadUInt(offsetInDns + Offset.MinimumTtl, Endianity.Big);;

            return(new DnsResourceDataStartOfAuthority(mainNameServer, responsibleMailbox, serial, refresh, retry, expire, minimumTtl));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstantPartLength)
            {
                return(null);
            }

            ushort priortiy = dns.ReadUShort(offsetInDns + Offset.Priority, Endianity.Big);
            ushort weight   = dns.ReadUShort(offsetInDns + Offset.Weight, Endianity.Big);
            ushort port     = dns.ReadUShort(offsetInDns + Offset.Port, Endianity.Big);

            DnsDomainName target;
            int           targetLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns + Offset.Target, length - ConstantPartLength, out target, out targetLength))
            {
                return(null);
            }

            if (ConstantPartLength + targetLength != length)
            {
                return(null);
            }

            return(new DnsResourceDataServerSelection(priortiy, weight, port, target));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 2)
            {
                return((DnsResourceData)null);
            }
            DnsDomainName domainName1;
            int           numBytesRead1;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - 1, out domainName1, out numBytesRead1))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead1;
            length      -= numBytesRead1;
            DnsDomainName domainName2;
            int           numBytesRead2;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName2, out numBytesRead2))
            {
                return((DnsResourceData)null);
            }
            if (length != numBytesRead2)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataTrustAnchorLink(domainName1, domainName2));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 18)
            {
                return((DnsResourceData)null);
            }
            DnsType      typeCovered = (DnsType)dns.ReadUShort(offsetInDns, Endianity.Big);
            DnsAlgorithm algorithm   = (DnsAlgorithm)dns[offsetInDns + 2];
            byte         labels      = dns[offsetInDns + 3];
            uint         originalTtl = dns.ReadUInt(offsetInDns + 4, Endianity.Big);
            uint         num1        = dns.ReadUInt(offsetInDns + 8, Endianity.Big);
            uint         num2        = dns.ReadUInt(offsetInDns + 12, Endianity.Big);
            ushort       keyTag      = dns.ReadUShort(offsetInDns + 16, Endianity.Big);

            offsetInDns += 18;
            length      -= 18;
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            DataSegment signature = dns.Subsegment(offsetInDns, length);

            return((DnsResourceData) new DnsResourceDataSignature(typeCovered, algorithm, labels, originalTtl, (SerialNumber32)num1, (SerialNumber32)num2, keyTag, domainName, signature));
        }
Ejemplo n.º 7
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            DnsDomainName nextDomainName;
            int           nextDomainNameLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out nextDomainName, out nextDomainNameLength))
            {
                return(null);
            }
            offsetInDns += nextDomainNameLength;
            length      -= nextDomainNameLength;

            if (length > MaxTypeBitmapLength)
            {
                return(null);
            }

            DataSegment typeBitmap = dns.Subsegment(offsetInDns, length);

            if (length != 0 && typeBitmap.Last == 0)
            {
                return(null);
            }

            return(new DnsResourceDataNextDomain(nextDomainName, typeBitmap));
        }
Ejemplo n.º 8
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 2)
            {
                return((DnsResourceData)null);
            }
            ushort preference = dns.ReadUShort(offsetInDns, Endianity.Big);

            offsetInDns += 2;
            length      -= 2;
            DnsDomainName domainName1;
            int           numBytesRead1;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName1, out numBytesRead1))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead1;
            length      -= numBytesRead1;
            DnsDomainName domainName2;
            int           numBytesRead2;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName2, out numBytesRead2))
            {
                return((DnsResourceData)null);
            }
            length -= numBytesRead2;
            if (length != 0)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataX400Pointer(preference, domainName1, domainName2));
        }
Ejemplo n.º 9
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            DnsDomainName domainName1;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName1, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            DnsDomainName domainName2;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName2, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            if (length != 20)
            {
                return((DnsResourceData)null);
            }
            uint num        = dns.ReadUInt(offsetInDns, Endianity.Big);
            uint refresh    = dns.ReadUInt(offsetInDns + 4, Endianity.Big);
            uint retry      = dns.ReadUInt(offsetInDns + 8, Endianity.Big);
            uint expire     = dns.ReadUInt(offsetInDns + 12, Endianity.Big);
            uint minimumTtl = dns.ReadUInt(offsetInDns + 16, Endianity.Big);

            return((DnsResourceData) new DnsResourceDataStartOfAuthority(domainName1, domainName2, (SerialNumber32)num, refresh, retry, expire, minimumTtl));
        }
Ejemplo n.º 10
0
        internal static DnsGateway CreateInstance(DnsGatewayType gatewayType, DnsDatagram dns, int offsetInDns, int length)
        {
            switch (gatewayType)
            {
            case DnsGatewayType.None:
                return(None);

            case DnsGatewayType.IpV4:
                if (length < IpV4Address.SizeOf)
                {
                    return(null);
                }
                return(new DnsGatewayIpV4(dns.ReadIpV4Address(offsetInDns, Endianity.Big)));

            case DnsGatewayType.IpV6:
                if (length < IpV6Address.SizeOf)
                {
                    return(null);
                }
                return(new DnsGatewayIpV6(dns.ReadIpV6Address(offsetInDns, Endianity.Big)));

            case DnsGatewayType.DomainName:
                DnsDomainName domainName;
                int           numBytesRead;
                if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
                {
                    return(null);
                }
                return(new DnsGatewayDomainName(domainName));

            default:
                return(null);
            }
        }
Ejemplo n.º 11
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < MinimumLength)
            {
                return(null);
            }

            DnsDomainName previous;
            int           previousLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - DnsDomainName.RootLength, out previous, out previousLength))
            {
                return(null);
            }
            offsetInDns += previousLength;
            length      -= previousLength;

            DnsDomainName next;
            int           nextLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out next, out nextLength))
            {
                return(null);
            }

            if (length != nextLength)
            {
                return(null);
            }

            return(new DnsResourceDataTrustAnchorLink(previous, next));
        }
Ejemplo n.º 12
0
 internal static bool TryParseBase(DnsDatagram dns, int offsetInDns, out DnsDomainName domainName, out DnsType type, out DnsClass dnsClass, out int numBytesRead)
 {
     type     = DnsType.Any;
     dnsClass = DnsClass.Any;
     if (!DnsDomainName.TryParse(dns, offsetInDns, dns.Length - offsetInDns, out domainName, out numBytesRead) || offsetInDns + numBytesRead + 4 > dns.Length)
     {
         return(false);
     }
     type          = (DnsType)dns.ReadUShort(offsetInDns + numBytesRead, Endianity.Big);
     dnsClass      = (DnsClass)dns.ReadUShort(offsetInDns + numBytesRead + 2, Endianity.Big);
     numBytesRead += 4;
     return(true);
 }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < MinimumLength)
            {
                return(null);
            }

            ushort order      = dns.ReadUShort(offsetInDns + Offset.Order, Endianity.Big);
            ushort preference = dns.ReadUShort(offsetInDns + Offset.Preference, Endianity.Big);

            DataSegment data       = dns.Subsegment(offsetInDns + ConstantPartLength, length - ConstantPartLength);
            int         dataOffset = 0;

            DataSegment flags = ReadString(data, ref dataOffset);

            if (flags == null || !IsLegalFlags(flags))
            {
                return(null);
            }

            DataSegment services = ReadString(data, ref dataOffset);

            if (services == null)
            {
                return(null);
            }

            DataSegment regexp = ReadString(data, ref dataOffset);

            if (regexp == null)
            {
                return(null);
            }

            DnsDomainName replacement;
            int           replacementLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns + ConstantPartLength + dataOffset, length - ConstantPartLength - dataOffset,
                                        out replacement, out replacementLength))
            {
                return(null);
            }

            if (ConstantPartLength + dataOffset + replacementLength != length)
            {
                return(null);
            }

            return(new DnsResourceDataNamingAuthorityPointer(order, preference, flags, services, regexp, replacement));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstantPartLength + DnsDomainName.RootLength)
            {
                return(null);
            }

            DnsDomainName algorithm;
            int           algorithmLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - ConstantPartLength, out algorithm, out algorithmLength))
            {
                return(null);
            }
            offsetInDns += algorithmLength;
            length      -= algorithmLength;

            if (length < ConstantPartLength)
            {
                return(null);
            }

            uint inception              = dns.ReadUInt(offsetInDns + OffsetAfterAlgorithm.Inception, Endianity.Big);
            uint expiration             = dns.ReadUInt(offsetInDns + OffsetAfterAlgorithm.Expiration, Endianity.Big);
            DnsTransactionKeyMode mode  = (DnsTransactionKeyMode)dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Mode, Endianity.Big);
            DnsResponseCode       error = (DnsResponseCode)dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Error, Endianity.Big);

            int keySize = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.KeySize, Endianity.Big);

            if (length < ConstantPartLength + keySize)
            {
                return(null);
            }
            DataSegment key = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.KeyData, keySize);

            int totalReadAfterAlgorithm = OffsetAfterAlgorithm.KeyData + keySize;

            offsetInDns += totalReadAfterAlgorithm;
            length      -= totalReadAfterAlgorithm;
            int otherSize = dns.ReadUShort(offsetInDns, Endianity.Big);

            if (length != sizeof(ushort) + otherSize)
            {
                return(null);
            }
            DataSegment other = dns.Subsegment(offsetInDns + sizeof(ushort), otherSize);

            return(new DnsResourceDataTransactionKey(algorithm, inception, expiration, mode, error, key, other));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstantPartLength + DnsDomainName.RootLength)
            {
                return(null);
            }

            DnsDomainName algorithm;
            int           algorithmLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - ConstantPartLength, out algorithm, out algorithmLength))
            {
                return(null);
            }
            offsetInDns += algorithmLength;
            length      -= algorithmLength;

            if (length < ConstantPartLength)
            {
                return(null);
            }

            UInt48 timeSigned = dns.ReadUInt48(offsetInDns + OffsetAfterAlgorithm.TimeSigned, Endianity.Big);
            ushort fudge      = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Fudge, Endianity.Big);
            int    messageAuthenticationCodeLength = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCodeSize, Endianity.Big);

            if (length < ConstantPartLength + messageAuthenticationCodeLength)
            {
                return(null);
            }
            DataSegment messageAuthenticationCode = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCode, messageAuthenticationCodeLength);
            int         totalReadAfterAlgorithm   = OffsetAfterAlgorithm.MessageAuthenticationCode + messageAuthenticationCodeLength;

            offsetInDns += totalReadAfterAlgorithm;
            length      -= totalReadAfterAlgorithm;

            ushort          originalId  = dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.OriginalId, Endianity.Big);
            DnsResponseCode error       = (DnsResponseCode)dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.Error, Endianity.Big);
            int             otherLength = dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherLength, Endianity.Big);

            if (length != OffsetAfterMessageAuthenticationCode.OtherData + otherLength)
            {
                return(null);
            }
            DataSegment other = dns.Subsegment(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherData, otherLength);

            return(new DnsResourceDataTransactionSignature(algorithm, timeSigned, fudge, messageAuthenticationCode, originalId, error, other));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            length -= numBytesRead;
            if (length != 0)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataDomainName(domainName));
        }
        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));
        }
        internal static List <DnsDomainName> ReadDomainNames(DnsDatagram dns, int offsetInDns, int length, int numExpected = 0)
        {
            List <DnsDomainName> list = new List <DnsDomainName>(numExpected);

            while (length != 0)
            {
                DnsDomainName domainName;
                int           numBytesRead;
                if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
                {
                    return((List <DnsDomainName>)null);
                }
                offsetInDns += numBytesRead;
                length      -= numBytesRead;
                list.Add(domainName);
            }
            return(list);
        }
Ejemplo n.º 19
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 17)
            {
                return((DnsResourceData)null);
            }
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - 16, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            if (length < 16)
            {
                return((DnsResourceData)null);
            }
            UInt48 timeSigned = dns.ReadUInt48(offsetInDns, Endianity.Big);
            ushort fudge      = dns.ReadUShort(offsetInDns + 6, Endianity.Big);
            int    length1    = (int)dns.ReadUShort(offsetInDns + 8, Endianity.Big);

            if (length < 16 + length1)
            {
                return((DnsResourceData)null);
            }
            DataSegment messageAuthenticationCode = dns.Subsegment(offsetInDns + 10, length1);
            int         num = 10 + length1;

            offsetInDns += num;
            length      -= num;
            ushort          originalId = dns.ReadUShort(offsetInDns, Endianity.Big);
            DnsResponseCode error      = (DnsResponseCode)dns.ReadUShort(offsetInDns + 2, Endianity.Big);
            int             length2    = (int)dns.ReadUShort(offsetInDns + 4, Endianity.Big);

            if (length != 6 + length2)
            {
                return((DnsResourceData)null);
            }
            DataSegment other = dns.Subsegment(offsetInDns + 6, length2);

            return((DnsResourceData) new DnsResourceDataTransactionSignature(domainName, timeSigned, fudge, messageAuthenticationCode, originalId, error, other));
        }
Ejemplo n.º 20
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 17)
            {
                return((DnsResourceData)null);
            }
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - 16, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            if (length < 16)
            {
                return((DnsResourceData)null);
            }
            uint num1 = dns.ReadUInt(offsetInDns, Endianity.Big);
            uint num2 = dns.ReadUInt(offsetInDns + 4, Endianity.Big);
            DnsTransactionKeyMode mode  = (DnsTransactionKeyMode)dns.ReadUShort(offsetInDns + 8, Endianity.Big);
            DnsResponseCode       error = (DnsResponseCode)dns.ReadUShort(offsetInDns + 10, Endianity.Big);
            int length1 = (int)dns.ReadUShort(offsetInDns + 12, Endianity.Big);

            if (length < 16 + length1)
            {
                return((DnsResourceData)null);
            }
            DataSegment key  = dns.Subsegment(offsetInDns + 14, length1);
            int         num3 = 14 + length1;

            offsetInDns += num3;
            length      -= num3;
            int length2 = (int)dns.ReadUShort(offsetInDns, Endianity.Big);

            if (length != 2 + length2)
            {
                return((DnsResourceData)null);
            }
            DataSegment other = dns.Subsegment(offsetInDns + 2, length2);

            return((DnsResourceData) new DnsResourceDataTransactionKey(domainName, (SerialNumber32)num1, (SerialNumber32)num2, mode, error, key, other));
        }
        internal static bool TryRead(out ushort value, out DnsDomainName domainName, DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 2)
            {
                value      = (ushort)0;
                domainName = (DnsDomainName)null;
                return(false);
            }
            value   = dns.ReadUShort(offsetInDns, Endianity.Big);
            length -= 2;
            int numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns + 2, length, out domainName, out numBytesRead))
            {
                return(false);
            }
            length -= numBytesRead;
            return(length == 0);
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            DnsTypeBitmaps instance = DnsTypeBitmaps.CreateInstance(dns.Buffer, dns.StartOffset + offsetInDns, length);

            if (instance == null)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataNextDomainSecure(domainName, instance));
        }
        internal static List <DnsDomainName> ReadDomainNames(DnsDatagram dns, int offsetInDns, int length, int numExpected = 0)
        {
            List <DnsDomainName> domainNames = new List <DnsDomainName>(numExpected);

            while (length != 0)
            {
                DnsDomainName domainName;
                int           domainNameLength;
                if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out domainNameLength))
                {
                    return(null);
                }
                offsetInDns += domainNameLength;
                length      -= domainNameLength;
                domainNames.Add(domainName);
            }

            return(domainNames);
        }
Ejemplo n.º 24
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 8)
            {
                return((DnsResourceData)null);
            }
            ushort      order      = dns.ReadUShort(offsetInDns, Endianity.Big);
            ushort      preference = dns.ReadUShort(offsetInDns + 2, Endianity.Big);
            DataSegment data       = dns.Subsegment(offsetInDns + 4, length - 4);
            int         offset     = 0;
            DataSegment flags      = DnsResourceData.ReadString(data, ref offset);

            if (flags == null || !DnsResourceDataNamingAuthorityPointer.IsLegalFlags(flags))
            {
                return((DnsResourceData)null);
            }
            DataSegment services = DnsResourceData.ReadString(data, ref offset);

            if (services == null)
            {
                return((DnsResourceData)null);
            }
            DataSegment regularExpression = DnsResourceData.ReadString(data, ref offset);

            if (regularExpression == null)
            {
                return((DnsResourceData)null);
            }
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns + 4 + offset, length - 4 - offset, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            if (4 + offset + numBytesRead != length)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataNamingAuthorityPointer(order, preference, flags, services, regularExpression, domainName));
        }
Ejemplo n.º 25
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));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            DnsDomainName nextDomainName;
            int           nextDomainNameLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out nextDomainName, out nextDomainNameLength))
            {
                return(null);
            }
            offsetInDns += nextDomainNameLength;
            length      -= nextDomainNameLength;

            DnsTypeBitmaps typeBitmaps = DnsTypeBitmaps.CreateInstance(dns.Buffer, dns.StartOffset + offsetInDns, length);

            if (typeBitmaps == null)
            {
                return(null);
            }

            return(new DnsResourceDataNextDomainSecure(nextDomainName, typeBitmaps));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstantPartLength)
            {
                return(null);
            }

            int hostIdentityTagLength = dns[offsetInDns + Offset.HostIdentityTagLength];
            DnsPublicKeyAlgorithm publicKeyAlgorithm = (DnsPublicKeyAlgorithm)dns[offsetInDns + Offset.PublicKeyAlgorithm];
            int publicKeyLength = dns.ReadUShort(offsetInDns + Offset.PublicKeyLength, Endianity.Big);

            if (length < ConstantPartLength + hostIdentityTagLength + publicKeyLength)
            {
                return(null);
            }
            DataSegment hostIdentityTag = dns.Subsegment(offsetInDns + Offset.HostIdentityTag, hostIdentityTagLength);
            int         publicKeyOffset = offsetInDns + ConstantPartLength + hostIdentityTagLength;
            DataSegment publicKey       = dns.Subsegment(publicKeyOffset, publicKeyLength);

            offsetInDns += ConstantPartLength + hostIdentityTagLength + publicKeyLength;
            length      -= ConstantPartLength + hostIdentityTagLength + publicKeyLength;

            List <DnsDomainName> rendezvousServers = new List <DnsDomainName>();

            while (length != 0)
            {
                DnsDomainName rendezvousServer;
                int           rendezvousServerLength;
                if (!DnsDomainName.TryParse(dns, offsetInDns, length, out rendezvousServer, out rendezvousServerLength))
                {
                    return(null);
                }
                rendezvousServers.Add(rendezvousServer);
                offsetInDns += rendezvousServerLength;
                length      -= rendezvousServerLength;
            }

            return(new DnsResourceDataHostIdentityProtocol(hostIdentityTag, publicKeyAlgorithm, publicKey, rendezvousServers));
        }
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 6)
            {
                return((DnsResourceData)null);
            }
            ushort        priority = dns.ReadUShort(offsetInDns, Endianity.Big);
            ushort        weight   = dns.ReadUShort(offsetInDns + 2, Endianity.Big);
            ushort        port     = dns.ReadUShort(offsetInDns + 4, Endianity.Big);
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns + 6, length - 6, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            if (6 + numBytesRead != length)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataServerSelection(priority, weight, port, domainName));
        }
Ejemplo n.º 29
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstantPartLength)
            {
                return(null);
            }

            ushort preference = dns.ReadUShort(offsetInDns + Offset.Preference, Endianity.Big);

            offsetInDns += ConstantPartLength;
            length      -= ConstantPartLength;

            DnsDomainName map822;
            int           map822Length;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out map822, out map822Length))
            {
                return(null);
            }
            offsetInDns += map822Length;
            length      -= map822Length;

            DnsDomainName mapX400;
            int           mapX400Length;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out mapX400, out mapX400Length))
            {
                return(null);
            }
            length -= mapX400Length;

            if (length != 0)
            {
                return(null);
            }

            return(new DnsResourceDataX400Pointer(preference, map822, mapX400));
        }
Ejemplo n.º 30
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            if (length > 16)
            {
                return((DnsResourceData)null);
            }
            DataSegment typeBitmap = dns.Subsegment(offsetInDns, length);

            if (length != 0 && (int)typeBitmap.Last == 0)
            {
                return((DnsResourceData)null);
            }
            return((DnsResourceData) new DnsResourceDataNextDomain(domainName, typeBitmap));
        }