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 char* if_name, std::string* ssid_out) { | |
19 DCHECK(if_name); | |
mark a. foltz
2017/04/26 22:25:12
DCHECK(ssid_out)
btolsch
2017/05/03 22:03:09
Done.
| |
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, 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
| |
26 | |
27 char ssid[IW_ESSID_MAX_SIZE + 1] = {0}; | |
28 std::string maybe_ssid; | |
29 wreq.u.essid.pointer = ssid; | |
30 wreq.u.essid.length = IW_ESSID_MAX_SIZE; | |
31 if (ioctl(ioctl_socket.get(), SIOCGIWESSID, &wreq) != -1) | |
32 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
| |
33 | |
34 if (maybe_ssid.size() > 0) { | |
35 *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.
| |
36 return true; | |
37 } | |
38 return false; | |
39 } | |
OLD | NEW |