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

Unified Diff: net/base/net_util_linux.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/base/net_util_linux.h ('k') | net/base/net_util_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util_linux.cc
diff --git a/net/base/net_util_linux.cc b/net/base/net_util_linux.cc
index a3489128007b2d6441f0519b2fb93d3ff95c25f1..8342597032d567c57d723de2f9cfdad16ae97c6a 100644
--- a/net/base/net_util_linux.cc
+++ b/net/base/net_util_linux.cc
@@ -18,7 +18,6 @@
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
-#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
@@ -69,7 +68,11 @@ bool TryConvertNativeToNetIPAttributes(int native_attributes,
namespace internal {
inline const unsigned char* GetIPAddressData(const IPAddressNumber& ip) {
- return vector_as_array(&ip);
+#if defined(OS_ANDROID)
+ return ip.begin();
+#else
+ return ip.data();
+#endif
}
// Gets the connection type for interface |ifname| by checking for wireless
@@ -100,6 +103,21 @@ NetworkChangeNotifier::ConnectionType GetInterfaceConnectionType(
return NetworkChangeNotifier::CONNECTION_UNKNOWN;
}
+std::string GetInterfaceSSID(const std::string& ifname) {
+ base::ScopedFD ioctl_socket(socket(AF_INET, SOCK_DGRAM, 0));
+ if (!ioctl_socket.is_valid())
+ return "";
+ struct iwreq wreq = {};
+ strncpy(wreq.ifr_name, ifname.c_str(), IFNAMSIZ - 1);
+
+ char ssid[IW_ESSID_MAX_SIZE + 1] = {0};
+ wreq.u.essid.pointer = ssid;
+ wreq.u.essid.length = IW_ESSID_MAX_SIZE;
+ if (ioctl(ioctl_socket.get(), SIOCGIWESSID, &wreq) != -1)
+ return ssid;
+ return "";
+}
+
bool GetNetworkListImpl(
NetworkInterfaceList* networks,
int policy,
@@ -169,6 +187,23 @@ bool GetNetworkListImpl(
return true;
}
+std::string GetWifiSSIDFromInterfaceListInternal(
+ const NetworkInterfaceList& interfaces,
+ internal::GetInterfaceSSIDFunction get_interface_ssid) {
+ std::string connected_ssid;
+ for (size_t i = 0; i < interfaces.size(); ++i) {
+ if (interfaces[i].type != NetworkChangeNotifier::CONNECTION_WIFI)
+ return "";
+ std::string ssid = get_interface_ssid(interfaces[i].name);
+ if (i == 0) {
+ connected_ssid = ssid;
+ } else if (ssid != connected_ssid) {
+ return "";
+ }
+ }
+ return connected_ssid;
+}
+
} // namespace internal
bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
@@ -183,4 +218,13 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
&internal::AddressTrackerLinux::GetInterfaceName);
}
+std::string GetWifiSSID() {
+ NetworkInterfaceList networks;
+ if (GetNetworkList(&networks, net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)) {
+ return internal::GetWifiSSIDFromInterfaceListInternal(
+ networks, internal::GetInterfaceSSID);
+ }
+ return "";
+}
+
} // namespace net
« no previous file with comments | « net/base/net_util_linux.h ('k') | net/base/net_util_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698