Add support for multiple DNS servers on Android.

Before, c-ares always used the first DNS server on Android, causing
network problems if this DNS server was not available.

Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
pull/8/merge
Guenter Knauf 13 years ago
parent 80de4a7295
commit 2c67ce6459
  1. 18
      ares_init.c

@ -62,6 +62,7 @@
#if defined(ANDROID) || defined(__ANDROID__) #if defined(ANDROID) || defined(__ANDROID__)
#include <sys/system_properties.h> #include <sys/system_properties.h>
#define MAX_DNS_PROPERTIES 8 /* From the Bionic sources */
#endif #endif
#include "ares.h" #include "ares.h"
@ -953,11 +954,22 @@ DhcpNameServer
status = ARES_EOF; status = ARES_EOF;
#elif defined(ANDROID) || defined(__ANDROID__) #elif defined(ANDROID) || defined(__ANDROID__)
unsigned int i;
char name[PROP_NAME_MAX];
char value[PROP_VALUE_MAX]=""; char value[PROP_VALUE_MAX]="";
__system_property_get("net.dns1", value); int len;
status = config_nameserver(&servers, &nservers, value); for (i = 1; i <= MAX_DNS_PROPERTIES; i++) {
if (status == ARES_SUCCESS) snprintf(name, sizeof(name), "net.dns%u", i);
len = __system_property_get(name, value);
if (len < 1) {
status = ARES_EOF;
break;
}
status = config_nameserver(&servers, &nservers, value);
if (status != ARES_SUCCESS)
break;
status = ARES_EOF; status = ARES_EOF;
}
#else #else
{ {
char *p; char *p;

Loading…
Cancel
Save