예제 #1
0
 private void ReadAdditionalRecords(Pointer pointer)
 {
     for (int index = 0; index < _additionalRecords.Length; index++)
     {
         _additionalRecords[index] = new AdditionalRecord(pointer);
     }
 }
예제 #2
0
        // these are fields we're interested in from the message

        /// <summary>
        ///     Construct a Response object from the supplied byte array
        /// </summary>
        /// <param name="message">a byte array returned from a DNS server query</param>
        internal Response(byte[] message)
        {
            // the bit flags are in bytes 2 and 3
            var flags1 = message[2];
            var flags2 = message[3];

            // get return code from lowest 4 bits of byte 3
            var returnCode = flags2 & 15;

            // if its in the reserved section, set to other
            if (returnCode > 6)
            {
                returnCode = 6;
            }
            ReturnCode = (ReturnCode)returnCode;

            // other bit flags
            AuthoritativeAnswer = (flags1 & 4) != 0;
            RecursionAvailable  = (flags2 & 128) != 0;
            MessageTruncated    = (flags1 & 2) != 0;

            // create the arrays of response objects
            Questions         = new Question[GetShort(message, 4)];
            Answers           = new Answer[GetShort(message, 6)];
            NameServers       = new NameServer[GetShort(message, 8)];
            AdditionalRecords = new AdditionalRecord[GetShort(message, 10)];

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

            // and now populate them, they always follow this order
            for (var index = 0; index < Questions.Length; index++)
            {
                try
                {
                    // try to build a quesion from the response
                    Questions[index] = new Question(pointer);
                }
                catch (Exception ex)
                {
                    // something grim has happened, we can't continue
                    throw new InvalidResponseException(ex);
                }
            }

            for (var index = 0; index < Answers.Length; index++)
            {
                Answers[index] = new Answer(pointer);
            }
            for (var index = 0; index < NameServers.Length; index++)
            {
                NameServers[index] = new NameServer(pointer);
            }
            for (var index = 0; index < AdditionalRecords.Length; index++)
            {
                AdditionalRecords[index] = new AdditionalRecord(pointer);
            }
        }
예제 #3
0
        /// <summary>
        ///     Construct a Response object from the supplied byte array
        /// </summary>
        /// <param name="message">a byte array returned from a DNS server query</param>
        internal Response(byte[] message)
        {
            // the bit flags are in bytes 2 and 3
            byte flags1 = message[2];
            byte flags2 = message[3];

            // get return code from lowest 4 bits of byte 3
            int returnCode = flags2 & 15;

            // if its in the reserved section, set to other
            if (returnCode > 6) returnCode = 6;
            _returnCode = (ReturnCode) returnCode;

            // other bit flags
            _authoritativeAnswer = ((flags1 & 4) != 0);
            _recursionAvailable = ((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)];
            _nameServers = new NameServer[GetShort(message, 8)];
            _additionalRecords = new AdditionalRecord[GetShort(message, 10)];

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

            // and now populate them, they always follow this order
            for (int index = 0; index < _questions.Length; index++)
            {
                try
                {
                    // try to build a quesion from the response
                    _questions[index] = new Question(pointer);
                }
                catch (Exception ex)
                {
                    // something grim has happened, we can't continue
                    throw new InvalidResponseException(ex);
                }
            }
            for (int index = 0; index < _answers.Length; index++)
            {
                _answers[index] = new Answer(pointer);
            }
            for (int index = 0; index < _nameServers.Length; index++)
            {
                _nameServers[index] = new NameServer(pointer);
            }
            for (int index = 0; index < _additionalRecords.Length; index++)
            {
                _additionalRecords[index] = new AdditionalRecord(pointer);
            }
        }
예제 #4
0
 private void ReadAdditionalRecords(Pointer pointer)
 {
     for (int index = 0; index < _additionalRecords.Length; index++)
     {
         _additionalRecords[index] = new AdditionalRecord(pointer);
     }
 }