public static DefaultDnsResponse FromArray(byte[] message)
        {
            DnsMessageHeader header = DnsMessageHeader.FromArray(message);
            int offset = header.Size;

            if (!header.Response || header.QuestionCount == 0)
            {
                throw new ArgumentException("Invalid response message");
            }

            if (header.Truncated)
            {
                return(new DefaultDnsResponse(header,
                                              DnsQuestion.GetAllFromArray(message, offset, header.QuestionCount),
                                              new List <IResourceRecord>(),
                                              new List <IResourceRecord>(),
                                              new List <IResourceRecord>()));
            }

            return(new DefaultDnsResponse(header,
                                          DnsQuestion.GetAllFromArray(message, offset, header.QuestionCount, out offset),
                                          ResourceRecordFactory.GetAllFromArray(message, offset, header.AnswerRecordCount, out offset),
                                          ResourceRecordFactory.GetAllFromArray(message, offset, header.AuthorityRecordCount, out offset),
                                          ResourceRecordFactory.GetAllFromArray(message, offset, header.AdditionalRecordCount, out offset)));
        }
 public DefaultDnsResponse(DnsMessageHeader header, IList <DnsQuestion> questions, IList <IResourceRecord> answers,
                           IList <IResourceRecord> authority, IList <IResourceRecord> additional)
 {
     this.header     = header;
     this.questions  = questions;
     this.answers    = answers;
     this.authority  = authority;
     this.additional = additional;
 }
        public DefaultDnsRequest()
        {
            this.questions  = new List <DnsQuestion>();
            this.header     = new DnsMessageHeader();
            this.additional = new List <IResourceRecord>();

            this.header.OperationCode = DnsOperationCode.Query;
            this.header.Response      = false;
            this.header.Id            = RANDOM.Next(UInt16.MaxValue);
        }
        public DefaultDnsResponse()
        {
            this.header     = new DnsMessageHeader();
            this.questions  = new List <DnsQuestion>();
            this.answers    = new List <IResourceRecord>();
            this.authority  = new List <IResourceRecord>();
            this.additional = new List <IResourceRecord>();

            this.header.Response = true;
            this.header.Id       = RANDOM.Next(UInt16.MaxValue);
        }
        public DefaultDnsRequest(IDnsRequest request)
        {
            this.header     = new DnsMessageHeader();
            this.questions  = new List <DnsQuestion>(request.Questions);
            this.additional = new List <IResourceRecord>(request.AdditionalRecords);

            this.header.Response = false;

            Id               = request.Id;
            OperationCode    = request.OperationCode;
            RecursionDesired = request.RecursionDesired;
        }
        public DefaultDnsResponse(IDnsResponse response)
        {
            this.header     = new DnsMessageHeader();
            this.questions  = new List <DnsQuestion>(response.Questions);
            this.answers    = new List <IResourceRecord>(response.AnswerRecords);
            this.authority  = new List <IResourceRecord>(response.AuthorityRecords);
            this.additional = new List <IResourceRecord>(response.AdditionalRecords);

            this.header.Response = true;

            Id = response.Id;
            RecursionAvailable = response.RecursionAvailable;
            AuthorativeServer  = response.AuthorativeServer;
            OperationCode      = response.OperationCode;
            ResponseCode       = response.ResponseCode;
        }
        public static DefaultDnsRequest FromArray(byte[] message)
        {
            DnsMessageHeader header = DnsMessageHeader.FromArray(message);
            int offset = header.Size;

            if (header.Response || header.QuestionCount == 0 ||
                header.AnswerRecordCount + header.AuthorityRecordCount > 0 ||
                header.ResponseCode != DnsResponseCode.NoError)
            {
                throw new ArgumentException("Invalid request message");
            }

            return(new DefaultDnsRequest(header,
                                         DnsQuestion.GetAllFromArray(message, offset, header.QuestionCount, out offset),
                                         ResourceRecordFactory.GetAllFromArray(message, offset, header.AdditionalRecordCount, out offset)));
        }
 public DefaultDnsRequest(DnsMessageHeader header, IList <DnsQuestion> questions, IList <IResourceRecord> additional)
 {
     this.header     = header;
     this.questions  = questions;
     this.additional = additional;
 }