Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: net/base/net_util_posix.cc

Issue 10905207: Implement net::GetNetworkList() for Android. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Refine the patch Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/android/network_library.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util_posix.cc
diff --git a/net/base/net_util_posix.cc b/net/base/net_util_posix.cc
index 8ff720f3e43d0e47e4707eecde5a5a36a25892ea..ecea33f84fff21e876faec9a4d05985dacd527fc 100644
--- a/net/base/net_util_posix.cc
+++ b/net/base/net_util_posix.cc
@@ -9,6 +9,7 @@
#include "base/eintr_wrapper.h"
#include "base/file_path.h"
#include "base/logging.h"
+#include "base/string_tokenizer.h"
#include "base/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "googleurl/src/gurl.h"
@@ -22,6 +23,10 @@
#include <net/if.h>
#include <netinet/in.h>
+#if defined(OS_ANDROID)
+#include "net/android/network_library.h"
+#endif
+
namespace net {
bool FileURLToFilePath(const GURL& url, FilePath* path) {
@@ -60,12 +65,27 @@ bool FileURLToFilePath(const GURL& url, FilePath* path) {
bool GetNetworkList(NetworkInterfaceList* networks) {
#if defined(OS_ANDROID)
- // TODO: Android API doesn't support ifaddrs. This method was only used by
- // P2PMessage. Consider to implement it until really needed. The possible
- // approach is implementing the similar feature by
- // java.net.NetworkInterface through JNI.
- NOTIMPLEMENTED();
- return false;
+ std::string network_list = android::GetNetworkList();
+ StringTokenizer network_interfaces(network_list, ";");
+ while (network_interfaces.GetNext()) {
+ std::string network_item = network_interfaces.token();
+ StringTokenizer network_tokenizer(network_item, ",");
+ std::string name;
+ if (!network_tokenizer.GetNext())
+ continue;
+ name = network_tokenizer.token();
+
+ std::string literal_address;
+ if (!network_tokenizer.GetNext())
+ continue;
+ literal_address = network_tokenizer.token();
+
+ IPAddressNumber address;
+ if (!ParseIPLiteralToNumber(literal_address, &address))
+ continue;
+ networks->push_back(NetworkInterface(name, address));
+ }
+ return true;
#else
// getifaddrs() may require IO operations.
base::ThreadRestrictions::AssertIOAllowed();
« no previous file with comments | « net/android/network_library.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698