Example #1
0
        /// <summary>
        /// Initialises a new instance of the MBRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the mailbox for the owner
        /// name.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="mailbox">The domain mailbox.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="mailbox"/> is
        /// <see langword="null"/>.
        /// </exception>
        public MBRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, DnsName mailbox)
            : base(owner, DnsRecordType.MG, cls, ttl)
        {
            Guard.NotNull(mailbox, "mailbox");

            _mailbox = mailbox;
        }
Example #2
0
        /// <summary>
        /// Initialises a new instance of the PtrRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the domain name pointer.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="domain">The domain name of <paramref name="owner"/>'s authoritative
        /// name server.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> <paramref name="domain"/> is
        /// <see langword="null"/>.
        /// </exception>
        public PtrRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, DnsName domain)
            : base(owner, DnsRecordType.Ptr, cls, ttl)
        {
            Guard.NotNull(domain, "domain");

            _domain = domain;
        }
Example #3
0
        /// <summary>
        /// Initialises a new instance of the NSRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the record data.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="data">The resource record data.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> <paramref name="data"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// Thrown when <paramref name="address"/> is not of the
        /// <see cref="System.Net.Sockets.AddressFamily.InterNetwork"/> family.
        /// </exception>
        public NullRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, byte[] data)
            : base(owner, DnsRecordType.Null, cls, ttl)
        {
            Guard.NotNull(data, "data");

            _data = data;
        }
Example #4
0
        /// <summary>
        /// Initialises a new instance of the CNameRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the canonical name of the
        /// owner name.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="canonical">The canonical name of the owner name.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="canonical"/> is
        /// <see langword="null"/>.
        /// </exception>
        public CNameRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, DnsName canonical)
            : base(owner, DnsRecordType.CName, cls, ttl)
        {
            Guard.NotNull(canonical, "canonical");

            _canonical = canonical;
        }
Example #5
0
        /// <summary>
        /// Initialises a new instance of the MRRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the new mailbox for the
        /// owner name.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="newMailbox">The new mailbox.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="mailbox"/> is
        /// <see langword="null"/>.
        /// </exception>
        public MRRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, DnsName newMailbox)
            : base(owner, DnsRecordType.MG, cls, ttl)
        {
            Guard.NotNull(newMailbox, "newMailbox");

            _newMailbox = newMailbox;
        }
Example #6
0
        /// <summary>
        /// Initialises a new instance of the NullRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public NullRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.Null, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            _data = reader.ReadBytes(reader.ReadUInt16());
        }
Example #7
0
        /// <summary>
        /// Initialises a new instance of the DNRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the redirection target.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="target">The canonical name of the owner name.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="target"/> is
        /// <see langword="null"/>.
        /// </exception>
        public DNRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, DnsName target)
            : base(owner, DnsRecordType.CName, cls, ttl)
        {
            Guard.NotNull(target, "target");

            _target = target;
        }
 public DnsResourceRecord(DnsDomain domain, byte[] data, DnsRecordType type, DnsRecordClass klass = DnsRecordClass.IN, TimeSpan ttl = default)
 {
     Name       = domain;
     Type       = type;
     Class      = klass;
     TimeToLive = ttl;
     Data       = data;
 }
Example #9
0
 public DnsTxtRecord(string hostname, DnsRecordClass @class, uint ttl, params string[] strings)
     : base(hostname, DnsRecordType.Txt, @class, ttl)
 {
     if (strings != null)
     {
         Strings.AddRange(strings);
     }
 }
Example #10
0
 public DnsSrvRecord(string hostname, DnsRecordClass @class, uint ttl, ushort priority, ushort weight, ushort port, string srvHostname)
     : base(hostname, DnsRecordType.Srv, @class, ttl)
 {
     Priority    = priority;
     Weight      = weight;
     Port        = port;
     SrvHostname = srvHostname;
 }
Example #11
0
        /// <summary>
        /// Resolves the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="recordType">Type of the record.</param>
        /// <param name="recordClass">The record class.</param>
        /// <returns>Task&lt;DnsMessage&gt;.</returns>
        public async Task <DnsMessage> Resolve(string name, DnsRecordType recordType,
                                               DnsRecordClass recordClass = DnsRecordClass.IN)
        {
            var dnsMessage = await GetDnsClient().ResolveAsync(DomainName.Parse(name), (RecordType)recordType.IntValue,
                                                               (RecordClass)(int)recordClass);

            return(dnsMessage);
        }
Example #12
0
        /// <summary>
        /// Initialises a new instance of the TxtRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public TxtRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.Txt, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _text = reader.ReadCharString();
        }
Example #13
0
        /// <summary>
        /// Initialises a new instance of the MInfoRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record, the responsible mailbox and the
        /// mailbox to which errors are sent.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="rMbox">The domain name of the mailbox which is responsible for the mailing
        /// list or mailbox.</param>
        /// <param name="eMbox">The domain name of the mailbox which errors are mailed to.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> <paramref name="rMbox"/> <paramref name="eMbox"/> is
        /// <see langword="null"/>.
        /// </exception>
        public MInfoRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, DnsName rMbox, DnsName eMbox)
            : base(owner, DnsRecordType.HInfo, cls, ttl)
        {
            Guard.NotNull(rMbox, "rMbox");
            Guard.NotNull(eMbox, "eMbox");

            _rMbox = rMbox;
            _eMbox = eMbox;
        }
Example #14
0
        /// <summary>
        /// Initialises a new instance of the MXRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record, the preference of the mail
        /// exchange and the domain of the exchange itself.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="exchange">The domain name of the exchange.</param>
        /// <param name="preference">The preference of the exchange.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> <paramref name="exchange"/> is
        /// <see langword="null"/>.
        /// </exception>
        public MXRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, short preference,
                        DnsName exchange)
            : base(owner, DnsRecordType.MX, cls, ttl)
        {
            Guard.NotNull(exchange, "exchange");

            _preference = preference;
            _exchange   = exchange;
        }
Example #15
0
        /// <summary>
        /// Initialises a new instance of the SpfRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public SpfRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.Spf, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _specification = reader.ReadCharString();
        }
Example #16
0
        /// <summary>
        /// Reads <see cref="AK.Net.Dns.DnsRecord"/> from the underlying data stream.
        /// </summary>
        /// <returns>
        /// A <see cref="AK.Net.Dns.DnsRecord"/> from the underlying source stream.
        /// </returns>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the number of bytes remaining on the underlying data stream
        /// is not sufficient to satify the requirments of the operation.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// Thrown when the reader has been disposed of.
        /// </exception>
        public DnsRecord ReadRecord()
        {
            DnsName        owner = ReadName();
            DnsRecordType  type  = ReadRecordType();
            DnsRecordClass cls   = ReadRecordClass();
            TimeSpan       ttl   = ReadTtl();

            return(DnsRecord.GetBuilder(type).Build(owner, type, cls, ttl, this));
        }
Example #17
0
        /// <summary>
        /// Initialises a new instance of the MRRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public MRRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.MR, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _newMailbox = reader.ReadName();
        }
Example #18
0
        /// <summary>
        /// Initialises a new instance of the CNameRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public CNameRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.CName, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _canonical = reader.ReadName();
        }
Example #19
0
        /// <summary>
        /// Initialises a new instance of the PtrRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public PtrRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.Ptr, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _domain = reader.ReadName();
        }
Example #20
0
 public DnsRecordAlias(string name, DnsRecordType type, DnsRecordClass cls, bool unique, byte[] body, byte[] fullPacket)
     : base(name, type, cls, unique, body)
 {
     using (MemoryStream ms = new MemoryStream(body, false))
         using (BinaryReader br = new BinaryReader(ms))
         {
             _alias = ReadName(br, fullPacket);
         }
 }
Example #21
0
        /// <summary>
        /// Initialises a new instance of the HInfoRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record, the CPU type and the OS type
        /// of the host.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="cpu">The CPU type.</param>
        /// <param name="os">The OS type.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> <paramref name="cpu"/> <paramref name="os"/> is
        /// <see langword="null"/>.
        /// </exception>
        public HInfoRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, string cpu, string os)
            : base(owner, DnsRecordType.HInfo, cls, ttl)
        {
            Guard.NotNull(cpu, "cpu");
            Guard.NotNull(os, "os");

            _cpu = cpu;
            _os  = os;
        }
Example #22
0
 public ResourceRecord(Domain domain, byte[] data, DnsRecordType type,
                       DnsRecordClass klass = DnsRecordClass.IN, TimeSpan ttl = default(TimeSpan))
 {
     this.domain = domain;
     this.type   = type;
     this.klass  = klass;
     this.ttl    = ttl;
     this.data   = data;
 }
Example #23
0
        public DefaultDnsPtrRecord(string name, DnsRecordClass dnsClass, long timeToLive, string hostname)
            : base(name, DnsRecordType.PTR, timeToLive, dnsClass)
        {
            if (string.IsNullOrWhiteSpace(hostname))
            {
                throw new ArgumentNullException(hostname);
            }

            HostName = hostname;
        }
Example #24
0
        /// <summary>
        /// Initialises a new instance of the DnsRecord class and specifies the
        /// owner name, the resource record class and the TTL of the record.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="type">The class of resource record.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> is <see langword="null"/>.
        /// </exception>
        protected DnsRecord(DnsName owner, DnsRecordType type, DnsRecordClass cls, TimeSpan ttl)
        {
            Guard.NotNull(owner, "owner");

            _owner   = owner;
            _type    = type;
            _class   = cls;
            _ttl     = ttl;
            _expires = DnsClock.Now() + ttl;
        }
Example #25
0
        /// <summary>
        /// Initialises a new instance of the MXRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public MXRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.MX, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _preference = reader.ReadInt16();
            _exchange   = reader.ReadName();
        }
Example #26
0
        public DnsAAAARecord(string hostname, DnsRecordClass @class, uint ttl, IPAddress ipAddress)
            : base(hostname, DnsRecordType.AAAA, @class, ttl)
        {
            if (ipAddress.AddressFamily != AddressFamily.InterNetworkV6)
            {
                throw new InvalidDataException("IPAddress should be of type AddressFamily InterNetwork");
            }

            IPAddress = ipAddress;
        }
Example #27
0
        public DnsQuestion(string name, DnsRecordType type, DnsRecordClass cls, bool unique)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            _name = name;
            _type = type;
            _class = cls;
            _unique = unique;
        }
Example #28
0
        protected IDnsRecord DecodeRecord(string name, DnsRecordType type, DnsRecordClass dnsClass, long timeToLive,
                                          IByteBuffer inputBuffer, int offset, int length)
        {
            if (type == DnsRecordType.PTR)
            {
                return(new DefaultDnsPtrRecord(name, dnsClass, timeToLive, DecodeName(inputBuffer.SetIndex(offset, offset + length))));
            }

            return(new DefaultDnsRawRecord(name, type, dnsClass, timeToLive, inputBuffer.SetIndex(offset, offset + length)));
        }
Example #29
0
        /// <summary>
        /// Initialises a new instance of the SrvRecord class and specifies the owner name,
        /// the resource record class, the TTL, priority, weight, port and location of the
        /// service.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="priority">The service priority.</param>
        /// <param name="weight">The weight of the service over other services with the
        /// same priority.</param>
        /// <param name="port">The service port.</param>
        /// <param name="target">The service location.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="target"/> is
        /// <see langword="null"/>.
        /// </exception>
        public SrvRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, int priority, int weight,
                         int port, DnsName target)
            : base(owner, DnsRecordType.Srv, cls, ttl)
        {
            Guard.NotNull(target, "target");

            _priority = priority;
            _weight   = weight;
            _port     = port;
            _target   = target;
        }
Example #30
0
        private DnsQuestion ReadQuestion(BinaryReader br, byte[] fullPacket)
        {
            string         name   = ReadName(br, fullPacket);
            DnsRecordType  type   = (DnsRecordType)IPAddress.NetworkToHostOrder(br.ReadInt16());
            DnsRecordClass cls    = (DnsRecordClass)IPAddress.NetworkToHostOrder(br.ReadInt16());
            bool           unique = (cls & DnsRecordClass.CLASS_UNIQUE) != 0;

            cls = cls & DnsRecordClass.CLASS_MASK;

            return(new DnsQuestion(name, type, cls, unique));
        }
Example #31
0
        private IDnsQueryAnswer GetDnsQueryAnswer(IDnsNameParser parser, DnsName name, DnsRecordType recordType, DnsRecordClass recordClass, UInt32 ttl, short recordDataLength, int recordDataOffset, byte[] packetContent)
        {
            var answer = GetDnsQueryAnswer(parser, recordType, recordDataLength, null, packetContent, recordDataOffset);
            answer.Name = name;
            answer.RecordType = recordType;
            answer.RecordClass = recordClass;
            answer.Ttl = ttl;
            answer.RecordDataLength = recordDataLength;
            //answer.RecordData = recordData;

            return answer;
        }
Example #32
0
        /// <summary>
        /// Initialises a new instance of the SrvRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the reply reader from
        /// which the RDLENGTH and RDATA section of the resource record will be read.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="cls">The class of resource record.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="reader">The reply reader.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="reader"/> is
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the RDATA section of the record could not be read from the
        /// <paramref name="reader"/>.
        /// </exception>
        public SrvRecord(DnsName owner, DnsRecordClass cls, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.Srv, cls, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _priority = reader.ReadUInt16();
            _weight   = reader.ReadUInt16();
            _port     = reader.ReadUInt16();
            _target   = reader.ReadName();
        }
Example #33
0
        internal static DnsRecord Create(string name, DnsRecordType type, DnsRecordClass cls, bool unique, byte[] body, byte[] fullPacket)
        {
            switch(type)
            {
                case DnsRecordType.A:
                case DnsRecordType.AAAA:
                    return new DnsRecordAddress(name, type, cls, unique, body);

                case DnsRecordType.TXT:
                    return new DnsRecordText(name, type, cls, unique, body);

                case DnsRecordType.CNAME:
                case DnsRecordType.PTR:
                    return new DnsRecordAlias(name, type, cls, unique, body, fullPacket);

                case DnsRecordType.SRV:
                    return new DnsRecordServer(name, type, cls, unique, body, fullPacket);

                default:
                    return new DnsRecord(name, type, cls, unique, body);
            }
        }
Example #34
0
 public DnsRecordAlias(string name, DnsRecordType type, DnsRecordClass cls, bool unique, byte[] body, byte[] fullPacket)
     : base(name, type, cls, unique, body)
 {
     using(MemoryStream ms = new MemoryStream(body, false))
     using (BinaryReader br = new BinaryReader(ms))
     {
         _alias = ReadName(br, fullPacket);
     }
 }
Example #35
0
 public DnsRecordAddress(string name, DnsRecordType type, DnsRecordClass cls, bool unique, byte[] body)
     : base(name, type, cls, unique, body)
 {
     if (type == DnsRecordType.A && body.Length == 4)
         _addr = new IPAddress(body);
     else if (type == DnsRecordType.AAAA && body.Length == 16)
         _addr = new IPAddress(body);
     else
         throw new InvalidOperationException();
 }
Example #36
0
 public DnsRecordServer(string name, DnsRecordType type, DnsRecordClass cls, bool unique, byte[] body, byte[] fullPacket)
     : base(name, type, cls, unique, body)
 {
     using (MemoryStream ms = new MemoryStream(body, false))
     using (BinaryReader br = new BinaryReader(ms))
     {
         _prio = unchecked((ushort)IPAddress.NetworkToHostOrder(br.ReadInt16()));
         _weight = unchecked((ushort)IPAddress.NetworkToHostOrder(br.ReadInt16()));
         _port = unchecked((ushort)IPAddress.NetworkToHostOrder(br.ReadInt16()));
         _name = ReadName(br, fullPacket);
     }
 }
Example #37
0
 public DnsRecordText(string name, DnsRecordType type, DnsRecordClass cls, bool unique, byte[] body)
     : base(name, type, cls, unique, body)
 {
     _text = Encoding.UTF8.GetString(body);
 }