Example #1
0
 /// <summary>
 /// Construct the question reading from a DNS Server response. Consult RFC1035 4.1.2
 /// for byte-wise details of this structure in byte array form
 /// </summary>
 /// <param name="pointer">a logical pointer to the Question in byte array form</param>
 internal Question(Pointer pointer)
 {
     // extract from the message
     _domain = pointer.ReadDomain();
     _dnsType = (DnsType)pointer.ReadShort();
     _dnsClass = (DnsClass)pointer.ReadShort();
 }
Example #2
0
        /// <summary>
        /// Construct a resource record from a pointer to a byte array
        /// </summary>
        /// <param name="pointer">the position in the byte array of the record</param>
        internal ResourceRecord(Pointer pointer)
        {
            // extract the domain, question type, question class and Ttl
            _domain     = pointer.ReadDomain();
            _dnsType    = (DnsType) pointer.ReadShort();
            _dnsClass   = (DnsClass) pointer.ReadShort();
            _Ttl        = pointer.ReadInt();

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

            // and create the appropriate RDATA record based on the dnsType
            switch (_dnsType)
            {
                case DnsType.SRV:
                    _record = new SRVRecord(pointer);
                    break;

                default:
                {
                    // move the pointer over this unrecognised record
                    pointer.Position += recordLength;
                    break;
                }
            }
        }
Example #3
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 internal SRVRecord(Pointer pointer)
 {
     m_Priority = pointer.ReadShort();
        m_Weight = pointer.ReadShort();
        m_Port = pointer.ReadShort();
        m_Target = pointer.ReadDomain();
 }
Example #4
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
            Pointer 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);
            }
        }
Example #5
0
 internal AdditionalRecord(Pointer pointer) : base(pointer)
 {
 }
Example #6
0
 internal NameServer(Pointer pointer) : base(pointer)
 {
 }
Example #7
0
 internal Answer(Pointer pointer) : base(pointer)
 {
 }
Example #8
0
 internal NameServer(Pointer pointer)
     : base(pointer)
 {
 }
Example #9
0
 internal Answer(Pointer pointer)
     : base(pointer)
 {
 }
Example #10
0
 internal AdditionalRecord(Pointer pointer)
     : base(pointer)
 {
 }