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); }