Beispiel #1
0
 /// <summary>
 /// Construct the question reading from a DNS Server response.
 /// </summary>
 /// <param name="pointer">A logical pointer to the Question in byte array form.</param>
 internal Question(RecordPointer pointer)
 {
     // extract from the pointer
     domain_    = pointer.GetDomain();
     dns_type_  = (DnsType)pointer.GetShort();
     dns_class_ = (DnsClass)pointer.GetShort();
 }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceRecord"/> class by using the specified
        /// pointer.
        /// </summary>
        /// <param name="pointer">The position in the byte array of the record.</param>
        internal ResourceRecord(RecordPointer pointer) {
            domain_ = pointer.GetDomain();
            dns_type_ = (DnsType)pointer.GetShort();
            dns_class_ = (DnsClass)pointer.GetShort();
            ttl_ = pointer.GetInt();

            // the next short is the record length, we only use it for unrecognised record types.
            int length = pointer.GetShort();
            switch(dns_type_) {
                case DnsType.MX:
                    record_ = new MXRecord(pointer);
                    break;

                default:
                    // move the pointer over this unrecognised record
                    pointer += length;
                    break;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceRecord"/> class by using the specified
        /// pointer.
        /// </summary>
        /// <param name="pointer">The position in the byte array of the record.</param>
        internal ResourceRecord(RecordPointer pointer)
        {
            domain_    = pointer.GetDomain();
            dns_type_  = (DnsType)pointer.GetShort();
            dns_class_ = (DnsClass)pointer.GetShort();
            ttl_       = pointer.GetInt();

            // the next short is the record length, we only use it for unrecognised record types.
            int length = pointer.GetShort();

            switch (dns_type_)
            {
            case DnsType.MX:
                record_ = new MXRecord(pointer);
                break;

            default:
                // move the pointer over this unrecognised record
                pointer += length;
                break;
            }
        }
Beispiel #5
0
 internal AdditionalRecord(RecordPointer pointer) : base(pointer)
 {
 }
 internal AdditionalRecord(RecordPointer pointer) : base(pointer) { }
Beispiel #7
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);
            }
        }
Beispiel #8
0
 internal Answer(RecordPointer pointer) : base(pointer) { }
Beispiel #9
0
 internal NameServer(RecordPointer pointer) : base(pointer)
 {
 }
Beispiel #10
0
 /// <summary>
 /// Construct the question reading from a DNS Server response.
 /// </summary>
 /// <param name="pointer">A logical pointer to the Question in byte array form.</param>
 internal Question(RecordPointer pointer) {
     // extract from the pointer
     domain_ = pointer.GetDomain();
     dns_type_ = (DnsType)pointer.GetShort();
     dns_class_ = (DnsClass)pointer.GetShort();
 }
Beispiel #11
0
 internal Answer(RecordPointer pointer) : base(pointer)
 {
 }
Beispiel #12
0
 /// <summary>
 /// Initializes a nes instance_ of the MXRecord class by using the specified pointer.
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 internal MXRecord(RecordPointer pointer)
 {
     preference_  = pointer.GetShort();
     domain_name_ = pointer.GetDomain();
 }
Beispiel #13
0
 internal NameServer(RecordPointer pointer) : base(pointer) { }