use dns library to resolve missing ipv6 or ipv4 addresses

This commit is contained in:
Daniel Gultsch 2015-05-28 16:55:48 +02:00
parent 165965bb83
commit 5373956e19
1 changed files with 30 additions and 1 deletions

View File

@ -142,11 +142,21 @@ public class DNSHelper {
for (SRV srv : result) {
if (ips6.containsKey(srv.getName())) {
values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips6));
} else {
DNSMessage response = client.query(srv.getName(), TYPE.AAAA, CLASS.IN, dnsServer.getHostAddress());
if (response.getAnswers().length >= 1) {
values.add(createNamePortBundle(srv.getName(),srv.getPort(),response.getAnswers()[0].getPayload()));
}
}
if (ips4.containsKey(srv.getName())) {
values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips4));
} else {
DNSMessage response = client.query(srv.getName(), TYPE.A, CLASS.IN, dnsServer.getHostAddress());
if (response.getAnswers().length >= 1) {
values.add(createNamePortBundle(srv.getName(),srv.getPort(),response.getAnswers()[0].getPayload()));
}
values.add(createNamePortBundle(srv.getName(),srv.getPort(),null));
}
values.add(createNamePortBundle(srv.getName(), srv.getPort()));
}
bundle.putParcelableArrayList("values", values);
} catch (SocketTimeoutException e) {
@ -157,6 +167,13 @@ public class DNSHelper {
return bundle;
}
private static Bundle createNamePortBundle(String name, int port) {
Bundle namePort = new Bundle();
namePort.putString("name", name);
namePort.putInt("port", port);
return namePort;
}
private static Bundle createNamePortBundle(String name, int port, TreeMap<String, ArrayList<String>> ips) {
Bundle namePort = new Bundle();
namePort.putString("name", name);
@ -169,6 +186,18 @@ public class DNSHelper {
return namePort;
}
private static Bundle createNamePortBundle(String name, int port, Data data) {
Bundle namePort = new Bundle();
namePort.putString("name", name);
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;
}
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {