public ResourceRecord(DnsReader br)
        {
            _domain = br.ReadDomain();
            _qtype = (RecordType)br.ReadInt16();
            _qclass = (RecordClass)br.ReadInt16();
            _ttl = br.ReadInt32();

            int recordLength = br.ReadInt16();
            if (recordLength != 0)
            {
                switch (_qtype)
                {
                    case RecordType.A:     _record = new ARecord(br);      break;
                    case RecordType.CNAME: _record = new CNAMERecord(br);  break;
                    case RecordType.MX:    _record = new MXRecord(br);     break;
                    case RecordType.NS:    _record = new NSRecord(br);     break;
                    case RecordType.SOA:   _record = new SOARecord(br);    break;
                    case RecordType.TXT:   _record = new TXTRecord(br);    break;
					case RecordType.PTR:   _record = new PTRERecord(br);	break;

                    // NetBIOS related records
                    case RecordType.NB:    _record = new NBRecord(br);     break;
                    
                    default:
                        br += recordLength;
                        break;
                }
            }
        }
        public ResourceRecord(DnsReader br)
        {
            _domain = br.ReadDomain();
            _qtype = (RecordType)br.ReadInt16();
            _qclass = (RecordClass)br.ReadInt16();
            _ttl = br.ReadInt32();

            int recordLength = br.ReadInt16();
            if (recordLength != 0)
            {
                switch (_qtype)
                {
                    case RecordType.A:     _record = new ARecord(br);      break;
                    case RecordType.CNAME: _record = new CNAMERecord(br);  break;
                    case RecordType.MX:    _record = new MXRecord(br);     break;
                    case RecordType.NS:    _record = new NSRecord(br);     break;
                    case RecordType.SOA:   _record = new SOARecord(br);    break;
                    case RecordType.TXT:   _record = new TXTRecord(br);    break;
                    case RecordType.PTR:   _record = new PTRERecord(br);	break;

                    // NetBIOS related records
                    case RecordType.NB:    _record = new NBRecord(br);     break;

                    default:
                        br += recordLength;
                        break;
                }
            }
        }
        public DnsMessage(byte[] data)
        {
            Timestamp = DateTime.Now;
            DnsReader byteReader = new DnsReader(data);

            // Header
            Header = new Header(byteReader);

            // Question, Answer, Authority, Additional Counts
            Questions   = new Question[this.QuestionRecordCount];
            Answers     = new Answer[this.AnswerRecordCount];
            Authorities = new Authority[this.AuthorityRecordCount];
            Additionals = new Additional[this.AdditionalRecordCount];

            // Read Records
            for (int i = 0; i < this.QuestionRecordCount; i++)
            {
                this.Questions[i] = new Question(byteReader);
            }

            for (int i = 0; i < this.AnswerRecordCount; i++)
            {
                this.Answers[i] = new Answer(byteReader);
            }

            for (int i = 0; i < this.AuthorityRecordCount; i++)
            {
                this.Authorities[i] = new Authority(byteReader);
            }

            for (int i = 0; i < this.AdditionalRecordCount; i++)
            {
                this.Additionals[i] = new Additional(byteReader);
            }
        }
Beispiel #4
0
 public SOARecord(DnsReader br)
 {
     _mname = br.ReadDomain();
     _rname = br.ReadDomain();
     _serial = br.ReadInt32();
     _refresh = br.ReadInt32();
     _retry = br.ReadInt32();
     _expire = br.ReadInt32();
     _minimumTtl = br.ReadInt32();
 }
Beispiel #5
0
 public SOARecord(DnsReader br)
 {
     _mname      = br.ReadDomain();
     _rname      = br.ReadDomain();
     _serial     = br.ReadInt32();
     _refresh    = br.ReadInt32();
     _retry      = br.ReadInt32();
     _expire     = br.ReadInt32();
     _minimumTtl = br.ReadInt32();
 }
Beispiel #6
0
        /// <summary>
        /// Reads a domain name from the byte array. (RFC 1035 - 4.1.4.)
        /// </summary>
        public string ReadDomain()
        {
            StringBuilder domain = new StringBuilder();
            int           length = 0;

            while ((length = ReadByte()) != 0)
            {
                // top 2 bits set denotes domain name compression and to reference elsewhere
                if ((length & 0xc0) == 0xc0)
                {
                    // work out the existing domain name, copy this pointer
                    DnsReader newPointer = Copy();

                    // and move it to where specified here
                    newPointer.Position = (length & 0x3f) << 8 | ReadByte();

                    // repeat call recursively
                    domain.Append(newPointer.ReadDomain());
                    return(domain.ToString());
                }

                // if not using compression, copy a char at a time to the domain name
                while (length > 0)
                {
                    domain.Append(ReadChar());
                    length--;
                }

                // if size of next label isn't null (end of domain name) add a period ready for next label
                if (Peek() != 0)
                {
                    domain.Append('.');
                }
            }

            return(domain.ToString());
        }
Beispiel #7
0
 public PTRERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
 public CNAMERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
Beispiel #9
0
 public ARecord(DnsReader br)
 {
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Beispiel #10
0
 public TXTRecord(DnsReader br)
 {
     _txtData = br.ReadString();
 }
Beispiel #11
0
 public NSRecord(DnsReader br)
 {
     _domainName = br.ReadDomain();
 }
Beispiel #12
0
 public ARecord(DnsReader br)
 {
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Beispiel #13
0
 internal Question(DnsReader br)
 {
     _domain = br.ReadDomain();
     _qtype = (RecordType)br.ReadInt16();
     _qclass = (RecordClass)br.ReadInt16();
 }
Beispiel #14
0
 public NBRecord(DnsReader br)
 {
     _flags = br.ReadUInt16();
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Beispiel #15
0
 public NSRecord(DnsReader br)
 {
     _domainName = br.ReadDomain();
 }
Beispiel #16
0
        public DnsMessage(byte[] data)
        {
            Timestamp = DateTime.Now;
            DnsReader byteReader = new DnsReader(data);

            // Header
            Header = new Header(byteReader);

            // Question, Answer, Authority, Additional Counts
            Questions = new Question[this.QuestionRecordCount];
            Answers = new Answer[this.AnswerRecordCount];
            Authorities = new Authority[this.AuthorityRecordCount];
            Additionals = new Additional[this.AdditionalRecordCount];

            // Read Records
            for (int i = 0; i < this.QuestionRecordCount; i++)
                this.Questions[i] = new Question(byteReader);

            for (int i = 0; i < this.AnswerRecordCount; i++)
                this.Answers[i] = new Answer(byteReader);

            for (int i = 0; i < this.AuthorityRecordCount; i++)
                this.Authorities[i] = new Authority(byteReader);

            for (int i = 0; i < this.AdditionalRecordCount; i++)
                this.Additionals[i] = new Additional(byteReader);
        }
Beispiel #17
0
 public Authority(DnsReader br)
     : base(br)
 {
 }
Beispiel #18
0
 public TXTRecord(DnsReader br)
 {
     _txtData = br.ReadString();
 }
Beispiel #19
0
 public Additional(DnsReader br)
     : base(br)
 {
 }
Beispiel #20
0
 internal Question(DnsReader br)
 {
     _domain = br.ReadDomain();
     _qtype  = (RecordType)br.ReadInt16();
     _qclass = (RecordClass)br.ReadInt16();
 }
Beispiel #21
0
 public CNAMERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
Beispiel #22
0
 public Additional(DnsReader br) : base(br)
 {
 }
Beispiel #23
0
 public Answer(DnsReader br) : base(br)
 {
 }
Beispiel #24
0
 public NBRecord(DnsReader br)
 {
     _flags     = br.ReadUInt16();
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Beispiel #25
0
 public PTRERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
Beispiel #26
0
 public Authority(DnsReader br) : base(br)
 {
 }
Beispiel #27
0
 public Answer(DnsReader br)
     : base(br)
 {
 }
Beispiel #28
0
 public MXRecord(DnsReader br)
 {
     _preference = br.ReadInt16();
     _domainName = br.ReadDomain();
 }