Search in sources :

Example 1 with ExtLookup

use of org.xbill.DNS.ExtLookup in project xabber-android by redsolution.

the class ExtDNSJavaResolver method lookupSRVRecords0.

@Override
protected List<SRVRecord> lookupSRVRecords0(String name, List<HostAddress> failedAddresses, ConnectionConfiguration.DnssecMode dnssecMode) {
    List<SRVRecord> res = new ArrayList<SRVRecord>();
    org.xbill.DNS.ResolverConfig.refresh();
    ExtLookup lookup;
    String[] servers = getDNSServersListForOreo();
    try {
        lookup = new ExtLookup(name, Type.SRV);
        if (servers != null && servers.length > 0)
            lookup.setResolver(new ExtendedResolver(servers));
        else
            lookup.setResolver(new ExtendedResolver());
    } catch (TextParseException e) {
        throw new IllegalStateException(e);
    } catch (UnknownHostException e) {
        throw new RuntimeException("Failed to initialize resolver");
    }
    Record[] recs = lookup.run();
    if (recs == null)
        return res;
    for (Record record : recs) {
        org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
        if (srvRecord != null && srvRecord.getTarget() != null) {
            String host = srvRecord.getTarget().toString();
            int port = srvRecord.getPort();
            int priority = srvRecord.getPriority();
            int weight = srvRecord.getWeight();
            List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode);
            if (hostAddresses == null) {
                continue;
            }
            SRVRecord r = new SRVRecord(host, port, priority, weight, hostAddresses);
            res.add(r);
        }
    }
    return res;
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) ExtLookup(org.xbill.DNS.ExtLookup) SRVRecord(org.jivesoftware.smack.util.dns.SRVRecord) Record(org.xbill.DNS.Record) SRVRecord(org.jivesoftware.smack.util.dns.SRVRecord) InetAddress(java.net.InetAddress) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 SRVRecord (org.jivesoftware.smack.util.dns.SRVRecord)1 ExtLookup (org.xbill.DNS.ExtLookup)1 ExtendedResolver (org.xbill.DNS.ExtendedResolver)1 Record (org.xbill.DNS.Record)1 TextParseException (org.xbill.DNS.TextParseException)1