Example #1
0
        private static byte[] GetResponseBytes(DnsQueryResponse message, byte[] answerData)
        {
            using (var writer = new DnsDatagramWriter())
            {
                writer.WriteUInt16NetworkOrder((ushort)message.Header.Id);
                writer.WriteUInt16NetworkOrder((ushort)message.Header.HeaderFlags);
                // lets iterate answers only, makse it easier
                //writer.WriteUInt16Network((ushort)message.Header.QuestionCount);
                writer.WriteUInt16NetworkOrder(0);
                writer.WriteUInt16NetworkOrder(1);
                //writer.WriteUInt16Network((ushort)message.Header.NameServerCount);
                writer.WriteUInt16NetworkOrder(0);
                //writer.WriteUInt16Network((ushort)message.Header.AdditionalCount);
                writer.WriteUInt16NetworkOrder(0);

                var answer = message.Answers.First();
                writer.WriteHostName(answer.DomainName.Value);
                writer.WriteUInt16NetworkOrder((ushort)answer.RecordType);
                writer.WriteUInt16NetworkOrder((ushort)answer.RecordClass);
                writer.WriteUInt32NetworkOrder((uint)answer.TimeToLive);
                writer.WriteUInt16NetworkOrder((ushort)answerData.Length);

                //writer.Extend(answerData.Length);   // the following data->length
                writer.WriteBytes(answerData, answerData.Length);

                return(writer.Data.ToArray());
            }
        }