using System; using System.Collections.Generic; using System.Linq; using System.Reflection.PortableExecutable; using System.Text; using System.Threading.Tasks; using skyscraper5.DNS.Protocol.ResourceRecords; namespace skyscraper5.DNS.Protocol { public class Response { public static Response FromArray(byte[] message) { Header header = Header.FromArray(message); int offset = header.Size; if (!header.Response) { throw new ArgumentException("Invalid response message"); } if (header.Truncated) { return new Response(header, Question.GetAllFromArray(message, offset, header.QuestionCount), new List(), new List(), new List()); } return new Response(header, Question.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 Response(Header header, IList questions, IList answers, IList authority, IList additional) { this.header = header; this.questions = questions; this.answers = answers; this.authority = authority; this.additional = additional; } private Header header; private IList questions; private IList answers; private IList authority; private IList additional; public IList Questions { get { return questions; } } public IList AnswerRecords { get { return answers; } } public IList AdditionalRecords { get { return additional; } } } }