/// <summary> /// Creates a new instance of this class /// </summary> public DNSResourceRecord() { dnsEnc = new DNSNameEncoder(); strName = ""; dnsType = DNSResourceType.All; dnsClass = DNSResourceClass.Any; }
/// <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 < 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; }
/// <summary> /// Creates a new instance of this class /// </summary> public DNSQuestion() { dnsEnc = new DNSNameEncoder(); strQuestion = ""; qType = DNSResourceType.All; qClass = DNSResourceClass.Any; }
/// <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 < 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; }
/// <summary> /// Creates a new instance of this class /// </summary> /// <param name="strName">Gets or sets the DNS name for which the IP address should be spoofed</param> /// <param name="ipaToRedirect">The address which sould be inserted instead of the real address</param> /// <param name="dnsRecordType">The record type of the record to spoof.</param> public DNSSpooferEntry(string strName, IPAddress ipaToRedirect, DNSResourceType dnsRecordType) { if (ipaToRedirect.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork && ipaToRedirect.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6) { throw new ArgumentException("Only IPv4 and IPv6 addresses are supported at the moment."); } this.strName = strName; this.ipaToRedirect = ipaToRedirect; this.RecordType = dnsRecordType; }