コード例 #1
0
        internal static DnsDataResourceRecord Parse(DnsDatagram dns, int offsetInDns, out int numBytesRead)
        {
            DnsDomainName domainName;
            DnsType       type;
            DnsClass      dnsClass;

            if (!DnsResourceRecord.TryParseBase(dns, offsetInDns, out domainName, out type, out dnsClass, out numBytesRead))
            {
                return((DnsDataResourceRecord)null);
            }
            if (offsetInDns + numBytesRead + 6 > dns.Length)
            {
                return((DnsDataResourceRecord)null);
            }
            int    ttl = dns.ReadInt(offsetInDns + numBytesRead, Endianity.Big);
            ushort num = dns.ReadUShort(offsetInDns + numBytesRead + 4, Endianity.Big);

            numBytesRead += 6;
            if (offsetInDns + numBytesRead + (int)num > dns.Length)
            {
                return((DnsDataResourceRecord)null);
            }
            DnsResourceData data = DnsResourceData.Read(dns, type, offsetInDns + numBytesRead, (int)num);

            if (data == null)
            {
                return((DnsDataResourceRecord)null);
            }
            numBytesRead += (int)num;
            if (type == DnsType.Opt)
            {
                return((DnsDataResourceRecord) new DnsOptResourceRecord(domainName, dnsClass, ttl, data));
            }
            return(new DnsDataResourceRecord(domainName, type, dnsClass, ttl, data));
        }
コード例 #2
0
        internal static DnsDataResourceRecord Parse(DnsDatagram dns, int offsetInDns, out int numBytesRead)
        {
            DnsDomainName domainName;
            DnsType       type;
            DnsClass      dnsClass;

            if (!TryParseBase(dns, offsetInDns, out domainName, out type, out dnsClass, out numBytesRead))
            {
                return(null);
            }

            if (offsetInDns + numBytesRead + MinimumLengthAfterBase > dns.Length)
            {
                return(null);
            }

            int    ttl        = dns.ReadInt(offsetInDns + numBytesRead + OffsetAfterBase.Ttl, Endianity.Big);
            ushort dataLength = dns.ReadUShort(offsetInDns + numBytesRead + OffsetAfterBase.DataLength, Endianity.Big);

            numBytesRead += MinimumLengthAfterBase;
            if (offsetInDns + numBytesRead + dataLength > dns.Length)
            {
                return(null);
            }
            DnsResourceData data = DnsResourceData.Read(dns, type, offsetInDns + numBytesRead, dataLength);

            if (data == null)
            {
                return(null);
            }
            numBytesRead += dataLength;

            if (type == DnsType.Opt)
            {
                return(new DnsOptResourceRecord(domainName, dnsClass, ttl, data));
            }
            return(new DnsDataResourceRecord(domainName, type, dnsClass, ttl, data));
        }