use of org.minidns.record.AAAA in project minidns by MiniDNS.
the class IterativeDNSClient method queryRecursive.
private DNSMessage queryRecursive(ResolutionState resolutionState, DNSMessage q) throws IOException {
InetAddress primaryTarget = null, secondaryTarget = null;
Question question = q.getQuestion();
DNSName parent = question.name.getParent();
switch(ipVersionSetting) {
case v4only:
for (A a : getCachedIPv4NameserverAddressesFor(parent)) {
if (primaryTarget == null) {
primaryTarget = a.getInetAddress();
continue;
}
secondaryTarget = a.getInetAddress();
break;
}
break;
case v6only:
for (AAAA aaaa : getCachedIPv6NameserverAddressesFor(parent)) {
if (primaryTarget == null) {
primaryTarget = aaaa.getInetAddress();
continue;
}
secondaryTarget = aaaa.getInetAddress();
break;
}
break;
case v4v6:
InetAddress[] v4v6targets = getTargets(getCachedIPv4NameserverAddressesFor(parent), getCachedIPv6NameserverAddressesFor(parent));
primaryTarget = v4v6targets[0];
secondaryTarget = v4v6targets[1];
break;
case v6v4:
InetAddress[] v6v4targets = getTargets(getCachedIPv6NameserverAddressesFor(parent), getCachedIPv4NameserverAddressesFor(parent));
primaryTarget = v6v4targets[0];
secondaryTarget = v6v4targets[1];
break;
default:
throw new AssertionError();
}
DNSName authoritativeZone = parent;
if (primaryTarget == null) {
authoritativeZone = DNSName.ROOT;
switch(ipVersionSetting) {
case v4only:
primaryTarget = getRandomIpv4RootServer();
break;
case v6only:
primaryTarget = getRandomIpv6RootServer();
break;
case v4v6:
primaryTarget = getRandomIpv4RootServer();
secondaryTarget = getRandomIpv6RootServer();
break;
case v6v4:
primaryTarget = getRandomIpv6RootServer();
secondaryTarget = getRandomIpv4RootServer();
break;
}
}
List<IOException> ioExceptions = new LinkedList<>();
try {
return queryRecursive(resolutionState, q, primaryTarget, authoritativeZone);
} catch (IOException ioException) {
abortIfFatal(ioException);
ioExceptions.add(ioException);
}
if (secondaryTarget != null) {
try {
return queryRecursive(resolutionState, q, secondaryTarget, authoritativeZone);
} catch (IOException ioException) {
ioExceptions.add(ioException);
}
}
MultipleIoException.throwIfRequired(ioExceptions);
return null;
}
use of org.minidns.record.AAAA in project Smack by igniterealtime.
the class MiniDnsResolver method lookupHostAddress0.
@Override
protected List<InetAddress> lookupHostAddress0(final DnsName name, List<RemoteConnectionEndpointLookupFailure> lookupFailures, DnssecMode dnssecMode) {
final ResolverApi resolver = getResolver(dnssecMode);
final ResolverResult<A> aResult;
final ResolverResult<AAAA> aaaaResult;
try {
aResult = resolver.resolve(name, A.class);
aaaaResult = resolver.resolve(name, AAAA.class);
} catch (IOException e) {
RemoteConnectionEndpointLookupFailure failure = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, e);
lookupFailures.add(failure);
return null;
}
if (!aResult.wasSuccessful() && !aaaaResult.wasSuccessful()) {
// Both results where not successful.
RemoteConnectionEndpointLookupFailure failureA = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, getExceptionFrom(aResult));
lookupFailures.add(failureA);
RemoteConnectionEndpointLookupFailure failureAaaa = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, getExceptionFrom(aaaaResult));
lookupFailures.add(failureAaaa);
return null;
}
if (shouldAbortIfNotAuthentic(name, dnssecMode, aResult, lookupFailures) || shouldAbortIfNotAuthentic(name, dnssecMode, aaaaResult, lookupFailures)) {
return null;
}
// TODO: Use ResolverResult.getAnswersOrEmptySet() once we updated MiniDNS.
Set<A> aResults;
if (aResult.wasSuccessful()) {
aResults = aResult.getAnswers();
} else {
aResults = Collections.emptySet();
}
// TODO: Use ResolverResult.getAnswersOrEmptySet() once we updated MiniDNS.
Set<AAAA> aaaaResults;
if (aaaaResult.wasSuccessful()) {
aaaaResults = aaaaResult.getAnswers();
} else {
aaaaResults = Collections.emptySet();
}
List<InetAddress> inetAddresses = new ArrayList<>(aResults.size() + aaaaResults.size());
for (A a : aResults) {
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByAddress(a.getIp());
} catch (UnknownHostException e) {
continue;
}
inetAddresses.add(inetAddress);
}
for (AAAA aaaa : aaaaResults) {
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByAddress(name.ace, aaaa.getIp());
} catch (UnknownHostException e) {
continue;
}
inetAddresses.add(inetAddress);
}
return inetAddresses;
}
use of org.minidns.record.AAAA in project minidns by MiniDNS.
the class DNSMessageTest method testAAAALookup.
@Test
public void testAAAALookup() throws Exception {
DNSMessage m = getMessageFromResource("google-aaaa");
assertFalse(m.authoritativeAnswer);
List<Record<? extends Data>> answers = m.answerSection;
assertEquals(1, answers.size());
Record<? extends Data> answer = answers.get(0);
assertCsEquals("google.com", answer.name);
assertTrue(answer.getPayload() instanceof AAAA);
assertEquals(TYPE.AAAA, answer.getPayload().getType());
assertCsEquals("2a00:1450:400c:c02:0:0:0:8a", answer.getPayload().toString());
}
use of org.minidns.record.AAAA in project minidns by MiniDNS.
the class SrvResolverResult method getSortedSrvResolvedAddresses.
public List<ResolvedSrvRecord> getSortedSrvResolvedAddresses() throws IOException {
if (sortedSrvResolvedAddresses != null) {
return sortedSrvResolvedAddresses;
}
throwIseIfErrorResponse();
List<SRV> srvRecords = SrvUtil.sortSrvRecords(getAnswers());
List<ResolvedSrvRecord> res = new ArrayList<>(srvRecords.size());
for (SRV srvRecord : srvRecords) {
ResolverResult<A> aRecordsResult = null;
ResolverResult<AAAA> aaaaRecordsResult = null;
Set<A> aRecords = Collections.emptySet();
if (ipVersion.v4) {
aRecordsResult = resolver.resolve(srvRecord.target, A.class);
if (aRecordsResult.wasSuccessful() && !aRecordsResult.hasUnverifiedReasons()) {
aRecords = aRecordsResult.getAnswers();
}
}
Set<AAAA> aaaaRecords = Collections.emptySet();
if (ipVersion.v6) {
aaaaRecordsResult = resolver.resolve(srvRecord.target, AAAA.class);
if (aaaaRecordsResult.wasSuccessful() && !aaaaRecordsResult.hasUnverifiedReasons()) {
aaaaRecords = aaaaRecordsResult.getAnswers();
}
}
if (aRecords.isEmpty() && aaaaRecords.isEmpty()) {
/*
ResolverResult<CNAME> cnameRecordResult = resolve(srvRecord.name, CNAME.class);
if (cnameRecordResult.wasSuccessful()) {
}
*/
continue;
}
List<InternetAddressRR> srvAddresses = new ArrayList<>(aRecords.size() + aaaaRecords.size());
switch(ipVersion) {
case v4only:
for (A a : aRecords) {
srvAddresses.add(a);
}
break;
case v6only:
for (AAAA aaaa : aaaaRecords) {
srvAddresses.add(aaaa);
}
break;
case v4v6:
for (A a : aRecords) {
srvAddresses.add(a);
}
for (AAAA aaaa : aaaaRecords) {
srvAddresses.add(aaaa);
}
break;
case v6v4:
for (AAAA aaaa : aaaaRecords) {
srvAddresses.add(aaaa);
}
for (A a : aRecords) {
srvAddresses.add(a);
}
break;
}
ResolvedSrvRecord resolvedSrvAddresses = new ResolvedSrvRecord(question.name, srvRecord, srvAddresses, aRecordsResult, aaaaRecordsResult);
res.add(resolvedSrvAddresses);
}
sortedSrvResolvedAddresses = res;
return res;
}
Aggregations