Chromium Code Reviews| Index: chrome/browser/net/discovery_network_list_wifi_linux.cc |
| diff --git a/chrome/browser/net/discovery_network_list_wifi_linux.cc b/chrome/browser/net/discovery_network_list_wifi_linux.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..417526070a1382d6ba80ea94aa64fd10751c4b04 |
| --- /dev/null |
| +++ b/chrome/browser/net/discovery_network_list_wifi_linux.cc |
| @@ -0,0 +1,37 @@ |
| +// 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/net/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/logging.h" |
| + |
| +bool MaybeGetWifiSSID(const char* if_name, std::string* ssid) { |
|
imcheng
2017/03/14 22:45:35
Can this be reused? https://cs.chromium.org/chromi
btolsch
2017/04/03 10:16:35
Done. Should I move it out of the internal namesp
|
| + DCHECK(if_name); |
| + |
| + struct iwreq iwreq; |
| + memset(&iwreq, 0, sizeof(iwreq)); |
| + |
| + int sock = socket(AF_INET, SOCK_DGRAM, 0); |
| + if (sock == -1) { |
| + return false; |
| + } |
| + |
| + strncpy(iwreq.ifr_name, if_name, IFNAMSIZ); |
| + char id[IW_ESSID_MAX_SIZE]; |
| + iwreq.u.essid.pointer = id; |
| + iwreq.u.essid.length = IW_ESSID_MAX_SIZE; |
| + |
| + if (ioctl(sock, SIOCGIWESSID, &iwreq) == -1) { |
| + return false; |
| + } |
| + ssid->assign(std::string(id, iwreq.u.essid.length)); |
| + return true; |
| +} |