aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/utils
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-03-25 17:21:56 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-03-25 17:21:56 +0100
commit0b9e089ac63b0743619893e30c4c612516661b23 (patch)
treebcb75db1335139df037a497d29699b3ad8f66e85 /src/eu/siacs/conversations/utils
parent10f2231bcf72c65389546c999e1d74968c482134 (diff)
using actual dns servers provided by the system
Diffstat (limited to 'src/eu/siacs/conversations/utils')
-rw-r--r--src/eu/siacs/conversations/utils/DNSHelper.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/eu/siacs/conversations/utils/DNSHelper.java b/src/eu/siacs/conversations/utils/DNSHelper.java
index 21d58edca..c20b45ecc 100644
--- a/src/eu/siacs/conversations/utils/DNSHelper.java
+++ b/src/eu/siacs/conversations/utils/DNSHelper.java
@@ -2,15 +2,45 @@ package eu.siacs.conversations.utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
+import java.util.ArrayList;
import java.util.Random;
import android.os.Bundle;
+import android.util.Log;
public class DNSHelper {
public static Bundle getSRVRecord(String host) throws IOException {
+ InetAddress ip = InetAddress.getByName("8.8.8.8");
+ try {
+ Class<?> SystemProperties = Class.forName("android.os.SystemProperties");
+ Method method = SystemProperties.getMethod("get", new Class[] { String.class });
+ ArrayList<String> servers = new ArrayList<String>();
+ for (String name : new String[] { "net.dns1", "net.dns2", "net.dns3", "net.dns4", }) {
+ String value = (String) method.invoke(null, name);
+
+ if (value != null && !"".equals(value) && !servers.contains(value))
+ ip = InetAddress.getByName(value);
+ servers.add(value);
+ }
+ } catch (ClassNotFoundException e) {
+ ip = InetAddress.getByName("8.8.8.8");
+ } catch (NoSuchMethodException e) {
+ ip = InetAddress.getByName("8.8.8.8");
+ } catch (IllegalAccessException e) {
+ ip = InetAddress.getByName("8.8.8.8");
+ } catch (IllegalArgumentException e) {
+ ip = InetAddress.getByName("8.8.8.8");
+ } catch (InvocationTargetException e) {
+ ip = InetAddress.getByName("8.8.8.8");
+ }
+
+ Log.d("xmppService","using dns server: "+ip.toString()+" to look up SRV records");
+
Bundle namePort = new Bundle();
String[] hostParts = host.split("\\.");
byte[] transId = new byte[2];
@@ -35,10 +65,9 @@ public class DNSHelper {
}
output.write(rest);
byte[] sendPaket = output.toByteArray();
- byte[] addr = { 0x8, 0x8, 0x8, 0x8 };
int realLenght = sendPaket.length - 11;
DatagramPacket packet = new DatagramPacket(sendPaket,
- sendPaket.length, InetAddress.getByAddress(addr), 53);
+ sendPaket.length, ip, 53);
DatagramSocket datagramSocket = new DatagramSocket();
datagramSocket.send(packet);
byte[] receiveData = new byte[1024];