/// <summary> /// Given a byte array interpret them as a DnsEntry /// </summary> /// <param name="response"></param> public DnsAnswer(byte[] response) { questions = new List <Question>(); answers = new List <Answer>(); servers = new List <Server>(); additional = new List <Record>(); exceptions = new List <Exception>(); DataBuffer buffer = new DataBuffer(response, 2); byte bits1 = buffer.ReadByte(); byte bits2 = buffer.ReadByte(); //Mask off return code int returnCode = bits2 & 15; if (returnCode > 6) { returnCode = 6; } this.returnCode = (ReturnCode)returnCode; //Get Additional Flags authoritative = TestBit(bits1, 2); recursive = TestBit(bits2, 8); truncated = TestBit(bits1, 1); int nQuestions = buffer.ReadBEShortInt(); int nAnswers = buffer.ReadBEShortInt(); int nServers = buffer.ReadBEShortInt(); int nAdditional = buffer.ReadBEShortInt(); //read in questions for (int i = 0; i < nQuestions; i++) { try { questions.Add(new Question(buffer)); } catch (Exception ex) { exceptions.Add(ex); } } //read in answers for (int i = 0; i < nAnswers; i++) { try { answers.Add(new Answer(buffer)); } catch (Exception ex) { exceptions.Add(ex); } } //read in servers for (int i = 0; i < nServers; i++) { try { servers.Add(new Server(buffer)); } catch (Exception ex) { exceptions.Add(ex); } } //read in additional records for (int i = 0; i < nAdditional; i++) { try { additional.Add(new Record(buffer)); } catch (Exception ex) { exceptions.Add(ex); } } }