Search in sources :

Example 1 with A

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;
}
Also used : AAAA(de.measite.minidns.record.AAAA) A(de.measite.minidns.record.A) Bundle(android.os.Bundle) AAAA(de.measite.minidns.record.AAAA)

Example 2 with A

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;
}
Also used : AAAA(de.measite.minidns.record.AAAA) A(de.measite.minidns.record.A) UnknownHostException(java.net.UnknownHostException) ResolverApi(de.measite.minidns.hla.ResolverApi) DnssecResolverApi(de.measite.minidns.hla.DnssecResolverApi) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HostAddress(org.jivesoftware.smack.util.dns.HostAddress) InetAddress(java.net.InetAddress) AAAA(de.measite.minidns.record.AAAA)

Example 3 with A

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() + "]");
            }
        }
    }
}
Also used : AAAA(de.measite.minidns.record.AAAA) A(de.measite.minidns.record.A) SRV(de.measite.minidns.record.SRV) Record(de.measite.minidns.Record) Data(de.measite.minidns.record.Data) AAAA(de.measite.minidns.record.AAAA) DNSMessage(de.measite.minidns.DNSMessage)

Aggregations

A (de.measite.minidns.record.A)3 AAAA (de.measite.minidns.record.AAAA)3 Bundle (android.os.Bundle)1 DNSMessage (de.measite.minidns.DNSMessage)1 Record (de.measite.minidns.Record)1 DnssecResolverApi (de.measite.minidns.hla.DnssecResolverApi)1 ResolverApi (de.measite.minidns.hla.ResolverApi)1 Data (de.measite.minidns.record.Data)1 SRV (de.measite.minidns.record.SRV)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HostAddress (org.jivesoftware.smack.util.dns.HostAddress)1