public void RequestWithHeaderAndResourceRecords() { Header header = new Header(); header.Response = true; Domain domain = new Domain(Helper.GetArray("www", "google", "com")); Question question = new Question(domain, RecordType.A, RecordClass.IN); Domain domain1 = new Domain(Helper.GetArray("www", "google", "com")); ResourceRecord record1 = new ResourceRecord(domain1, Helper.GetArray<byte>(3, 119, 119, 119, 0), RecordType.CNAME, RecordClass.IN, TimeSpan.FromSeconds(1)); Domain domain2 = new Domain(Helper.GetArray("dr", "dk")); ResourceRecord record2 = new ResourceRecord(domain2, Helper.GetArray<byte>(1, 1, 1, 1), RecordType.A, RecordClass.ANY, TimeSpan.FromSeconds(0)); Domain domain3 = new Domain(Helper.GetArray("www")); ResourceRecord record3 = new ResourceRecord(domain3, Helper.GetArray<byte>(192, 12), RecordType.CNAME, RecordClass.ANY, TimeSpan.FromSeconds(1)); Response response = new Response(header, Helper.GetList(question), Helper.GetList<IResourceRecord>(record1), Helper.GetList<IResourceRecord>(record2), Helper.GetList<IResourceRecord>(record3)); response.Id = 1; response.RecursionAvailable = true; byte[] content = Helper.ReadFixture("Response", "id-ra_all"); CollectionAssert.AreEqual(content, response.ToArray()); }
public void BasicQuestionWithEmptyDomain() { byte[] content = Helper.ReadFixture("Question", "empty-domain_basic"); Domain domain = new Domain(Helper.GetArray<string>()); Question question = new Question(domain, RecordType.A, RecordClass.IN); CollectionAssert.AreEqual(content, question.ToArray()); }
public void AllSetQuestionWithMultipleLabelDomain() { byte[] content = Helper.ReadFixture("Question", "www.google.com_all"); Domain domain = new Domain(Helper.GetArray("www", "google", "com")); Question question = new Question(domain, RecordType.CNAME, RecordClass.ANY); CollectionAssert.AreEqual(content, question.ToArray()); }
public IList<IResourceRecord> Get(Question question) { List<IResourceRecord> entries = new List<IResourceRecord>(); switch (question.Type) { case DNS.Protocol.RecordType.A: if (ipv4Address_ == null) { log_.Info("No IPv4 address for A question"); break; } log_.Info("Answer[A]:" + question.Name + ":" + ipv4Address_); entries.Add(new IPAddressResourceRecord(question.Name, ipv4Address_, ttl_)); break; case DNS.Protocol.RecordType.AAAA: if (ipv6Address_ == null) { log_.Info("No IPv6 address for AAAA question"); break; } log_.Info("Answer[AAAA]:" + question.Name + ":" + ipv6Address_); entries.Add(new IPAddressResourceRecord(question.Name, ipv6Address_, ttl_)); break; default: if (ipv4Address_ == null) { log_.Info("No IPv4 address for " + question.Name + " question"); break; } log_.Info("Answer[" + question.Type.ToString() + "]:" + question.Name + ":" + ipv4Address_); entries.Add(new IPAddressResourceRecord(question.Name, ipv4Address_, ttl_)); break; } return entries; }
public ClientResponse Resolve(Domain domain, RecordType type) { ClientRequest request = Create(); Question question = new Question(domain, type); request.Questions.Add(question); request.OperationCode = OperationCode.Query; request.RecursionDesired = true; return request.Resolve(); }
public void BasicQuestionResponseWithEmptyHeader() { Header header = new Header(); header.Response = true; Domain domain = new Domain(Helper.GetArray<string>()); Question question = new Question(domain, RecordType.A, RecordClass.IN); ResourceRecord record = new ResourceRecord(domain, Helper.GetArray<byte>(0, 0, 0, 0), RecordType.A, RecordClass.IN, new TimeSpan()); Response response = new Response(header, Helper.GetList(question), Helper.GetList<IResourceRecord>(record), Helper.GetList<IResourceRecord>(record), Helper.GetList<IResourceRecord>(record)); byte[] content = Helper.ReadFixture("Response", "empty-header_basic"); CollectionAssert.AreEqual(content, response.ToArray()); }
public IList<IResourceRecord> Get(Question question) { return Get(question.Name, question.Type); }