예제 #1
0
        internal static DnsResourceData Read(DnsDatagram dns, DnsType type, int offsetInDns, int length)
        {
            DnsResourceData prototype = TryGetPrototype(type);

            if (prototype != null)
            {
                return(prototype.CreateInstance(dns, offsetInDns, length));
            }
            return(new DnsResourceDataAnything(dns.Subsegment(offsetInDns, length)));
        }
예제 #2
0
        /// <summary>
        /// Returns the DnsResourceData concrete type that should be created for the given DnsType.
        /// </summary>
        public static Type GetDnsResourceDataType(DnsType dnsType)
        {
            DnsResourceData prototype = TryGetPrototype(dnsType);

            if (prototype == null)
            {
                return(null);
            }
            return(prototype.GetType());
        }
예제 #3
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));
        }
예제 #4
0
 /// <summary>
 /// Creates a resource record from domain name, type, class, ttl and data.
 /// </summary>
 /// <param name="domainName">An owner name, i.e., the name of the node to which this resource record pertains.</param>
 /// <param name="type">Two octets containing one of the RR TYPE codes.</param>
 /// <param name="dnsClass">Two octets containing one of the RR CLASS codes.</param>
 /// <param name="ttl">
 /// A 32 bit signed integer that specifies the time interval that the resource record may be cached before the source of the information should again be consulted.
 /// Zero values are interpreted to mean that the RR can only be used for the transaction in progress, and should not be cached.
 /// For example, SOA records are always distributed with a zero TTL to prohibit caching.
 /// Zero values can also be used for extremely volatile data.
 /// </param>
 /// <param name="data">
 /// A variable length string of octets that describes the resource.
 /// The format of this information varies according to the TYPE and CLASS of the resource record.
 /// For example, the if the TYPE is A and the CLASS is IN, the RDATA field is a 4 octet ARPA Internet address.
 /// </param>
 public DnsDataResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass, int ttl, DnsResourceData data)
     : base(domainName, type, dnsClass)
 {
     Ttl  = ttl;
     Data = data;
 }
예제 #5
0
 internal DnsOptResourceRecord(DnsDomainName domainName, DnsClass dnsClass, int ttl, DnsResourceData data)
     : base(domainName, DnsType.Opt, dnsClass, ttl, data)
 {
 }