mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-25 02:02:16 -05:00
use dns library to resolve missing ipv6 or ipv4 addresses
This commit is contained in:
parent
165965bb83
commit
5373956e19
@ -142,11 +142,21 @@ public class DNSHelper {
|
|||||||
for (SRV srv : result) {
|
for (SRV srv : result) {
|
||||||
if (ips6.containsKey(srv.getName())) {
|
if (ips6.containsKey(srv.getName())) {
|
||||||
values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips6));
|
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())) {
|
if (ips4.containsKey(srv.getName())) {
|
||||||
values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips4));
|
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);
|
bundle.putParcelableArrayList("values", values);
|
||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
@ -157,6 +167,13 @@ public class DNSHelper {
|
|||||||
return bundle;
|
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) {
|
private static Bundle createNamePortBundle(String name, int port, TreeMap<String, ArrayList<String>> ips) {
|
||||||
Bundle namePort = new Bundle();
|
Bundle namePort = new Bundle();
|
||||||
namePort.putString("name", name);
|
namePort.putString("name", name);
|
||||||
@ -169,6 +186,18 @@ public class DNSHelper {
|
|||||||
return namePort;
|
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();
|
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||||
|
|
||||||
public static String bytesToHex(byte[] bytes) {
|
public static String bytesToHex(byte[] bytes) {
|
||||||
|
Loading…
Reference in New Issue
Block a user