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