Chromium Code Reviews| Index: net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java |
| diff --git a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java |
| index ef8fa032e8fbc9884a214f14d3a59b2022d3385c..361ff3640bf9bcbebb4aa545bd535c1e59244d50 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 |
|
bulach
2012/09/11 10:16:36
nit: s/. the/. The/
|
| + * the list string is delimited by a semicolon ";", each item |
|
bulach
2012/09/11 10:16:36
nit: s/string is/string are/
|
| + * is a network interface name and address pair and formatted |
| + * as "name,address". i.e. |
| + * 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, "counld not get network interfaces: " + e); |
|
bulach
2012/09/11 10:16:36
nit: s/counld not/Could not/ (or perhaps "Unable t
|
| + 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); |
| + |
| + result.append(addressString.toString()); |
| + if (addressList.hasMoreElements()) |
| + result.append(";"); |
| + } |
| + } 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. |