public DnsHeader(Stream s) { _ID = DnsDatagram.ReadUInt16NetworkOrder(s); int lB = s.ReadByte(); _QR = Convert.ToByte((lB & 0x80) >> 7); _OPCODE = (DnsOpcode)Convert.ToByte((lB & 0x78) >> 3); _AA = Convert.ToByte((lB & 0x4) >> 2); _TC = Convert.ToByte((lB & 0x2) >> 1); _RD = Convert.ToByte(lB & 0x1); int rB = s.ReadByte(); _RA = Convert.ToByte((rB & 0x80) >> 7); _Z = Convert.ToByte((rB & 0x40) >> 6); _AD = Convert.ToByte((rB & 0x20) >> 5); _CD = Convert.ToByte((rB & 0x10) >> 4); _RCODE = (DnsResponseCode)(rB & 0xf); _QDCOUNT = DnsDatagram.ReadUInt16NetworkOrder(s); _ANCOUNT = DnsDatagram.ReadUInt16NetworkOrder(s); _NSCOUNT = DnsDatagram.ReadUInt16NetworkOrder(s); _ARCOUNT = DnsDatagram.ReadUInt16NetworkOrder(s); }
/// <summary> /// Constructs an instance out of the algorithm, inception, expiration, mode, error, key and other fields. /// </summary> /// <param name="algorithm"> /// Name of the algorithm in domain name syntax. /// The algorithm determines how the secret keying material agreed to using the TKEY RR is actually used to derive the algorithm specific key. /// </param> /// <param name="inception"> /// Number of seconds since the beginning of 1 January 1970 GMT ignoring leap seconds treated as modulo 2**32 using ring arithmetic. /// In messages between a DNS resolver and a DNS server where this field is meaningful, /// it is either the requested validity interval start for the keying material asked for or /// specify the validity interval start of keying material provided. /// /// To avoid different interpretations of the inception time in TKEY RRs, /// resolvers and servers exchanging them must have the same idea of what time it is. /// One way of doing this is with the NTP protocol [RFC 2030] but that or any other time synchronization used for this purpose must be done securely. /// </param> /// <param name="expiration"> /// Number of seconds since the beginning of 1 January 1970 GMT ignoring leap seconds treated as modulo 2**32 using ring arithmetic. /// In messages between a DNS resolver and a DNS server where this field is meaningful, /// it is either the requested validity interval end for the keying material asked for or /// specify the validity interval end of keying material provided. /// /// To avoid different interpretations of the expiration time in TKEY RRs, /// resolvers and servers exchanging them must have the same idea of what time it is. /// One way of doing this is with the NTP protocol [RFC 2030] but that or any other time synchronization used for this purpose must be done securely. /// </param> /// <param name="mode"> /// Specifies the general scheme for key agreement or the purpose of the TKEY DNS message. /// Servers and resolvers supporting this specification must implement the Diffie-Hellman key agreement mode and the key deletion mode for queries. /// All other modes are optional. /// A server supporting TKEY that receives a TKEY request with a mode it does not support returns the BADMODE error. /// </param> /// <param name="error"> /// When the TKEY Error Field is non-zero in a response to a TKEY query, the DNS header RCODE field indicates no error. /// However, it is possible if a TKEY is spontaneously included in a response the TKEY RR and DNS header error field /// could have unrelated non-zero error codes. /// </param> /// <param name="key">The key exchange data. The meaning of this data depends on the mode.</param> /// <param name="other">May be used in future extensions.</param> public DnsResourceDataTransactionKey(DnsDomainName algorithm, SerialNumber32 inception, SerialNumber32 expiration, DnsTransactionKeyMode mode, DnsResponseCode error, DataSegment key, DataSegment other) { if (key == null) { throw new ArgumentNullException("key"); } if (other == null) { throw new ArgumentNullException("other"); } if (key.Length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("key", key.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue)); } if (other.Length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("other", other.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue)); } Algorithm = algorithm; Inception = inception; Expiration = expiration; Mode = mode; Error = error; Key = key; Other = other; }
/// <summary> /// Constructs an instance out of the algorithm time signed, fudge, message authentication code, original ID, error and other fields. /// </summary> /// <param name="algorithm">Name of the algorithm in domain name syntax.</param> /// <param name="timeSigned">Seconds since 1-Jan-70 UTC.</param> /// <param name="fudge">Seconds of error permitted in Time Signed.</param> /// <param name="messageAuthenticationCode">Defined by Algorithm Name.</param> /// <param name="originalId">Original message ID.</param> /// <param name="error">RCODE covering TSIG processing.</param> /// <param name="other">Empty unless Error == BADTIME.</param> public DnsResourceDataTransactionSignature(DnsDomainName algorithm, UInt48 timeSigned, ushort fudge, DataSegment messageAuthenticationCode, ushort originalId, DnsResponseCode error, DataSegment other) { if (messageAuthenticationCode == null) { throw new ArgumentNullException("messageAuthenticationCode"); } if (other == null) { throw new ArgumentNullException("other"); } if (messageAuthenticationCode.Length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("messageAuthenticationCode", messageAuthenticationCode.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue)); } if (other.Length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("other", other.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue)); } Algorithm = algorithm; TimeSigned = timeSigned; Fudge = fudge; MessageAuthenticationCode = messageAuthenticationCode; OriginalId = originalId; Error = error; Other = other; }
public DnsHeader(dynamic jsonResponse) { _QR = 1; //is response _OPCODE = DnsOpcode.StandardQuery; _TC = (byte)(jsonResponse.TC.Value ? 1 : 0); _RD = (byte)(jsonResponse.RD.Value ? 1 : 0); _RA = (byte)(jsonResponse.RA.Value ? 1 : 0); _AD = (byte)(jsonResponse.AD.Value ? 1 : 0); _CD = (byte)(jsonResponse.CD.Value ? 1 : 0); _RCODE = (DnsResponseCode)jsonResponse.Status; _QDCOUNT = Convert.ToUInt16(jsonResponse.Question.Count); if (jsonResponse.Answer != null) { _ANCOUNT = Convert.ToUInt16(jsonResponse.Answer.Count); } if (jsonResponse.Authority != null) { _NSCOUNT = Convert.ToUInt16(jsonResponse.Authority.Count); } if (jsonResponse.Additional != null) { _ARCOUNT = Convert.ToUInt16(jsonResponse.Additional.Count); } }
public CacheNode(DnsResponseCode responseCode, DnsRecordType recordType, ICollection <DnsRecord> records, CacheNodeSource source) { Guard.NotNull(records, "records"); _records = records; _source = source; }
public void ctor_should_set_message_and_response_code() { string message = "message"; DnsResponseCode responseCode = DnsResponseCode.NameError; DnsResolutionException exc = new DnsResolutionException(message, responseCode); Assert.AreSame(exc.Message, message); Assert.AreEqual(exc.ResponseCode, responseCode); }
public DnsResponse(DnsResponseCode responseCode, DnsRecordType queryType, string queryName, DnsResourceRecord[] answerRecords, DnsResourceRecord[] authorityRecords, DnsResourceRecord[] additionalInformationRecords) { this.ResponseCode = responseCode; this.QueryType = queryType; this.QueryName = queryName; this.AnswerRecords = answerRecords; this.AuthorityRecords = authorityRecords; this.AdditionalInformationRecords = additionalInformationRecords; }
public static string GetErrorText(DnsResponseCode code) { if (!errors.ContainsKey(code)) { return(Unassigned); } return(errors[code]); }
public DnsHeader(ushort ID, bool isResponse, DnsOpcode OPCODE, bool authoritativeAnswer, bool truncation, bool recursionDesired, bool recursionAvailable, bool authenticData, bool checkingDisabled, DnsResponseCode RCODE, ushort QDCOUNT, ushort ANCOUNT, ushort NSCOUNT, ushort ARCOUNT) { _ID = ID; if (_ID == 0) { byte[] buffer = new byte[2]; DnsClient._rnd.GetBytes(buffer); _ID = BitConverter.ToUInt16(buffer, 0); } if (isResponse) { _QR = 1; } _OPCODE = OPCODE; if (authoritativeAnswer) { _AA = 1; } if (truncation) { _TC = 1; } if (recursionDesired) { _RD = 1; } if (recursionAvailable) { _RA = 1; } if (authenticData) { _AD = 1; } if (checkingDisabled) { _CD = 1; } _RCODE = RCODE; _QDCOUNT = QDCOUNT; _ANCOUNT = ANCOUNT; _NSCOUNT = NSCOUNT; _ARCOUNT = ARCOUNT; }
/// <summary> /// Intitialises a new instance of the <see cref="DnsCacheResult2"/> type. /// </summary> /// <param name="responseCode">The cache response code.</param> /// <param name="records">The records returned by the operation.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="records"/> is <see langword="null"/>. /// </exception> /// <exception cref="System.ArgumentException"> /// Thrown when <paramref name="records"/> is not readonly. /// </exception> public DnsCacheResult2(DnsResponseCode responseCode, ICollection <DnsRecord> records) { Guard.NotNull(records, "records"); if (!records.IsReadOnly) { throw Guard.CollectionMustBeReadonly("records"); } _responseCode = responseCode; _records = records; _isEmpty = false; }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < ConstantPartLength + DnsDomainName.RootLength) { return(null); } DnsDomainName algorithm; int algorithmLength; if (!DnsDomainName.TryParse(dns, offsetInDns, length - ConstantPartLength, out algorithm, out algorithmLength)) { return(null); } offsetInDns += algorithmLength; length -= algorithmLength; if (length < ConstantPartLength) { return(null); } uint inception = dns.ReadUInt(offsetInDns + OffsetAfterAlgorithm.Inception, Endianity.Big); uint expiration = dns.ReadUInt(offsetInDns + OffsetAfterAlgorithm.Expiration, Endianity.Big); DnsTransactionKeyMode mode = (DnsTransactionKeyMode)dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Mode, Endianity.Big); DnsResponseCode error = (DnsResponseCode)dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Error, Endianity.Big); int keySize = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.KeySize, Endianity.Big); if (length < ConstantPartLength + keySize) { return(null); } DataSegment key = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.KeyData, keySize); int totalReadAfterAlgorithm = OffsetAfterAlgorithm.KeyData + keySize; offsetInDns += totalReadAfterAlgorithm; length -= totalReadAfterAlgorithm; int otherSize = dns.ReadUShort(offsetInDns, Endianity.Big); if (length != sizeof(ushort) + otherSize) { return(null); } DataSegment other = dns.Subsegment(offsetInDns + sizeof(ushort), otherSize); return(new DnsResourceDataTransactionKey(algorithm, inception, expiration, mode, error, key, other)); }
public DnsHeader(ushort ID, bool isResponse, DnsOpcode OPCODE, bool authoritativeAnswer, bool truncation, bool recursionDesired, bool recursionAvailable, bool authenticData, bool checkingDisabled, DnsResponseCode RCODE, ushort QDCOUNT, ushort ANCOUNT, ushort NSCOUNT, ushort ARCOUNT) { _ID = ID; if (isResponse) { _QR = 1; } _OPCODE = OPCODE; if (authoritativeAnswer) { _AA = 1; } if (truncation) { _TC = 1; } if (recursionDesired) { _RD = 1; } if (recursionAvailable) { _RA = 1; } if (authenticData) { _AD = 1; } if (checkingDisabled) { _CD = 1; } _RCODE = RCODE; _QDCOUNT = QDCOUNT; _ANCOUNT = ANCOUNT; _NSCOUNT = NSCOUNT; _ARCOUNT = ARCOUNT; }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < ConstantPartLength + DnsDomainName.RootLength) { return(null); } DnsDomainName algorithm; int algorithmLength; if (!DnsDomainName.TryParse(dns, offsetInDns, length - ConstantPartLength, out algorithm, out algorithmLength)) { return(null); } offsetInDns += algorithmLength; length -= algorithmLength; if (length < ConstantPartLength) { return(null); } UInt48 timeSigned = dns.ReadUInt48(offsetInDns + OffsetAfterAlgorithm.TimeSigned, Endianity.Big); ushort fudge = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Fudge, Endianity.Big); int messageAuthenticationCodeLength = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCodeSize, Endianity.Big); if (length < ConstantPartLength + messageAuthenticationCodeLength) { return(null); } DataSegment messageAuthenticationCode = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCode, messageAuthenticationCodeLength); int totalReadAfterAlgorithm = OffsetAfterAlgorithm.MessageAuthenticationCode + messageAuthenticationCodeLength; offsetInDns += totalReadAfterAlgorithm; length -= totalReadAfterAlgorithm; ushort originalId = dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.OriginalId, Endianity.Big); DnsResponseCode error = (DnsResponseCode)dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.Error, Endianity.Big); int otherLength = dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherLength, Endianity.Big); if (length != OffsetAfterMessageAuthenticationCode.OtherData + otherLength) { return(null); } DataSegment other = dns.Subsegment(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherData, otherLength); return(new DnsResourceDataTransactionSignature(algorithm, timeSigned, fudge, messageAuthenticationCode, originalId, error, other)); }
public IDnsResponse Decode(T sender, T recipient, IByteBuffer buffer) { int id = buffer.ReadUnsignedShort(); int flags = buffer.ReadUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } IDnsResponse response = NewResponse( sender, recipient, id, new DnsOpCode((byte)(flags >> 11 & 0xf)), DnsResponseCode.From((flags & 0xf))); response.IsRecursionDesired = (flags >> 8 & 1) == 1; response.IsAuthoritativeAnswer = (flags >> 10 & 1) == 1; response.IsTruncated = (flags >> 9 & 1) == 1; response.IsRecursionAvailable = (flags >> 7 & 1) == 1; response.Z = flags >> 4 & 0x7; bool success = false; try { int questionCount = buffer.ReadUnsignedShort(); int answerCount = buffer.ReadUnsignedShort(); int authorityRecordCount = buffer.ReadUnsignedShort(); int additionalRecordCount = buffer.ReadUnsignedShort(); DecodeQuestions(response, buffer, questionCount); DecodeRecords(response, DnsSection.ANSWER, buffer, answerCount); DecodeRecords(response, DnsSection.AUTHORITY, buffer, authorityRecordCount); DecodeRecords(response, DnsSection.ADDITIONAL, buffer, additionalRecordCount); success = true; return(response); } finally { if (!success) { response.Release(); } } }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < 17) { return((DnsResourceData)null); } DnsDomainName domainName; int numBytesRead; if (!DnsDomainName.TryParse(dns, offsetInDns, length - 16, out domainName, out numBytesRead)) { return((DnsResourceData)null); } offsetInDns += numBytesRead; length -= numBytesRead; if (length < 16) { return((DnsResourceData)null); } UInt48 timeSigned = dns.ReadUInt48(offsetInDns, Endianity.Big); ushort fudge = dns.ReadUShort(offsetInDns + 6, Endianity.Big); int length1 = (int)dns.ReadUShort(offsetInDns + 8, Endianity.Big); if (length < 16 + length1) { return((DnsResourceData)null); } DataSegment messageAuthenticationCode = dns.Subsegment(offsetInDns + 10, length1); int num = 10 + length1; offsetInDns += num; length -= num; ushort originalId = dns.ReadUShort(offsetInDns, Endianity.Big); DnsResponseCode error = (DnsResponseCode)dns.ReadUShort(offsetInDns + 2, Endianity.Big); int length2 = (int)dns.ReadUShort(offsetInDns + 4, Endianity.Big); if (length != 6 + length2) { return((DnsResourceData)null); } DataSegment other = dns.Subsegment(offsetInDns + 6, length2); return((DnsResourceData) new DnsResourceDataTransactionSignature(domainName, timeSigned, fudge, messageAuthenticationCode, originalId, error, other)); }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < 17) { return((DnsResourceData)null); } DnsDomainName domainName; int numBytesRead; if (!DnsDomainName.TryParse(dns, offsetInDns, length - 16, out domainName, out numBytesRead)) { return((DnsResourceData)null); } offsetInDns += numBytesRead; length -= numBytesRead; if (length < 16) { return((DnsResourceData)null); } uint num1 = dns.ReadUInt(offsetInDns, Endianity.Big); uint num2 = dns.ReadUInt(offsetInDns + 4, Endianity.Big); DnsTransactionKeyMode mode = (DnsTransactionKeyMode)dns.ReadUShort(offsetInDns + 8, Endianity.Big); DnsResponseCode error = (DnsResponseCode)dns.ReadUShort(offsetInDns + 10, Endianity.Big); int length1 = (int)dns.ReadUShort(offsetInDns + 12, Endianity.Big); if (length < 16 + length1) { return((DnsResourceData)null); } DataSegment key = dns.Subsegment(offsetInDns + 14, length1); int num3 = 14 + length1; offsetInDns += num3; length -= num3; int length2 = (int)dns.ReadUShort(offsetInDns, Endianity.Big); if (length != 2 + length2) { return((DnsResourceData)null); } DataSegment other = dns.Subsegment(offsetInDns + 2, length2); return((DnsResourceData) new DnsResourceDataTransactionKey(domainName, (SerialNumber32)num1, (SerialNumber32)num2, mode, error, key, other)); }
private static IDnsResponse NewResponse(DatagramPacket packet, IByteBuffer buffer) { int id = buffer.ReadUnsignedShort(); int flags = buffer.ReadUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } IDnsResponse response = new DatagramDnsResponse( packet.Sender, packet.Recipient, id, DnsOpCode.From((byte)(flags >> 1 & 0xf)), DnsResponseCode.From((byte)(flags & 0xf))); return(response); }
/// <summary> /// Creates a new object initialized with all the log entry parameters. /// </summary> /// <param name="rowNumber">The row number of the entry in the selected data set.</param> /// <param name="timestamp">The time stamp of the log entry.</param> /// <param name="clientIpAddress">The client IP address of the request.</param> /// <param name="protocol">The DNS transport protocol of the request.</param> /// <param name="responseType">The type of response sent by the DNS server.</param> /// <param name="rcode">The response code sent by the DNS server.</param> /// <param name="question">The question section in the request.</param> /// <param name="answer">The answer in text format sent by the DNS server.</param> public DnsLogEntry(long rowNumber, DateTime timestamp, IPAddress clientIpAddress, DnsTransportProtocol protocol, DnsServerResponseType responseType, DnsResponseCode rcode, DnsQuestionRecord question, string answer) { _rowNumber = rowNumber; _timestamp = timestamp; _clientIpAddress = clientIpAddress; _protocol = protocol; _responseType = responseType; _rcode = rcode; _question = question; _answer = answer; switch (_timestamp.Kind) { case DateTimeKind.Local: _timestamp = _timestamp.ToUniversalTime(); break; case DateTimeKind.Unspecified: _timestamp = DateTime.SpecifyKind(_timestamp, DateTimeKind.Utc); break; } }
/// <summary> /// Initialises a new instance of the <see cref="DnsResolutionException"/> class /// and specifies a message describing the error and the /// <see cref="AK.Net.Dns.DnsResponseCode"/> that has caused this exception to /// be thrown. /// </summary> /// <param name="message">A message describing the error.</param> /// <param name="responseCode">The response code.</param> public DnsResolutionException(string message, DnsResponseCode responseCode) : base(message) { this.ResponseCode = responseCode; }
public void AuditEdnsOpt(short udpSize, byte version, DnsResponseCode responseCodeEx) { // TODO: flags _auditWriter.AppendLine($"; EDNS: version: {version}, flags:; udp: {udpSize}"); }
public void AuditResponseError(DnsResponseCode responseCode) { _auditWriter.AppendLine($";; ERROR: {DnsResponseCodeText.GetErrorText(responseCode)}"); }
public DnsFailureRecord(DnsResponseCode rcode) { _rcode = rcode; }
/// <summary> /// Initializes a new instance of the <see cref="DnsResponseException"/> class /// with a custom <paramref name="message"/> and the given <paramref name="code"/>. /// </summary> public DnsResponseException(DnsResponseCode code, string message, Exception innerException) : base(message, innerException) { Code = code; DnsError = DnsResponseCodeText.GetErrorText(Code); }
/// <summary> /// Initializes a new instance of the <see cref="DnsResponseException"/> class /// with the standard error text for the given <paramref name="code"/>. /// </summary> public DnsResponseException(DnsResponseCode code) : base(DnsResponseCodeText.GetErrorText(code)) { Code = code; DnsError = DnsResponseCodeText.GetErrorText(Code); }
protected virtual IDnsResponse NewResponse(T sender, T recipient, int id, DnsOpCode opCode, DnsResponseCode responseCode) => new DefaultDnsResponse(id, opCode, responseCode);
public DnsClientTsigRequestFailedException(DnsResponseCode rCode, DnsTsigError error) : base("TSIG Request failed (Server RCODE=" + rCode.ToString() + ", Server TSIG Error=" + error.ToString() + ").") { _rCode = rCode; _error = error; }
bool RetrieveDnsResponse(UdpSocket socket, UInt16 transactionID, out DnsResponse dnsResponse, Int64 timeoutInMachineTicks) { byte[] dnsFrameBuffer = new byte[DNS_FRAME_BUFFER_LENGTH]; while (timeoutInMachineTicks > Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks) { Int32 bytesReceived = socket.Receive(dnsFrameBuffer, 0, dnsFrameBuffer.Length, 0, timeoutInMachineTicks); if (bytesReceived == 0) // timeout { break; } /* parse our DNS response */ Int32 bufferIndex = 0; // verify that the transaction ID matches UInt16 verifyTransactionID = (UInt16)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); if (transactionID != verifyTransactionID) { continue; /* filter out this DHCP frame */ } // Flags UInt16 flags = (UInt16)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); DnsResponseCode responseCode = (DnsResponseCode)(flags & 0x0F); // Query Count UInt16 queryCount = (UInt16)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); // Answer Record Count UInt16 answerRecordCount = (UInt16)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); // Authority Record Count UInt16 authorityRecordCount = (UInt16)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); // Additional Information Record Count UInt16 additionalInformationRecordCount = (UInt16)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); /* parse our query records */ string queryName = ""; DnsRecordType queryType = (DnsRecordType)0; for (int iRecord = 0; iRecord < queryCount; iRecord++) { // Query Name bufferIndex += ParseDnsName(dnsFrameBuffer, bufferIndex, out queryName); queryType = (DnsRecordType)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); UInt16 queryClass = (UInt16)( (UInt16)(dnsFrameBuffer[bufferIndex++] << 8) + (UInt16)(dnsFrameBuffer[bufferIndex++]) ); if (queryClass != DNS_RECORD_CLASS_INTERNET) { continue; /* filter out the current query */ } } /* parse our answer records */ DnsResourceRecord[] answerRecords = new DnsResourceRecord[answerRecordCount]; for (int iRecord = 0; iRecord < answerRecordCount; iRecord++) { // store answer record bufferIndex += ParseResourceRecord(dnsFrameBuffer, bufferIndex, out answerRecords[iRecord]); } /* parse our authority records */ DnsResourceRecord[] authorityRecords = new DnsResourceRecord[authorityRecordCount]; for (int iRecord = 0; iRecord < authorityRecordCount; iRecord++) { // store authority record bufferIndex += ParseResourceRecord(dnsFrameBuffer, bufferIndex, out authorityRecords[iRecord]); } /* parse our authority records */ DnsResourceRecord[] additionalInformationRecords = new DnsResourceRecord[additionalInformationRecordCount]; for (int iRecord = 0; iRecord < additionalInformationRecordCount; iRecord++) { // store authority record bufferIndex += ParseResourceRecord(dnsFrameBuffer, bufferIndex, out additionalInformationRecords[iRecord]); } dnsResponse = new DnsResponse(responseCode, queryType, queryName, answerRecords, authorityRecords, additionalInformationRecords); return(true); } // if we did not receive a message before timeout, return false. dnsResponse = null; return(false); }
public Response(ushort id, DnsResponseCode responseCode, IEnumerable <DnsDataResourceRecord> resData, IpV4Address source, IpV4Address target, IpV4Protocol protocol, IEnumerable <DnsResourceRecord> queries) : base(id, source, target, protocol, queries) { ResponseCode = responseCode; ResponseData = resData; }
public DnsDatagram Query(DnsDatagram request, bool isRecursionAllowed) { AuthZone zone = _root.FindZone(request.Question[0].Name, out AuthZone delegation, out AuthZone authZone, out bool hasSubDomains); if ((authZone == null) || !authZone.IsActive) //no authority for requested zone { return(new DnsDatagram(request.Identifier, true, DnsOpcode.StandardQuery, false, false, request.RecursionDesired, isRecursionAllowed, false, false, DnsResponseCode.Refused, request.Question)); } if ((delegation != null) && delegation.IsActive) { return(GetReferralResponse(request, delegation, isRecursionAllowed)); } if ((zone == null) || !zone.IsActive) { //zone not found if (authZone is StubZone) { return(GetReferralResponse(request, authZone, isRecursionAllowed)); } else if (authZone is ForwarderZone) { return(GetForwarderResponse(request, null, authZone, isRecursionAllowed)); } DnsResponseCode rCode = DnsResponseCode.NoError; IReadOnlyList <DnsResourceRecord> authority = authZone.QueryRecords(DnsResourceRecordType.APP); if (authority.Count == 0) { if (!hasSubDomains) { rCode = DnsResponseCode.NxDomain; } authority = authZone.GetRecords(DnsResourceRecordType.SOA); } return(new DnsDatagram(request.Identifier, true, DnsOpcode.StandardQuery, true, false, request.RecursionDesired, isRecursionAllowed, false, false, rCode, request.Question, null, authority)); } else { //zone found IReadOnlyList <DnsResourceRecord> authority; IReadOnlyList <DnsResourceRecord> additional; IReadOnlyList <DnsResourceRecord> answers = zone.QueryRecords(request.Question[0].Type); if (answers.Count == 0) { //record type not found if (authZone is StubZone) { return(GetReferralResponse(request, authZone, isRecursionAllowed)); } else if (authZone is ForwarderZone) { return(GetForwarderResponse(request, zone, authZone, isRecursionAllowed)); } authority = zone.QueryRecords(DnsResourceRecordType.APP); if (authority.Count == 0) { authority = authZone.QueryRecords(DnsResourceRecordType.APP); if (authority.Count == 0) { authority = authZone.GetRecords(DnsResourceRecordType.SOA); } } additional = null; } else { //record type found if (zone.Name.Contains("*")) { //wildcard zone; generate new answer records DnsResourceRecord[] wildcardAnswers = new DnsResourceRecord[answers.Count]; for (int i = 0; i < answers.Count; i++) { wildcardAnswers[i] = new DnsResourceRecord(request.Question[0].Name, answers[i].Type, answers[i].Class, answers[i].TtlValue, answers[i].RDATA) { Tag = answers[i].Tag } } ; answers = wildcardAnswers; } switch (request.Question[0].Type) { case DnsResourceRecordType.NS: case DnsResourceRecordType.MX: case DnsResourceRecordType.SRV: authority = null; additional = GetAdditionalRecords(answers); break; case DnsResourceRecordType.ANY: authority = null; additional = null; break; default: authority = authZone.QueryRecords(DnsResourceRecordType.NS); additional = GetAdditionalRecords(authority); break; } } return(new DnsDatagram(request.Identifier, true, DnsOpcode.StandardQuery, true, false, request.RecursionDesired, isRecursionAllowed, false, false, DnsResponseCode.NoError, request.Question, answers, authority, additional)); } }
public DnsClientTsigRequestFailedException(DnsResponseCode rCode, DnsTsigError error, string message, Exception innerException) : base(message, innerException) { _rCode = rCode; _error = error; }