示例#1
0
        public DnsQuery(byte[] packetContent)
        {
            PacketContent = packetContent;
            var parser = new DnsNameParser(packetContent);
            Header = new DnsQueryHeader(packetContent);

            var questions = new List<DnsQueryQuestion>();

            var startOfQuestion = 12;
            for (int i = 0; i < Header.QuestionCount; i++)
            {
                var question = ExtractQuestion(parser, packetContent, ref startOfQuestion);
                questions.Add(question);
            }
            Questions = questions;

            var answers = new List<IDnsQueryAnswer>();
            var dnsQueryAnswerFactory = new DnsQueryAnswerFactory();
            var startOfAnswer = startOfQuestion - 1;
            for (int i = 0; i < Header.AnswerCount; i++)
            {
                var answer = dnsQueryAnswerFactory.GetDnsQueryAnswer(parser, packetContent, ref startOfAnswer);
                answers.Add(answer);
            }
            Answers = answers;
        }
示例#2
0
 public DnsQuery(int transactionId, string hostname, DnsRecordType recordType)
 {
     Header = new DnsQueryHeader(transactionId, 1, DnsQueryType.Query, true);
     Questions = new List<DnsQueryQuestion> { new DnsQueryQuestion(hostname, recordType) };
 }