Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 | 8 |
| 9 #include "base/eintr_wrapper.h" | 9 #include "base/eintr_wrapper.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_tokenizer.h" | |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #if defined(OS_ANDROID) | |
| 17 #include "net/android/network_library.h" | |
| 18 #endif | |
|
wtc
2012/09/11 23:04:49
The Chromium Coding Style page recommends that pla
Shouqun Liu
2012/09/12 01:06:08
Done.
| |
| 15 #include "net/base/escape.h" | 19 #include "net/base/escape.h" |
| 16 #include "net/base/ip_endpoint.h" | 20 #include "net/base/ip_endpoint.h" |
| 17 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 18 | 22 |
| 19 #if !defined(OS_ANDROID) | 23 #if !defined(OS_ANDROID) |
| 20 #include <ifaddrs.h> | 24 #include <ifaddrs.h> |
| 21 #endif | 25 #endif |
| 22 #include <net/if.h> | 26 #include <net/if.h> |
| 23 #include <netinet/in.h> | 27 #include <netinet/in.h> |
| 24 | 28 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 53 old_path.swap(new_path); | 57 old_path.swap(new_path); |
| 54 } while (new_path != old_path); | 58 } while (new_path != old_path); |
| 55 | 59 |
| 56 file_path_str.assign(old_path); | 60 file_path_str.assign(old_path); |
| 57 | 61 |
| 58 return !file_path_str.empty(); | 62 return !file_path_str.empty(); |
| 59 } | 63 } |
| 60 | 64 |
| 61 bool GetNetworkList(NetworkInterfaceList* networks) { | 65 bool GetNetworkList(NetworkInterfaceList* networks) { |
| 62 #if defined(OS_ANDROID) | 66 #if defined(OS_ANDROID) |
| 63 // TODO: Android API doesn't support ifaddrs. This method was only used by | 67 std::string network_list = android::GetNetworkList(); |
| 64 // P2PMessage. Consider to implement it until really needed. The possible | 68 StringTokenizer network_interfaces(network_list, ";"); |
| 65 // approach is implementing the similar feature by | 69 while (network_interfaces.GetNext()) { |
| 66 // java.net.NetworkInterface through JNI. | 70 std::string network_item = network_interfaces.token(); |
| 67 NOTIMPLEMENTED(); | 71 StringTokenizer network_tokenizer(network_item, ","); |
| 68 return false; | 72 std::string name; |
| 73 if (!network_tokenizer.GetNext()) | |
| 74 continue; | |
| 75 name = network_tokenizer.token(); | |
| 76 | |
| 77 std::string literal_address; | |
| 78 if (!network_tokenizer.GetNext()) | |
| 79 continue; | |
| 80 literal_address = network_tokenizer.token(); | |
| 81 | |
| 82 IPAddressNumber address; | |
| 83 if (!ParseIPLiteralToNumber(literal_address, &address)) | |
| 84 continue; | |
| 85 networks->push_back(NetworkInterface(name, address)); | |
| 86 } | |
| 87 return true; | |
| 69 #else | 88 #else |
| 70 // getifaddrs() may require IO operations. | 89 // getifaddrs() may require IO operations. |
| 71 base::ThreadRestrictions::AssertIOAllowed(); | 90 base::ThreadRestrictions::AssertIOAllowed(); |
| 72 | 91 |
| 73 ifaddrs *interfaces; | 92 ifaddrs *interfaces; |
| 74 if (getifaddrs(&interfaces) < 0) { | 93 if (getifaddrs(&interfaces) < 0) { |
| 75 PLOG(ERROR) << "getifaddrs"; | 94 PLOG(ERROR) << "getifaddrs"; |
| 76 return false; | 95 return false; |
| 77 } | 96 } |
| 78 | 97 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 134 } |
| 116 } | 135 } |
| 117 | 136 |
| 118 freeifaddrs(interfaces); | 137 freeifaddrs(interfaces); |
| 119 | 138 |
| 120 return true; | 139 return true; |
| 121 #endif | 140 #endif |
| 122 } | 141 } |
| 123 | 142 |
| 124 } // namespace net | 143 } // namespace net |
| OLD | NEW |