diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/android/java/org/chromium/net/AndroidNetworkLibrary.java | 31 | ||||
-rw-r--r-- | net/android/network_library.cc | 5 | ||||
-rw-r--r-- | net/android/network_library.h | 5 | ||||
-rw-r--r-- | net/base/net_util.cc | 7 | ||||
-rw-r--r-- | net/base/net_util.h | 1 |
5 files changed, 48 insertions, 1 deletions
diff --git a/net/android/java/org/chromium/net/AndroidNetworkLibrary.java b/net/android/java/org/chromium/net/AndroidNetworkLibrary.java index 699a3a4..2de0854 100644 --- a/net/android/java/org/chromium/net/AndroidNetworkLibrary.java +++ b/net/android/java/org/chromium/net/AndroidNetworkLibrary.java @@ -13,6 +13,8 @@ import org.chromium.base.CalledByNative; import org.chromium.base.CalledByNativeUnchecked; import java.io.ByteArrayInputStream; +import java.net.NetworkInterface; +import java.net.SocketException; import java.net.URLConnection; import java.security.KeyStore; import java.security.KeyStoreException; @@ -21,6 +23,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.concurrent.atomic.AtomicReference; +import java.util.Enumeration; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; @@ -58,6 +61,34 @@ class AndroidNetworkLibrary { return URLConnection.guessContentTypeFromName("foo." + extension); } + // Returns true if it can determine that only loopback addresses are configured. + // i.e. if only 127.0.0.1 and ::1 are routable. + // Also returns false if it cannot determine this. + @CalledByNative + static public boolean haveOnlyLoopbackAddresses() { + boolean result = true; + try { + Enumeration list = NetworkInterface.getNetworkInterfaces(); + if (list == null) return false; + + while (list.hasMoreElements()) { + NetworkInterface netIf = (NetworkInterface)list.nextElement(); + try { + if (!netIf.isUp() || netIf.isLoopback()) + continue; + result = false; + break; + } catch (SocketException e) { + continue; + } + } + } catch (SocketException e) { + Log.w(TAG, "could not get network interfaces: " + e); + return false; + } + return result; + } + /** * Validate the server's certificate chain is trusted. * @param certChain The ASN.1 DER encoded bytes for certificates. diff --git a/net/android/network_library.cc b/net/android/network_library.cc index 24a065e..57cf551 100644 --- a/net/android/network_library.cc +++ b/net/android/network_library.cc @@ -64,6 +64,11 @@ bool StoreKeyPair(const uint8* public_key, return ret; } +bool HaveOnlyLoopbackAddresses() { + JNIEnv* env = AttachCurrentThread(); + return Java_AndroidNetworkLibrary_haveOnlyLoopbackAddresses(env); +} + bool GetMimeTypeFromExtension(const std::string& extension, std::string* result) { JNIEnv* env = AttachCurrentThread(); diff --git a/net/android/network_library.h b/net/android/network_library.h index 5e2b8ec..a0a1913 100644 --- a/net/android/network_library.h +++ b/net/android/network_library.h @@ -40,6 +40,11 @@ bool StoreKeyPair(const uint8* public_key, const uint8* private_key, size_t private_len); +// Returns true if it can determine that only loopback addresses are configured. +// i.e. if only 127.0.0.1 and ::1 are routable. +// Also returns false if it cannot determine this. +bool HaveOnlyLoopbackAddresses(); + // Get the mime type (if any) that is associated with the file extension. // Returns true if a corresponding mime type exists. bool GetMimeTypeFromExtension(const std::string& extension, diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 5404204..126fc32 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -57,6 +57,9 @@ #include "googleurl/src/url_canon_ip.h" #include "googleurl/src/url_parse.h" #include "grit/net_resources.h" +#if defined(OS_ANDROID) +#include "net/android/network_library.h" +#endif #include "net/base/dns_util.h" #include "net/base/escape.h" #include "net/base/mime_util.h" @@ -2117,7 +2120,9 @@ bool IPv6Supported() { } bool HaveOnlyLoopbackAddresses() { -#if defined(OS_POSIX) && !defined(OS_ANDROID) +#if defined(OS_ANDROID) + return android::HaveOnlyLoopbackAddresses(); +#elif defined(OS_POSIX) struct ifaddrs* interface_addr = NULL; int rv = getifaddrs(&interface_addr); if (rv != 0) { diff --git a/net/base/net_util.h b/net/base/net_util.h index dabaa0f..790e422 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -370,6 +370,7 @@ NET_EXPORT bool IPv6Supported(); // Returns true if it can determine that only loopback addresses are configured. // i.e. if only 127.0.0.1 and ::1 are routable. +// Also returns false if it cannot determine this. bool HaveOnlyLoopbackAddresses(); // IPAddressNumber is used to represent an IP address's numeric value as an |