/// <summary>
        /// Creates a new instance of this class by parsing the given data
        /// <seealso cref="DNSQuestion"/>
        /// <example><code>
        /// // For parsing DNS frames, set the index variable to the index where parsing should begin.
        /// // This is in case of DNS frames 12 + the length of all records before this record
        /// int iIndex = 12;
        ///
        /// // Parse all records
        /// while (lRecords.Count &lt; iCount)
        /// {
        ///     // Create a new DNS records from the data and pass the index as pointer to the constructor.
        ///     // The index will be increased during parsing so that it will point to the beginning of the next record.
        ///     DNSResourceRecord qLast = new DNSResourceRecord(bData, ref iIndex);
        ///     lRecords.Add(qLast);
        /// }
        /// </code></example>
        /// </summary>
        /// <param name="bData">The data to parse</param>
        /// <param name="iParserIndex">The index where parsing starts. This index will be incremented automatically during parsing</param>
        public DNSResourceRecord(byte[] bData, ref int iParserIndex)
        {
            dnsEnc = new DNSNameEncoder();
            int iStringLen = 0;

            strName       = DNSNameEncoder.DecodeDNSName(bData, iParserIndex, ref iStringLen).Substring(1);
            iParserIndex += iStringLen;
            dnsType       = (DNSResourceType)(((bData[iParserIndex]) << 8) + bData[iParserIndex + 1]);
            dnsClass      = (DNSResourceClass)(((bData[iParserIndex + 2]) << 8) + bData[iParserIndex + 3]);
            iTTL          = ((int)bData[iParserIndex + 4] << 24) + ((int)bData[iParserIndex + 5] << 16) + ((int)bData[iParserIndex + 6] << 8) + bData[iParserIndex + 7];
            int iRDLen = ((int)bData[iParserIndex + 8] << 8) + bData[iParserIndex + 9];

            iParserIndex += 10;
            if (dnsType != DNSResourceType.CNAME)
            {
                bResourceData = new byte[iRDLen];

                for (int iC1 = 0; iC1 < iRDLen; iC1++)
                {
                    bResourceData[iC1] = bData[iParserIndex + iC1];
                }
            }
            else
            {
                int iDummy = 0;
                bResourceData = ASCIIEncoding.ASCII.GetBytes(DNSNameEncoder.DecodeDNSName(bData, iParserIndex, ref iDummy).Substring(1));
            }

            iParserIndex += iRDLen;
        }
Exemple #2
0
        /// <summary>
        /// Creates a new instance of this class by parsing the given data
        /// <example><code>
        /// // For parsing DNS frames, set the index variable to 12, because the question section starts there
        /// int iIndex = 12;
        ///
        /// // Parse all questions
        /// while (lQuestions.Count &lt; iQCount)
        /// {
        ///     // Create a new DNS question from the data and pass the index as pointer to the constructor.
        ///     // The index will be increased during parsing so that it will point to the beginning of the next record.
        ///     DNSQuestion qLast = new DNSQuestion(bData, ref iIndex);
        ///     lQuestions.Add(qLast);
        /// }
        /// </code></example>
        /// </summary>
        /// <param name="bData">The data to parse</param>
        /// <param name="iParserIndex">The index where parsing begins. This index must be passed as pointer for it will be increased during parsing.</param>
        public DNSQuestion(byte[] bData, ref int iParserIndex)
        {
            dnsEnc = new DNSNameEncoder();
            int iStringLen = 0;

            strQuestion   = DNSNameEncoder.DecodeDNSName(bData, iParserIndex, ref iStringLen).Substring(1);
            iParserIndex += iStringLen;
            qType         = (DNSResourceType)(((bData[iParserIndex]) << 8) + bData[iParserIndex + 1]);
            qClass        = (DNSResourceClass)(((bData[iParserIndex + 2]) << 8) + bData[iParserIndex + 3]);
            iParserIndex += 4;
        }