示例#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>
 public Question(Pointer pointer)
 {
     // extract from the message
     this._domain   = pointer.ReadDomain();
     this._dnsType  = (DnsType)pointer.ReadShort();
     this._dnsClass = (DnsClass)pointer.ReadShort();
 }
示例#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
        /// <summary>
        ///     Reads a domain name from the byte array. The method by which this works is described
        ///     in RFC1035 - 4.1.4. Essentially to minimise the size of the message, if part of a domain
        ///     name already been seen in the message, rather than repeating it, a pointer to the existing
        ///     definition is used. Each word in a domain name is a label, and is preceded by its length
        ///
        ///     eg. bigdevelopments.co.uk
        ///
        ///     is [15] (size of bigdevelopments) + "bigdevelopments"
        ///     [2]  "co"
        ///     [2]  "uk"
        ///     [1]  0 (NULL)
        /// </summary>
        /// <returns> the byte at the pointer </returns>
        public string ReadDomain()
        {
            StringBuilder domain = new StringBuilder();
            int           length = 0;

            // get  the length of the first label
            while ((length = this.ReadByte()) != 0)
            {
                // top 2 bits set denotes domain name compression and to reference elsewhere
                if ((length & 0xc0) == 0xc0)
                {
                    // work out the existing domain name, copy this pointer
                    Pointer newPointer = this.Copy();

                    // and move it to where specified here
                    newPointer.SetPosition((length & 0x3f) << 8 | this.ReadByte());

                    // repeat call recursively
                    domain.Append(newPointer.ReadDomain());
                    return(domain.ToString());
                }

                // if not using compression, copy a char at a time to the domain name
                while (length > 0)
                {
                    domain.Append(this.ReadChar());
                    length--;
                }

                // if size of next label isn't null (end of domain name) add a period ready for next label
                if (this.Peek() != 0)
                {
                    domain.Append('.');
                }
            }

            // and return
            return(domain.ToString());
        }
示例#4
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();
 }
示例#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();
 }