public IDnsQueryResponse GetResponse() { var elapsed = Elapsed(); if (elapsed <= 0) { return(_response); } var response = new DnsResponseMessage(_response.Header, _response.MessageSize) { Audit = (_response as DnsQueryResponse)?.Audit ?? new LookupClientAudit() }; foreach (var record in _response.Questions) { response.AddQuestion(record); } foreach (var record in _response.Answers) { var clone = record.Clone(); clone.TimeToLive = clone.TimeToLive - elapsed; response.AddAnswer(clone); } foreach (var record in _response.Additionals) { var clone = record.Clone(); clone.TimeToLive = clone.TimeToLive - elapsed; response.AddAnswer(clone); } foreach (var record in _response.Authorities) { var clone = record.Clone(); clone.TimeToLive = clone.TimeToLive - elapsed; response.AddAnswer(clone); } var qr = response.AsQueryResponse(_response.NameServer); return(qr); }
public DnsResponseMessage GetResponseMessage(ArraySegment <byte> responseData) { var reader = new DnsDatagramReader(responseData); var id = reader.ReadUInt16NetworkOrder(); var flags = reader.ReadUInt16NetworkOrder(); var questionCount = reader.ReadUInt16NetworkOrder(); var answerCount = reader.ReadUInt16NetworkOrder(); var nameServerCount = reader.ReadUInt16NetworkOrder(); var additionalCount = reader.ReadUInt16NetworkOrder(); var header = new DnsResponseHeader(id, flags, questionCount, answerCount, additionalCount, nameServerCount); var response = new DnsResponseMessage(header, responseData.Count); for (var questionIndex = 0; questionIndex < questionCount; questionIndex++) { var questionQueryString = reader.ReadQuestionQueryString(); var queryTypeValue = reader.ReadUInt16NetworkOrder(); var queryClass = reader.ReadUInt16NetworkOrder(); if (!_queryTypes.TryGetValue(queryTypeValue, out var queryType)) { queryType = new PseudoResourceRecordType( abbreviation: "Unknown", value: queryTypeValue ); } var question = new DnsQuestion(questionQueryString, queryType, (QueryClass)queryClass); response.AddQuestion(question); } for (var answerIndex = 0; answerIndex < answerCount; answerIndex++) { var info = ReadRecordInfo(reader); var record = _dnsRecordFactory.GetRecord(info, reader); response.AddAnswer(record); } for (var serverIndex = 0; serverIndex < nameServerCount; serverIndex++) { var info = ReadRecordInfo(reader); var record = _dnsRecordFactory.GetRecord(info, reader); response.AddAuthority(record); } for (var additionalIndex = 0; additionalIndex < additionalCount; additionalIndex++) { var info = ReadRecordInfo(reader); var record = _dnsRecordFactory.GetRecord(info, reader); response.AddAdditional(record); } return(response); }
public virtual DnsResponseMessage GetResponseMessage(ArraySegment <byte> responseData) { var reader = new DnsDatagramReader(responseData); var factory = new DnsRecordFactory(reader); var id = reader.ReadUInt16NetworkOrder(); var flags = reader.ReadUInt16NetworkOrder(); var questionCount = reader.ReadUInt16NetworkOrder(); var answerCount = reader.ReadUInt16NetworkOrder(); var nameServerCount = reader.ReadUInt16NetworkOrder(); var additionalCount = reader.ReadUInt16NetworkOrder(); var header = new DnsResponseHeader(id, flags, questionCount, answerCount, additionalCount, nameServerCount); var response = new DnsResponseMessage(header, responseData.Count); for (int questionIndex = 0; questionIndex < questionCount; questionIndex++) { var question = new DnsQuestion(reader.ReadQuestionQueryString(), (QueryType)reader.ReadUInt16NetworkOrder(), (QueryClass)reader.ReadUInt16NetworkOrder()); response.AddQuestion(question); } for (int answerIndex = 0; answerIndex < answerCount; answerIndex++) { var info = factory.ReadRecordInfo(); var record = factory.GetRecord(info); response.AddAnswer(record); } for (int serverIndex = 0; serverIndex < nameServerCount; serverIndex++) { var info = factory.ReadRecordInfo(); var record = factory.GetRecord(info); response.AddAuthority(record); } for (int additionalIndex = 0; additionalIndex < additionalCount; additionalIndex++) { var info = factory.ReadRecordInfo(); var record = factory.GetRecord(info); response.AddAdditional(record); } return(response); }