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

Unified Diff: chrome/browser/media/router/discovery/discovery_network_list_wifi_linux.cc

Issue 2750453002: Add DiscoveryNetworkMonitor implementation (Closed)
Patch Set: Respond to mfoltz' comments, add chrome.dial API back with tests Created 3 years, 8 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
Index: chrome/browser/media/router/discovery/discovery_network_list_wifi_linux.cc
diff --git a/chrome/browser/media/router/discovery/discovery_network_list_wifi_linux.cc b/chrome/browser/media/router/discovery/discovery_network_list_wifi_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4ff7f289c2040498d7684907895fe9ce5e77976c
--- /dev/null
+++ b/chrome/browser/media/router/discovery/discovery_network_list_wifi_linux.cc
@@ -0,0 +1,39 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/router/discovery/discovery_network_list_wifi.h"
+
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <linux/wireless.h>
+
+#include "base/files/scoped_file.h"
+#include "base/logging.h"
+#include "net/base/network_interfaces_linux.h"
+
+bool MaybeGetWifiSSID(const char* if_name, std::string* ssid_out) {
+ DCHECK(if_name);
mark a. foltz 2017/04/26 22:25:12 DCHECK(ssid_out)
btolsch 2017/05/03 22:03:09 Done.
+
+ base::ScopedFD ioctl_socket(socket(AF_INET, SOCK_DGRAM, 0));
+ if (!ioctl_socket.is_valid())
+ return false;
+ struct iwreq wreq = {};
+ strncpy(wreq.ifr_name, if_name, IFNAMSIZ - 1);
mark a. foltz 2017/04/26 22:25:11 Is wreq.ifr_name guaranteed to hold IFNAMSIZE byte
btolsch 2017/05/03 22:03:09 Yes, wreq.ifr_name is defined as IFNAMSIZ bytes (u
+
+ char ssid[IW_ESSID_MAX_SIZE + 1] = {0};
+ std::string maybe_ssid;
+ wreq.u.essid.pointer = ssid;
+ wreq.u.essid.length = IW_ESSID_MAX_SIZE;
+ if (ioctl(ioctl_socket.get(), SIOCGIWESSID, &wreq) != -1)
+ maybe_ssid.assign(ssid);
mark a. foltz 2017/04/26 22:25:12 Are you certain ssid will be null terminated?
btolsch 2017/05/03 22:03:09 Yes. |ssid| above is defined with an extra byte w
+
+ if (maybe_ssid.size() > 0) {
+ *ssid_out = std::move(maybe_ssid);
mark a. foltz 2017/04/26 22:25:12 Can you just assign ssid to ssid_out directly?
btolsch 2017/05/03 22:03:09 D'oh, bad inlining by me. Done.
+ return true;
+ }
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698