diff options
author | Will Szumski <will@cowboycoders.org> | 2016-11-22 18:16:34 +0000 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2016-11-22 23:24:15 +0100 |
commit | 0aa036fd7f702e5d420beb12ec5d0ac478c07121 (patch) | |
tree | 75c0334604b18eade489779178279dcb6746d8d4 /jni | |
parent | a330b3bf6d2a854fd0e0c2d1c1e0565027c77b95 (diff) | |
download | andiodine-0aa036fd7f702e5d420beb12ec5d0ac478c07121.tar.gz andiodine-0aa036fd7f702e5d420beb12ec5d0ac478c07121.zip |
iterate through net.dns* and pick first valid IPv4 address
Diffstat (limited to 'jni')
-rw-r--r-- | jni/iodine-client.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/jni/iodine-client.c b/jni/iodine-client.c index 2c08229..0af59a7 100644 --- a/jni/iodine-client.c +++ b/jni/iodine-client.c @@ -4,6 +4,7 @@ #include <time.h> #include <unistd.h> #include <netdb.h> +#include <stdio.h> #include <jni.h> @@ -17,6 +18,7 @@ #define IODINE_CLIENT_CLASS "org/xapek/andiodine/IodineClient" #define IODINE_CLIENT_CLASS_LOG_CALLBACK "log_callback" #define IODINE_CLIENT_CLASS_LOG_CALLBACK_SIG "(Ljava/lang/String;)V" +#define MAX_DNS_PROPERTIES 4 static int dns_fd; @@ -208,7 +210,15 @@ JNIEXPORT jint JNICALL Java_org_xapek_andiodine_IodineClient_getMtu(JNIEnv *env, // String IodineClient.getPropertyNetDns1 JNIEXPORT jstring JNICALL Java_org_xapek_andiodine_IodineClient_getPropertyNetDns1( JNIEnv *env, jclass klass) { - char value[PROP_VALUE_MAX]; - __system_property_get("net.dns1", value); - return (*env)->NewStringUTF(env, value); + struct sockaddr_in sa; + for (int i = 1; i <= MAX_DNS_PROPERTIES; i++) { + char prop_name[PROP_NAME_MAX]; + char dns[PROP_VALUE_MAX]; + snprintf(prop_name, sizeof(prop_name), "net.dns%d", i); + __system_property_get(prop_name, dns); + if (inet_pton(AF_INET, dns, &(sa.sin_addr)) == 1) { + return (*env)->NewStringUTF(env, dns); + } + } + return (*env)->NewStringUTF(env, ""); } |