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

Side by Side Diff: chrome/browser/media/router/discovery/discovery_network_list_posix.cc

Issue 2750453002: Add DiscoveryNetworkMonitor implementation (Closed)
Patch Set: Remove extension test files Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(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.h"
6
7 #include <ifaddrs.h>
8 #include <net/if.h>
9 #include <net/if_arp.h>
10 #include <netinet/in.h>
11 #include <netpacket/packet.h>
12 #include <sys/socket.h>
13 #include <sys/types.h>
14
15 #include "base/logging.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "chrome/browser/media/router/discovery/discovery_network_list_wifi.h"
18 #include "net/base/net_errors.h"
19
20 namespace {
21
22 void GetDiscoveryNetworkIdListImpl(
23 const struct ifaddrs* if_list,
24 std::vector<DiscoveryNetworkId>* network_ids) {
25 std::string ssid;
26 for (; if_list != NULL; if_list = if_list->ifa_next) {
27 const struct sockaddr* addr = if_list->ifa_addr;
28 std::string name(if_list->ifa_name);
29 if (name.size() == 0 || addr->sa_family != AF_PACKET) {
mark a. foltz 2017/05/04 23:16:39 As a future improvement, we could interrogate the
btolsch 2017/05/23 08:55:02 Acknowledged.
30 continue;
31 }
32
33 // |addr| will always be sockaddr_ll when |sa_family| == AF_PACKET.
34 const struct sockaddr_ll* ll_addr =
35 reinterpret_cast<const struct sockaddr_ll*>(addr);
36 if (ll_addr->sll_hatype != ARPHRD_ETHER) {
mark a. foltz 2017/05/04 23:16:39 It would be interesting to see if we could detect
btolsch 2017/05/23 08:55:02 AFAIK, another ioctl is required either way. We c
37 continue;
38 }
39
40 if (MaybeGetWifiSSID(name.data(), &ssid)) {
mark a. foltz 2017/05/04 23:16:38 Just pass |name|.
btolsch 2017/05/23 08:55:02 Done.
41 network_ids->push_back({name, ssid});
42 continue;
43 }
44
45 if (ll_addr->sll_halen == 0) {
46 continue;
47 }
48
49 network_ids->push_back(
50 {name, base::HexEncode(ll_addr->sll_addr, ll_addr->sll_halen)});
51 }
52 }
53
54 } // namespace
55
56 std::vector<DiscoveryNetworkId> GetDiscoveryNetworkIdList() {
57 std::vector<DiscoveryNetworkId> network_ids;
58
59 struct ifaddrs* if_list;
60 if (getifaddrs(&if_list)) {
61 DVLOG(2) << "getifaddrs() error: " << net::ErrorToString(errno);
62 return network_ids;
63 }
64
65 GetDiscoveryNetworkIdListImpl(if_list, &network_ids);
66 freeifaddrs(if_list);
67 return network_ids;
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698