use of org.minidns.record.RRWithTarget in project minidns by MiniDNS.
the class IterativeDNSClient method resolveIpRecursive.
private IpResultSet resolveIpRecursive(ResolutionState resolutionState, DNSName name) throws IOException {
IpResultSet.Builder res = newIpResultSetBuilder();
if (ipVersionSetting.v4) {
// TODO Try to retrieve A records for name out from cache.
Question question = new Question(name, TYPE.A);
final DNSMessage query = getQueryFor(question);
DNSMessage aMessage = queryRecursive(resolutionState, query);
if (aMessage != null) {
for (Record<? extends Data> answer : aMessage.answerSection) {
if (answer.isAnswer(question)) {
InetAddress inetAddress = inetAddressFromRecord(name.ace, (A) answer.payloadData);
res.ipv4Addresses.add(inetAddress);
} else if (answer.type == TYPE.CNAME && answer.name.equals(name)) {
return resolveIpRecursive(resolutionState, ((RRWithTarget) answer.payloadData).target);
}
}
}
}
if (ipVersionSetting.v6) {
// TODO Try to retrieve AAAA records for name out from cache.
Question question = new Question(name, TYPE.AAAA);
final DNSMessage query = getQueryFor(question);
DNSMessage aMessage = queryRecursive(resolutionState, query);
if (aMessage != null) {
for (Record<? extends Data> answer : aMessage.answerSection) {
if (answer.isAnswer(question)) {
InetAddress inetAddress = inetAddressFromRecord(name.ace, (AAAA) answer.payloadData);
res.ipv6Addresses.add(inetAddress);
} else if (answer.type == TYPE.CNAME && answer.name.equals(name)) {
return resolveIpRecursive(resolutionState, ((RRWithTarget) answer.payloadData).target);
}
}
}
}
return res.build();
}
use of org.minidns.record.RRWithTarget in project minidns by MiniDNS.
the class DNSMessageTest method testALookup.
@Test
public void testALookup() throws Exception {
DNSMessage m = getMessageFromResource("sun-a");
assertFalse(m.authoritativeAnswer);
List<Record<? extends Data>> answers = m.answerSection;
assertEquals(2, answers.size());
Record<? extends Data> cname = answers.get(0);
Record<? extends Data> a = answers.get(1);
assertTrue(cname.getPayload() instanceof RRWithTarget);
assertEquals(TYPE.CNAME, cname.getPayload().getType());
assertCsEquals("legacy-sun.oraclegha.com", ((RRWithTarget) (cname.getPayload())).target);
assertCsEquals("legacy-sun.oraclegha.com", a.name);
assertTrue(a.getPayload() instanceof A);
assertEquals(TYPE.A, a.getPayload().getType());
assertCsEquals("156.151.59.35", a.getPayload().toString());
}
Aggregations