mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-28 11:55:20 +01:00
Replaced getByName/getAllByName
This commit is contained in:
@@ -49,6 +49,8 @@ import org.minidns.record.TXT;
|
||||
import org.minidns.source.AbstractDnsDataSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
@@ -275,6 +277,37 @@ public class DnsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
static InetAddress getByName(Context context, String host) throws UnknownHostException {
|
||||
return getAllByName(context, host)[0];
|
||||
}
|
||||
|
||||
static InetAddress[] getAllByName(Context context, String host) throws UnknownHostException {
|
||||
List<InetAddress> result = new ArrayList<>();
|
||||
|
||||
boolean[] has46 = ConnectionHelper.has46(context);
|
||||
|
||||
if (has46[0])
|
||||
for (DnsRecord a : lookup(context, host, "a"))
|
||||
try {
|
||||
result.add(Inet4Address.getByName(a.response));
|
||||
} catch (UnknownHostException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
if (has46[1])
|
||||
for (DnsRecord aaaa : lookup(context, host, "aaaa"))
|
||||
try {
|
||||
result.add(Inet6Address.getByName(aaaa.response));
|
||||
} catch (UnknownHostException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
if (result.size() == 0)
|
||||
throw new UnknownHostException(host);
|
||||
else
|
||||
return result.toArray(new InetAddress[0]);
|
||||
}
|
||||
|
||||
private static List<String> getDnsServers(Context context) {
|
||||
List<String> result = new ArrayList<>();
|
||||
result.add(DEFAULT_DNS);
|
||||
|
||||
Reference in New Issue
Block a user