Пример #1
0
        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;
                }
            }
        }
Пример #2
0
        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;
                }
            }
        }
Пример #3
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);
            }
        }
Пример #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();
 }
Пример #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();
 }
Пример #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());
        }
Пример #7
0
 public PTRERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
Пример #8
0
 public CNAMERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
Пример #9
0
 public ARecord(DnsReader br)
 {
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Пример #10
0
 public TXTRecord(DnsReader br)
 {
     _txtData = br.ReadString();
 }
Пример #11
0
 public NSRecord(DnsReader br)
 {
     _domainName = br.ReadDomain();
 }
Пример #12
0
 public ARecord(DnsReader br)
 {
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Пример #13
0
 internal Question(DnsReader br)
 {
     _domain = br.ReadDomain();
     _qtype = (RecordType)br.ReadInt16();
     _qclass = (RecordClass)br.ReadInt16();
 }
Пример #14
0
 public NBRecord(DnsReader br)
 {
     _flags = br.ReadUInt16();
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Пример #15
0
 public NSRecord(DnsReader br)
 {
     _domainName = br.ReadDomain();
 }
Пример #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);
        }
Пример #17
0
 public Authority(DnsReader br)
     : base(br)
 {
 }
Пример #18
0
 public TXTRecord(DnsReader br)
 {
     _txtData = br.ReadString();
 }
Пример #19
0
 public Additional(DnsReader br)
     : base(br)
 {
 }
Пример #20
0
 internal Question(DnsReader br)
 {
     _domain = br.ReadDomain();
     _qtype  = (RecordType)br.ReadInt16();
     _qclass = (RecordClass)br.ReadInt16();
 }
Пример #21
0
 public CNAMERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
Пример #22
0
 public Additional(DnsReader br) : base(br)
 {
 }
Пример #23
0
 public Answer(DnsReader br) : base(br)
 {
 }
Пример #24
0
 public NBRecord(DnsReader br)
 {
     _flags     = br.ReadUInt16();
     _ipAddress = new IPAddress(br.ReadBytes(4));
 }
Пример #25
0
 public PTRERecord(DnsReader br)
 {
     _domain = br.ReadDomain();
 }
Пример #26
0
 public Authority(DnsReader br) : base(br)
 {
 }
Пример #27
0
 public Answer(DnsReader br)
     : base(br)
 {
 }
Пример #28
0
 public MXRecord(DnsReader br)
 {
     _preference = br.ReadInt16();
     _domainName = br.ReadDomain();
 }