pull/595/head
Brad House 1 year ago
parent 001d74bfd9
commit 89b49bc36f
  1. 96
      src/lib/ares_sysconfig.c
  2. 2
      src/lib/inet_net_pton.c

@ -748,62 +748,64 @@ static ares_status_t ares__init_sysconfig_watt32(ares_sysconfig_t *sysconfig)
#endif #endif
#if defined(ANDROID) || defined(__ANDROID__) #if defined(ANDROID) || defined(__ANDROID__)
static ares_status_t static ares_status_t ares__init_sysconfig_android(ares_sysconfig_t *sysconfig)
ares__init_sysconfig_android(ares_sysconfig_t *sysconfig) size_t i; {
char **dns_servers; size_t i;
char *domains; char **dns_servers;
size_t num_servers; char *domains;
ares_status_t status = ARES_EFILE; size_t num_servers;
ares_status_t status = ARES_EFILE;
/* Use the Android connectivity manager to get a list
* of DNS servers. As of Android 8 (Oreo) net.dns# /* Use the Android connectivity manager to get a list
* system properties are no longer available. Google claims this * of DNS servers. As of Android 8 (Oreo) net.dns#
* improves privacy. Apps now need the ACCESS_NETWORK_STATE * system properties are no longer available. Google claims this
* permission and must use the ConnectivityManager which * improves privacy. Apps now need the ACCESS_NETWORK_STATE
* is Java only. */ * permission and must use the ConnectivityManager which
dns_servers = ares_get_android_server_list(MAX_DNS_PROPERTIES, &num_servers); * is Java only. */
if (dns_servers != NULL) { dns_servers = ares_get_android_server_list(MAX_DNS_PROPERTIES, &num_servers);
for (i = 0; i < num_servers; i++) { if (dns_servers != NULL) {
status = ares__sconfig_append_fromstr(&sysconfig->sconfig, dns_servers[i]); for (i = 0; i < num_servers; i++) {
if (status != ARES_SUCCESS) { status =
return status; ares__sconfig_append_fromstr(&sysconfig->sconfig, dns_servers[i]);
if (status != ARES_SUCCESS) {
return status;
}
} }
for (i = 0; i < num_servers; i++) {
ares_free(dns_servers[i]);
}
ares_free(dns_servers);
} }
for (i = 0; i < num_servers; i++) {
ares_free(dns_servers[i]);
}
ares_free(dns_servers);
}
domains = ares_get_android_search_domains_list(); domains = ares_get_android_search_domains_list();
sysconfig->domains = ares__strsplit(domains, ", ", &sysconfig->ndomains); sysconfig->domains = ares__strsplit(domains, ", ", &sysconfig->ndomains);
ares_free(domains); ares_free(domains);
# ifdef HAVE___SYSTEM_PROPERTY_GET # ifdef HAVE___SYSTEM_PROPERTY_GET
/* Old way using the system property still in place as /* Old way using the system property still in place as
* a fallback. Older android versions can still use this. * a fallback. Older android versions can still use this.
* it's possible for older apps not not have added the new * it's possible for older apps not not have added the new
* permission and we want to try to avoid breaking those. * permission and we want to try to avoid breaking those.
* *
* We'll only run this if we don't have any dns servers * We'll only run this if we don't have any dns servers
* because this will get the same ones (if it works). */ * because this will get the same ones (if it works). */
if (sysconfig->sconfig == NULL) { if (sysconfig->sconfig == NULL) {
char propname[PROP_NAME_MAX]; char propname[PROP_NAME_MAX];
char propvalue[PROP_VALUE_MAX] = ""; char propvalue[PROP_VALUE_MAX] = "";
for (i = 1; i <= MAX_DNS_PROPERTIES; i++) { for (i = 1; i <= MAX_DNS_PROPERTIES; i++) {
snprintf(propname, sizeof(propname), "%s%u", DNS_PROP_NAME_PREFIX, i); snprintf(propname, sizeof(propname), "%s%u", DNS_PROP_NAME_PREFIX, i);
if (__system_property_get(propname, propvalue) < 1) { if (__system_property_get(propname, propvalue) < 1) {
break; break;
} }
status = ares__sconfig_append_fromstr(&sysconfig->sconfig, propvalue); status = ares__sconfig_append_fromstr(&sysconfig->sconfig, propvalue);
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
return status; return status;
}
} }
} }
}
# endif /* HAVE___SYSTEM_PROPERTY_GET */ # endif /* HAVE___SYSTEM_PROPERTY_GET */
return status; return status;
} }
#endif #endif

@ -441,5 +441,5 @@ int ares_inet_pton(int af, const char *src, void *dst)
if (result == -1 && ERRNO == ENOENT) { if (result == -1 && ERRNO == ENOENT) {
return 0; return 0;
} }
return (result > -1)? 1 : -1; return (result > -1) ? 1 : -1;
} }

Loading…
Cancel
Save