am 924c8785: am 8af58f0f: Use framework hints to determine dns query type.

* commit '924c8785f0b0822ab23a8a8917d312b7c5f63243':
  Use framework hints to determine dns query type.
This commit is contained in:
Robert Greenwalt 2011-09-22 23:44:57 -07:00 committed by Android Git Automerger
commit 3ec1bd2c7a

View File

@ -377,9 +377,20 @@ _test_connect(int pf, struct sockaddr *addr, size_t addrlen) {
* available, but whether addresses of the specified family are "configured
* on the local system". However, bionic doesn't currently support getifaddrs,
* so checking for connectivity is the next best thing.
*
* Note that simply checking connectivity is going to do the wrong thing on
* multihomed devices. Now we pass in a hint from the framework about what
* to use for this request ("v4", "v4v6", or "v6").
*/
static int
_have_ipv6() {
_have_ipv6(const char *propvalue) {
if (*propvalue != 0) {
if ((strcmp(propvalue, "v4v6") == 0) || (strcmp(propvalue, "v6") == 0)) {
return 1;
} else {
return 0;
}
} else {
static const struct sockaddr_in6 sin6_test = {
.sin6_family = AF_INET6,
.sin6_addr.s6_addr = { // 2000::
@ -387,16 +398,21 @@ _have_ipv6() {
};
sockaddr_union addr = { .in6 = sin6_test };
return _test_connect(PF_INET6, &addr.generic, sizeof(addr.in6));
}
}
static int
_have_ipv4() {
_have_ipv4(const char *propvalue) {
if (*propvalue != 0) {
return (strncmp(propvalue, "v4", 2) == 0);
} else {
static const struct sockaddr_in sin_test = {
.sin_family = AF_INET,
.sin_addr.s_addr = __constant_htonl(0x08080808L) // 8.8.8.8
};
sockaddr_union addr = { .in = sin_test };
return _test_connect(PF_INET, &addr.generic, sizeof(addr.in));
}
}
// Returns 0 on success, else returns non-zero on error (in which case
@ -1909,8 +1925,16 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap)
q.anslen = sizeof(buf->buf);
int query_ipv6 = 1, query_ipv4 = 1;
if (pai->ai_flags & AI_ADDRCONFIG) {
query_ipv6 = _have_ipv6();
query_ipv4 = _have_ipv4();
/* check if the fwk gave us a hint */
char propname[PROP_NAME_MAX];
char propvalue[PROP_VALUE_MAX];
propvalue[0] = 0;
snprintf(propname, sizeof(propname), "net.dnsproto.%d", getpid());
if (__system_property_get(propname, propvalue) <= 0) {
__system_property_get("net.dnsproto", propvalue);
}
query_ipv6 = _have_ipv6(propvalue);
query_ipv4 = _have_ipv4(propvalue);
}
if (query_ipv6) {
q.qtype = T_AAAA;