OSDN Git Service

Enable IPv6.
authorLorenzo Colitti <lorenzo@google.com>
Tue, 18 Aug 2009 23:14:33 +0000 (16:14 -0700)
committerLorenzo Colitti <lorenzo@google.com>
Tue, 18 Aug 2009 23:29:42 +0000 (16:29 -0700)
If the system has IPv6 connectivity, query the DNS for IPv6 addresses as well
as IPv4 addresses. If IPv6 addresses are returned, prefer them by default.

Impact of this change:

- If the device is on a network with IPv6 configured, is using wifi, and has
  obtained an IPv6 address using autoconfiguration, the network stack will
  request IPv6 addresses as well as IPv4 addresses when making DNS queries. This
  allows the device to connect to websites and services that declare themselves
  to be reachable over IPv6. If an IPv6 connection fails, the stack will fall
  back to IPv4.  This is what Windows Vista, Mac OS 10.4 and above, and most
  Linux distributions do by default.
- If the device is not on a network that supports IPv6, or is using 3G/EVDO,
  nothing will change.

I have been testing this change on self-compiled builds of master and eclair on
Dream and Sholes for several weeks with no breakage that I can see.

libcore/luni/src/main/native/java_net_InetAddress.cpp
vm/Properties.c

index 508656f..8724817 100644 (file)
@@ -116,7 +116,8 @@ static jobjectArray getAllByNameUsingDns(JNIEnv* env, const char* name,
      * resolver will create two separate requests, one for IPv4 and one,
      * currently unnecessary, for IPv6.
      */
-    hints.ai_family = AF_INET;
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_flags = AI_ADDRCONFIG;
     /*
      * If we don't specify a socket type, every address will appear twice, once
      * for SOCK_STREAM and one for SOCK_DGRAM. Since we do not return the family
index 7758660..9cfa022 100644 (file)
@@ -165,6 +165,8 @@ void dvmCreateDefaultProperties(Object* propObj)
     setProperty(propObj, put, "java.io.tmpdir", "/tmp");
     setProperty(propObj, put, "java.library.path", getenv("LD_LIBRARY_PATH"));
 
+    setProperty(propObj, put, "java.net.preferIPv6Addresses", "true");
+
     setProperty(propObj, put, "java.vendor", projectName);
     setProperty(propObj, put, "java.vendor.url", projectUrl);
     setProperty(propObj, put, "java.version", "0");
@@ -287,4 +289,3 @@ bail:
     dvmReleaseTrackedAlloc((Object*)keyObj, NULL);
     return result;
 }
-