summaryrefslogtreecommitdiffstats
path: root/net/android
diff options
context:
space:
mode:
Diffstat (limited to 'net/android')
-rw-r--r--net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java55
-rw-r--r--net/android/network_library.cc7
-rw-r--r--net/android/network_library.h6
3 files changed, 68 insertions, 0 deletions
diff --git a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
index ef8fa03..28208a7 100644
--- a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
+++ b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
@@ -12,6 +12,8 @@ import android.util.Log;
import org.chromium.base.CalledByNative;
import org.chromium.base.CalledByNativeUnchecked;
+import java.net.Inet6Address;
+import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URLConnection;
@@ -87,6 +89,59 @@ class AndroidNetworkLibrary {
}
/**
+ * @return the network interfaces list (if any) string. The items in
+ * the list string are delimited by a semicolon ";", each item
+ * is a network interface name and address pair and formatted
+ * as "name,address". e.g.
+ * eth0,10.0.0.2;eth0,fe80::5054:ff:fe12:3456
+ * represents a network list string which containts two items.
+ */
+ @CalledByNative
+ static public String getNetworkList() {
+ Enumeration<NetworkInterface> list = null;
+ try {
+ list = NetworkInterface.getNetworkInterfaces();
+ if (list == null) return "";
+ } catch (SocketException e) {
+ Log.w(TAG, "Unable to get network interfaces: " + e);
+ return "";
+ }
+
+ StringBuilder result = new StringBuilder();
+ while (list.hasMoreElements()) {
+ NetworkInterface netIf = list.nextElement();
+ try {
+ // Skip loopback interfaces, and ones which are down.
+ if (!netIf.isUp() || netIf.isLoopback())
+ continue;
+ Enumeration<InetAddress> addressList = netIf.getInetAddresses();
+ while (addressList.hasMoreElements()) {
+ InetAddress address = addressList.nextElement();
+ // Skip loopback addresses configured on non-loopback interfaces.
+ if (address.isLoopbackAddress())
+ continue;
+ StringBuilder addressString = new StringBuilder();
+ addressString.append(netIf.getName());
+ addressString.append(",");
+
+ String ipAddress = address.getHostAddress();
+ if (address instanceof Inet6Address && ipAddress.contains("%")) {
+ ipAddress = ipAddress.substring(0, ipAddress.lastIndexOf("%"));
+ }
+ addressString.append(ipAddress);
+
+ if (result.length() != 0)
+ result.append(";");
+ result.append(addressString.toString());
+ }
+ } catch (SocketException e) {
+ continue;
+ }
+ }
+ return result.toString();
+ }
+
+ /**
* 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 d518abaf..64f11aa 100644
--- a/net/android/network_library.cc
+++ b/net/android/network_library.cc
@@ -69,6 +69,13 @@ bool HaveOnlyLoopbackAddresses() {
return Java_AndroidNetworkLibrary_haveOnlyLoopbackAddresses(env);
}
+std::string GetNetworkList() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> ret =
+ Java_AndroidNetworkLibrary_getNetworkList(env);
+ return ConvertJavaStringToUTF8(ret);
+}
+
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 26b326ab..a0cf7d3 100644
--- a/net/android/network_library.h
+++ b/net/android/network_library.h
@@ -44,6 +44,12 @@ bool StoreKeyPair(const uint8* public_key,
// Also returns false if it cannot determine this.
bool HaveOnlyLoopbackAddresses();
+// Return a string containing a list of network interfaces, each item is a
+// network name and address pair.
+// e.g. "eth0,10.0.0.2;eth0,fe80::5054:ff:fe12:3456" is a result string
+// containing two items.
+std::string GetNetworkList();
+
// 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,