Пример #1
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>
        protected ResourceRecord(Pointer pointer)
        {
            // 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)pointer.ReadShort())
            {
                case DnsType.NS:
                    this._record = new NSRecord(pointer);
                    break;
                case DnsType.MX:
                    this._record = new MXRecord(pointer);
                    break;
                case DnsType.ANAME:
                    this._record = new ANameRecord(pointer);
                    break;
                case DnsType.SOA:
                    this._record = new SoaRecord(pointer);
                    break;
                default:
                    {
                        // move the pointer over this unrecognised record
                        pointer += recordLength;
                        break;
                    }
            }
        }
Пример #2
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>
 public Question(Pointer pointer)
 {
     // extract from the message
     this._domain = pointer.ReadDomain();
     this._dnsType = (DnsType) pointer.ReadShort();
     this._dnsClass = (DnsClass) pointer.ReadShort();
 }
Пример #3
0
        // expose this IP address r/o to the world

        /// <summary>
        ///     Constructs an ANAME record by reading bytes from a return message
        /// </summary>
        /// <param name="pointer"> A logical pointer to the bytes holding the record </param>
        public ANameRecord(Pointer pointer)
        {
            byte b1 = pointer.ReadByte();
            byte b2 = pointer.ReadByte();
            byte b3 = pointer.ReadByte();
            byte b4 = pointer.ReadByte();

            // this next line's not brilliant - couldn't find a better way though
            this.ipAddress = IPAddress.Parse(string.Format("{0}.{1}.{2}.{3}", b1, b2, b3, b4));
        }
Пример #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>
        public Response(byte[] message)
        {
            // create the arrays of response objects
            this.questions = new Question[GetShort(message, 4)];
            this.answers = new Answer[GetShort(message, 6)];
            this.nameServers = new NameServer[GetShort(message, 8)];
            this.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 < this.questions.Length; index++)
            {
                try
                {
                    // try to build a quesion from the response
                    this.questions[index] = new Question(pointer);
                }
                catch (Exception ex)
                {
					Log.Error("A DNS response question failure occured.", ex);
                    // something grim has happened, we can't continue
                    throw new InvalidResponseException(ex);
                }
            }
            for (int index = 0; index < this.answers.Length; index++)
            {
                this.answers[index] = new Answer(pointer);
            }
            for (int index = 0; index < this.nameServers.Length; index++)
            {
                this.nameServers[index] = new NameServer(pointer);
            }
            for (int index = 0; index < this.additionalRecords.Length; index++)
            {
                this.additionalRecords[index] = new AdditionalRecord(pointer);
            }
        }
Пример #5
0
 /// <summary>
 ///     Constructs an MX record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer"> A logical pointer to the bytes holding the record </param>
 public MXRecord(Pointer pointer)
 {
     this._preference = pointer.ReadShort();
     this._domainName = pointer.ReadDomain();
 }
Пример #6
0
 public NameServer(Pointer pointer) : base(pointer)
 {
 }
Пример #7
0
 public Answer(Pointer pointer) : base(pointer)
 {
 }
Пример #8
0
 public AdditionalRecord(Pointer pointer) : base(pointer)
 {
 }