use of org.minidns.record.A 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.A 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());
}
use of org.minidns.record.A in project minidns by MiniDNS.
the class HlaTest method idnSrvTest.
@IntegrationTest
public static void idnSrvTest() throws IOException {
ResolverResult<SRV> res = ResolverApi.INSTANCE.resolve("_xmpp-client._tcp.im.plä.net", SRV.class);
Set<SRV> answers = res.getAnswers();
assertEquals(1, answers.size());
SRV srv = answers.iterator().next();
ResolverResult<A> aRes = ResolverApi.INSTANCE.resolve(srv.target, A.class);
assertTrue(aRes.wasSuccessful());
}
use of org.minidns.record.A 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.A 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