Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance_ of the Response class by parsing the message reponse.
        /// </summary>
        /// <param name="message">A byte array that contains the response message.</param>
        internal Response(byte[] message) {
            if (message == null)
                throw new ArgumentException("message");

            // ID - 16 bits

            // QR - 1 bit
            // Opcode - 4 bits
            // AA, TC, RD - 3 bits
            byte flags1 = message[2];

            // RA, Z - 2 bits
            // RCODE - 4 bits
            byte flags2 = message[3];

            long counts = message[3];

            // adjust the return code
            int return_code = (flags2 & (byte)0x3c) >> 2;
            return_code_ = (return_code > 6) ? ReturnCode.Other : (ReturnCode)return_code;

            // other bit flags
            authoritative_answer_ = ((flags1 & 4) != 0);
            recursion_available_ = ((flags2 & 128) != 0);
            truncated_ = ((flags1 & 2) != 0);

            // create the arrays of response objects
            questions_ = new Question[GetShort(message, 4)];
            answers_ = new Answer[GetShort(message, 6)];
            name_servers_ = new NameServer[GetShort(message, 8)];
            additional_records_ = new AdditionalRecord[GetShort(message, 10)];

            // need a pointer to do this, position just after the header
            RecordPointer pointer = new RecordPointer(message, 12);

            // and now populate them, they always follow this order
            for (int i = 0; i < questions_.Length; i++) {
                try {
                    questions_[i] = new Question(pointer);
                } catch(Exception ex) {
                    throw new InvalidResponseException(ex);
                }
            }

            for (int i = 0; i < answers_.Length; i++) {
                answers_[i] = new Answer(pointer);
            }

            for (int i = 0; i < name_servers_.Length; i++) {
                name_servers_[i] = new NameServer(pointer);
            }

            for (int i = 0; i < additional_records_.Length; i++) {
                additional_records_[i] = new AdditionalRecord(pointer);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a question to the request to be sent to the DNS server.
        /// </summary>
        /// <param name="question">The DNS question to add to the request.</param>
        public void AddQuestion(Question question) {
            if(question == null)
                throw new ArgumentNullException("question");

            questions_.Add(question);
        }
Exemplo n.º 3
0
 public void NewQuestionDomainBad() {
     Question question = new Question("$$$$$.com", DnsType.MX, DnsClass.IN);
 }
Exemplo n.º 4
0
 public void NewQuestionBadType() {
     unchecked {
         Question question = new Question("codeproject.com", (DnsType)1999, DnsClass.IN);
     }
 }
Exemplo n.º 5
0
 public void NewQuestionDomainNull() {
     Question question = new Question(null, DnsType.MX, DnsClass.IN);
 }