OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/router/discovery/discovery_network_list_wifi.h" |
| 6 |
| 7 #include <string.h> |
| 8 #include <sys/ioctl.h> |
| 9 #include <sys/socket.h> |
| 10 #include <sys/types.h> |
| 11 |
| 12 #include <linux/wireless.h> |
| 13 |
| 14 #include "base/files/scoped_file.h" |
| 15 #include "base/logging.h" |
| 16 #include "net/base/network_interfaces_linux.h" |
| 17 |
| 18 bool MaybeGetWifiSSID(const std::string& if_name, std::string* ssid_out) { |
| 19 DCHECK(ssid_out); |
| 20 |
| 21 base::ScopedFD ioctl_socket(socket(AF_INET, SOCK_DGRAM, 0)); |
| 22 if (!ioctl_socket.is_valid()) |
| 23 return false; |
| 24 struct iwreq wreq = {}; |
| 25 strncpy(wreq.ifr_name, if_name.data(), IFNAMSIZ - 1); |
| 26 |
| 27 char ssid[IW_ESSID_MAX_SIZE + 1] = {0}; |
| 28 wreq.u.essid.pointer = ssid; |
| 29 wreq.u.essid.length = IW_ESSID_MAX_SIZE; |
| 30 if (ioctl(ioctl_socket.get(), SIOCGIWESSID, &wreq) == -1) { |
| 31 return false; |
| 32 } |
| 33 if (ssid[0] != 0) { |
| 34 ssid_out->assign(ssid); |
| 35 return true; |
| 36 } |
| 37 return false; |
| 38 } |
OLD | NEW |