Esempio n. 1
0
        private static IRecord ReadRecord(ByteReader byteReader)
        {
            var name   = DnsUtils.ReadName(byteReader);
            var rtype  = byteReader.GetUshort();
            var rclass = byteReader.GetUshort();
            var ttl    = byteReader.GetUint();

            if ((RecordType)rtype == RecordType.NS)
            {
                var record = new NSRecord()
                {
                    Name   = name,
                    RClass = rclass,
                    Ttl    = ttl,
                };
                var rdlength = byteReader.GetUshort();
                record.Host = ReadName(byteReader);
                return(record);
            }
            else if ((RecordType)rtype == RecordType.A)
            {
                var rdlength = byteReader.GetUshort();
                var ipv4     = ReadIpv4(byteReader);
                var record   = new ARecord(name, ipv4)
                {
                    RClass = rclass,
                    Ttl    = ttl,
                };
                return(record);
            }
            else if ((RecordType)rtype == RecordType.AAAA)
            {
                var rdlength = byteReader.GetUshort();
                var ipv6     = ReadIpv6(byteReader);
                var record   = new AaaaRecord(name, ipv6)
                {
                    RClass = rclass,
                    Ttl    = ttl,
                };
                return(record);
            }
            else
            {
                var record = new Record()
                {
                    Name   = name,
                    RType  = rtype,
                    RClass = (ushort)rclass,
                    Ttl    = ttl,
                };
                var rdlength = byteReader.GetUshort();
                record.RData = byteReader.GetBytes(rdlength);
                return(record);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Arguments:
        /// 0: domainName
        /// 1: nameServer
        /// 2: ttl (optional)
        /// 3: notes (optional)
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public DnsRecord ParseNS(string[] args)
        {
            string domainName = args.GetRequiredValue(0);
            string nameServer = args.GetRequiredValue(1);
            int    ttl        = this.ValidateTTL(args.GetOptionalValue <int>(2, 0));
            string notes      = args.GetOptionalValue(3, string.Empty);

            NSRecord nsRecord = new NSRecord(domainName, nameServer)
            {
                TTL = ttl
            };
            DnsRecord dnsRecord = new DnsRecord(domainName, DnsStandard.RecordType.NS, nsRecord.Serialize(), notes);

            return(dnsRecord);
        }
Esempio n. 3
0
        /// <summary>
        /// Tests equality between this NS record and the other <paramref name="record"/>.
        /// </summary>
        /// <param name="record">The other record.</param>
        /// <returns><c>true</c> if the RRs are equal, <c>false</c> otherwise.</returns>
        public override bool Equals(DnsResourceRecord record)
        {
            if (!base.Equals(record))
            {
                return(false);
            }

            NSRecord nsRecord = record as NSRecord;

            if (nsRecord == null)
            {
                return(false);
            }

            return(DnsStandard.Equals(m_nameserver, nsRecord.NameServer));
        }
        public void SerializeNSRecord()
        {
            var serializer = GetRrSerializer();
            var ns         = new NSRecord()
            {
                Name       = "www.",
                TimeToLive = 343,
                DName      = "aaa."
            };

            byte[] expected = { 0x03, 0x77, 0x77, 0x77, 0x00,
                                0x00, 0x02,
                                0x00, 0x01,
                                0x00, 0x00, 0x01, 0x57,
                                0x00, 0x05,
                                0x03, 0x61, 0x61, 0x61, 0x00 };

            var serialized = ns.ToByteArray();

            Assert.AreEqual(expected, serialized);
        }