use of de.measite.minidns.record.A in project Conversations by siacs.
the class DNSHelper method createNamePortBundle.
private static Bundle createNamePortBundle(String name, int port, Data data, final boolean tls) {
Bundle namePort = new Bundle();
namePort.putString("name", name);
namePort.putBoolean("tls", tls);
namePort.putInt("port", port);
if (data instanceof A) {
namePort.putString("ip", data.toString());
} else if (data instanceof AAAA) {
namePort.putString("ip", "[" + data.toString() + "]");
}
return namePort;
}
use of de.measite.minidns.record.A in project Smack by igniterealtime.
the class MiniDnsResolver method lookupHostAddress0.
@Override
protected List<InetAddress> lookupHostAddress0(final String name, List<HostAddress> failedAddresses, 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) {
failedAddresses.add(new HostAddress(name, e));
return null;
}
if (!aResult.wasSuccessful() && !aaaaResult.wasSuccessful()) {
// Both results where not successful.
failedAddresses.add(new HostAddress(name, getExceptionFrom(aResult)));
failedAddresses.add(new HostAddress(name, getExceptionFrom(aaaaResult)));
return null;
}
if (shouldAbortIfNotAuthentic(name, dnssecMode, aResult, failedAddresses) || shouldAbortIfNotAuthentic(name, dnssecMode, aaaaResult, failedAddresses)) {
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, aaaa.getIp());
} catch (UnknownHostException e) {
continue;
}
inetAddresses.add(inetAddress);
}
return inetAddresses;
}
use of de.measite.minidns.record.A in project Conversations by siacs.
the class DNSHelper method fillSrvMaps.
private static void fillSrvMaps(final String qname, final InetAddress dnsServer, final Map<Integer, List<TlsSrv>> priorities, final Map<String, List<String>> ips4, final Map<String, List<String>> ips6, final boolean tls) throws IOException {
final DNSMessage message = client.query(qname, TYPE.SRV, CLASS.IN, dnsServer.getHostAddress());
for (Record[] rrset : new Record[][] { message.getAnswers(), message.getAdditionalResourceRecords() }) {
for (Record rr : rrset) {
Data d = rr.getPayload();
final String name = rr.getName() != null ? rr.getName().toLowerCase(Locale.US) : null;
if (d instanceof SRV && NameUtil.idnEquals(qname, name)) {
SRV srv = (SRV) d;
if (!priorities.containsKey(srv.getPriority())) {
priorities.put(srv.getPriority(), new ArrayList<TlsSrv>());
}
priorities.get(srv.getPriority()).add(new TlsSrv(srv, tls));
} else if (d instanceof SRV) {
Log.d(Config.LOGTAG, "found unrecognized SRV record with name: " + name);
}
if (d instanceof A) {
A a = (A) d;
if (!ips4.containsKey(name)) {
ips4.put(name, new ArrayList<String>());
}
ips4.get(name).add(a.toString());
}
if (d instanceof AAAA) {
AAAA aaaa = (AAAA) d;
if (!ips6.containsKey(name)) {
ips6.put(name, new ArrayList<String>());
}
ips6.get(name).add("[" + aaaa.toString() + "]");
}
}
}
}
Aggregations