Example #1
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 #2
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 #3
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 SPF specification.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="specification">The SPF specification.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="specification"/> is
        /// <see langword="null"/>.
        /// </exception>
        public SpfRecord(DnsName owner, TimeSpan ttl, string specification)
            : base(owner, DnsRecordType.Spf, DnsRecordClass.IN, ttl)
        {
            Guard.NotNull(specification, "specification");

            _specification = specification;
        }
Example #4
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 #5
0
        /// <summary>
        /// Resolves and returns a <see cref="AK.Net.Dns.DnsName"/> instance for
        /// each of the authoritative name servers for the specified
        /// <paramref name="domain"/>.
        /// </summary>
        /// <param name="domain">The domain.</param>
        /// <returns>
        /// The list of <see cref="AK.Net.Dns.DnsName"/> instances for each of the
        /// authoritative name servers for the specified <paramref name="domain"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="domain"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsTransportException">
        /// Thrown when a transport error occurs.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsResolutionException">
        /// Thrown when an error occurs during the resolution, such as the query
        /// not being answered.
        /// </exception>
        public virtual DnsName[] GetNameServers(DnsName domain)
        {
            DnsName  qname = AppendNameSuffix(domain);
            DnsReply reply = Resolve(new DnsQuestion(qname, DnsQueryType.NS, DnsQueryClass.IN));

            return(reply.Answers.Where(F.IsNS).Select(x => F.ToNS(x).Domain).ToArray());
        }
 private DnsResponse(ushort messageId, DnsName queryName, RecordType queryType, RecordClass queryClass)
 {
     this.MessageId = messageId;
     this.QueryName = queryName;
     this.QueryType = queryType;
     this.QueryClass = queryClass;
 }
Example #7
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 #8
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 text of the record.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="text">The text.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> or <paramref name="text"/> is
        /// <see langword="null"/>.
        /// </exception>
        public TxtRecord(DnsName owner, TimeSpan ttl, string text)
            : base(owner, DnsRecordType.Txt, DnsRecordClass.IN, ttl)
        {
            Guard.NotNull(text, "text");

            _text = text;
        }
Example #9
0
        public void all_predicates()
        {
            XRecord record;
            DnsName owner = DnsName.Parse("test.com.");

            byte[]          rdata          = new byte[0];
            DnsRecordType[] allRecordTypes = (DnsRecordType[])Enum.GetValues(typeof(DnsRecordType));

            foreach (PredicateTestCase @case in PREDICATE_TEST_CASES)
            {
                Assert.IsFalse(@case.Predicate(null));
                foreach (DnsRecordType type in @case.Types)
                {
                    record = new XRecord(owner, type, DnsRecordClass.IN, TimeSpan.FromHours(1), rdata);
                    Assert.IsTrue(@case.Predicate(record), "{0} expected to return true for {1}", @case.Predicate.Method, type);
                }
                foreach (DnsRecordType type in allRecordTypes)
                {
                    if ([email protected](type))
                    {
                        record = new XRecord(owner, type, DnsRecordClass.IN, TimeSpan.FromHours(1), rdata);
                        Assert.IsFalse(@case.Predicate(record), "{0} expected to return false for {1}", @case.Predicate.Method, type);
                    }
                }
            }
        }
Example #10
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;
        }
Example #11
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 #12
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 #13
0
        public void Terminates_With_Null_Byte_On_Valid_Name()
        {
            var name = new DnsName("test.local");
            var result = name.ToByteArray();

            Assert.That(result.Last(), Is.EqualTo((byte)0));
        }
Example #14
0
        /// <summary>
        /// Initialises a new instance of the ARecord class and specifies the owner name,
        /// the resource record class, the TTL of the record and the owner's IP address.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="address">The owner's IP address.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/> <paramref name="address"/> 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 ARecord(DnsName owner, TimeSpan ttl, IPAddress address)
            : base(owner, DnsRecordType.A, DnsRecordClass.IN, ttl)
        {
            Guard.IsIPv4(address, "address");

            _address = address;
        }
Example #15
0
        public static NameEntry FromByteArray(ResourceRecord.RecordType type, byte[] arr, int payloadBase, int offset, out int size)
        {
            NameEntry ret = new NameEntry(type);

            ret.name = DnsName.FromByteArray(arr, payloadBase, offset, out size);
            return(ret);
        }
 public void Write(DnsName dnsName)
 {
     using (var writer = new DnsWriter(0, this.stream))
     {
         this.rootLabelNode.Write(dnsName, writer);
     }
 }
Example #17
0
        /// <summary>
        /// Writes the specified name to the underlying stream.
        /// </summary>
        /// <param name="name">The name to write.</param>
        /// <param name="compress"><see langword="true"/> if the name can be
        /// compressed, otherwise; <see langword="false"/>.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="name"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// Thrown when the writer has been disposed of.
        /// </exception>
        public void WriteName(DnsName name, bool compress)
        {
            Guard.NotNull(name, "name");

            CheckDisposed();

            if (!compress)
            {
                // Do not cache references to names that should not be compressed.
                foreach (string label in name.Labels)
                {
                    WriteLabel(label);
                }
                this.Buffer.WriteByte(0);
            }
            else if (this.References.ContainsKey(name.Name))
            {
                WritePtr(this.References[name.Name]);
            }
            else
            {
                bool           terminate = true;
                string         subDomain = name.Name;
                IList <string> labels    = name.Labels;

                if (labels.Count > 0)
                {
                    SaveReference(subDomain);
                    WriteLabel(labels[0]);
                    if (labels.Count > 1)
                    {
                        subDomain = subDomain.Substring(labels[0].Length + 1);
                        for (int i = 1; i < labels.Count; ++i)
                        {
                            if (this.References.ContainsKey(subDomain))
                            {
                                WritePtr(this.References[subDomain]);
                                // Pointers aren't terminated.
                                terminate = false;
                                break;
                            }
                            else
                            {
                                SaveReference(subDomain);
                                WriteLabel(labels[i]);
                                if (i < labels.Count - 1)
                                {
                                    subDomain = subDomain.Substring(labels[i].Length + 1);
                                }
                            }
                        }
                    }
                }
                if (terminate)
                {
                    this.Buffer.WriteByte(0);
                }
            }
        }
Example #18
0
        private static DnsName ReadName(byte[] buffer, int offset, out int next)
        {
            StringBuilder sb = new StringBuilder();

            ReadName(sb, buffer, offset, 0, out next);

            return(DnsName.Parse(sb.ToString()));
        }
Example #19
0
        /// <summary>
        /// Makes an SRV query name for the specified <paramref name="service"/>,
        /// <paramref name="protocol"/> and <paramref name="name"/>.
        /// </summary>
        /// <param name="service">The requested service.</param>
        /// <param name="protocol">The requested protocol.</param>
        /// <param name="name">The name.</param>
        /// <returns>The SRV query name for the specified <paramref name="service"/>,
        /// <paramref name="protocol"/> and <paramref name="name"/>.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="service"/>, <paramref name="protocol"/> or
        /// <paramref name="name"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the format of the resultant name is invalid because of:
        /// <list type="bullet">
        /// <item><paramref name="service"/> contains invalid characters</item>
        /// <item>the length <paramref name="service"/> is greater than the maximum label
        /// length</item>
        /// <item><paramref name="protocol"/> contains invalid characters</item>
        /// <item>the length <paramref name="protocol"/> is greater than the maximum label
        /// length</item>
        /// <item>the length of the resultant name is greater than
        /// <see cref="AK.Net.Dns.DnsName.MaxLength"/></item>
        /// </list>
        /// </exception>
        public static DnsName MakeName(string service, string protocol, DnsName name)
        {
            Guard.NotNull(service, "service");
            Guard.NotNull(protocol, "protocol");
            Guard.NotNull(name, "name");

            return(DnsName.Parse(string.Format("_{0}._{1}.{2}", service, protocol, name.Name)));
        }
Example #20
0
        /// <summary>
        /// Appends the <see cref="AK.Net.Dns.Resolvers.DnsResolver.NameSuffix"/> to the
        /// specified <paramref name="name"/> if <paramref name="name"/> is not
        /// absolute and <see cref="AK.Net.Dns.Resolvers.DnsResolver.NameSuffix"/> is not
        /// <see langword="null"/>.
        /// </summary>
        /// <param name="name">The name to append to.</param>
        /// <returns>A new name.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="name"/> is <see langword="null"/>.
        /// </exception>
        protected DnsName AppendNameSuffix(DnsName name)
        {
            Guard.NotNull(name, "name");

            DnsName suffix = this.NameSuffix;

            return(suffix != null && name.Kind == DnsNameKind.Relative ?
                   name.Concat(suffix) : name);
        }
Example #21
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 #22
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 #23
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();
        }
 public byte[] GetBytes(DnsName dnsName)
 {
     using (var stream = new MemoryStream())
     using (var writer = new DnsWriter(this.stream.Position, stream))
     {
         this.Write(dnsName, writer);
         return stream.ToArray();
     }
 }
Example #25
0
            /// <summary>
            /// Initialses a new instance of the Node class and specifies the records the node is
            /// to contain and a value indicating if the records are from an authoratative source.
            /// </summary>
            /// <param name="records">The resource records.</param>
            /// <param name="isAuthoratative">True if the records are from an authoratative source,
            /// otherwise; false.</param>
            public Node(DnsRecord[] records, bool isAuthoratative)
            {
                Guard.NotNull(records, "records");

                _isAuth  = isAuthoratative;
                _records = records;
                _owner   = _records[0].Owner;
                _type    = _records[0].GetType();
            }
Example #26
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 #27
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 #28
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 #29
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 #30
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;
        }
 protected DnsMessageBase(ushort messageId, DnsName queryName, RecordType queryType, RecordClass queryClass)
     : this()
 {
     this.MessageId = messageId;
     this.QueryCount = 1;
     this.QueryName = queryName;
     this.QueryType = queryType;
     this.QueryClass = queryClass;
 }
Example #32
0
        /// <summary>
        /// Initialises a new instance of the ARecord 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="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 ARecord(DnsName owner, TimeSpan ttl, IDnsReader reader)
            : base(owner, DnsRecordType.A, DnsRecordClass.IN, ttl)
        {
            Guard.NotNull(reader, "reader");

            // Skip the RDLENGTH.
            reader.ReadUInt16();
            _address = reader.ReadIPv4Address();
        }
Example #33
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();
        }
 public EquivalenceClassCollection <DnsQuestion> GetEquivalenceClasses()
 {
     return(EquivalenceClassCollection <DnsQuestion> .FromDistinctInstances(
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.Any),
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.CH),
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.HS),
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.IN),
                new DnsQuestion(DnsName.Parse("test.co.uk"), DnsQueryType.A, DnsQueryClass.IN)
                ));
 }
Example #35
0
        /// <summary>
        /// Initialises a new instance of the TxtRecord class and specifies the owner name,
        /// the resource record class, the TTL of the record, the host address, protocol and
        /// the map of services supported.
        /// </summary>
        /// <param name="owner">The owner name.</param>
        /// <param name="ttl">The TTL.</param>
        /// <param name="address">The address of the host.</param>
        /// <param name="protocol">The host protocol.</param>
        /// <param name="bitmap">The services supported by the host.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="owner"/>, <paramref name="address"/> or
        /// <paramref name="bitmap"/> 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 WksRecord(DnsName owner, TimeSpan ttl, IPAddress address, byte protocol, BitArray bitmap)
            : base(owner, DnsRecordType.Wks, DnsRecordClass.IN, ttl)
        {
            Guard.IsIPv4(address, "address");
            Guard.NotNull(bitmap, "bitmap");

            _address  = address;
            _protocol = protocol;
            _bitmap   = bitmap;
        }
Example #36
0
        public void Returns_Correctly_For_Two_Label_Name()
        {
            var name = new DnsName("host.com");
            var result = name.ToByteArray();

            Assert.That(result.Length, Is.EqualTo(10));
            for (int i = 0; i < host_dot_com_dnsname.Length; i++)
            {
                Assert.That(result[i], Is.EqualTo(host_dot_com_dnsname[i]));
            }
        }
        protected ResourceRecordBase(DnsName name, RecordType recordType, RecordClass recordClass, uint timeToLive)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.Name = name;
            this.RecordType = recordType;
            this.RecordClass = recordClass;
            this.TimeToLive = timeToLive;
        }
Example #38
0
 public void Extract_Name_Correctly_From_Well_Formed_Question_In_Dns_Response()
 {
     var parser = new DnsNameParser(test_dot_cocktail_dot_local_A_Record);
     var result = new DnsName(parser ,test_dot_cocktail_dot_local_A_Record, 12);
     Assert.That(result.Host, Is.EqualTo("test.cocktail.local"));
 }
Example #39
0
        public void Sets_Host_Property_Correctly()
        {
            var result = new DnsName("test.local");

            Assert.That(result.Host, Is.EqualTo("test.local"));
        }
 public CnameResourceRecord(DnsQuery query, uint timeToLive, DnsName dnsName)
     : base(query, timeToLive)
 {
     this.dnsName = dnsName;
 }
Example #41
0
 public void Extract_Name_Correctly_From_Well_Formed_Answer_In_Dns_Response_That_Involves_Lookback()
 {
     var parser = new DnsNameParser(test_dot_cocktail_dot_local_A_Record);
     var result = new DnsName(parser, test_dot_cocktail_dot_local_A_Record, 49);
     Assert.That(result.Host, Is.EqualTo("voip-1.cocktail.local"));
 }
 private void Write(DnsName dnsName, DnsWriter dnsWriter)
 {
     this.rootLabelNode.Write(dnsName, dnsWriter);
 }
Example #43
0
 public void Extracts_Name_Correctly_From_Well_Formed_Question_In_Dns_Response()
 {
     var parser = new DnsNameParser(ultraasp_dot_net_A_Record);
     var result = new DnsName(parser, ultraasp_dot_net_A_Record , 12);
     Assert.That(result.Host, Is.EqualTo("ultraasp.net"));
 }