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

Side by Side Diff: chrome/browser/local_discovery/privet_traffic_detector.cc

Issue 730623002: Rename network_prefix to prefix_length in NetworkInterface structure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | content/common/p2p_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/local_discovery/privet_traffic_detector.h" 5 #include "chrome/browser/local_discovery/privet_traffic_detector.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/sys_byteorder.h" 8 #include "base/sys_byteorder.h"
9 #include "net/base/dns_util.h" 9 #include "net/base/dns_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 14 matching lines...) Expand all
25 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 25 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
26 net::NetworkInterfaceList networks; 26 net::NetworkInterfaceList networks;
27 if (!GetNetworkList(&networks, net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)) 27 if (!GetNetworkList(&networks, net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES))
28 return; 28 return;
29 29
30 net::NetworkInterfaceList ip4_networks; 30 net::NetworkInterfaceList ip4_networks;
31 for (size_t i = 0; i < networks.size(); ++i) { 31 for (size_t i = 0; i < networks.size(); ++i) {
32 net::AddressFamily address_family = 32 net::AddressFamily address_family =
33 net::GetAddressFamily(networks[i].address); 33 net::GetAddressFamily(networks[i].address);
34 if (address_family == net::ADDRESS_FAMILY_IPV4 && 34 if (address_family == net::ADDRESS_FAMILY_IPV4 &&
35 networks[i].network_prefix >= 24) { 35 networks[i].prefix_length >= 24) {
36 ip4_networks.push_back(networks[i]); 36 ip4_networks.push_back(networks[i]);
37 } 37 }
38 } 38 }
39 39
40 net::IPAddressNumber localhost_prefix(4, 0); 40 net::IPAddressNumber localhost_prefix(4, 0);
41 localhost_prefix[0] = 127; 41 localhost_prefix[0] = 127;
42 ip4_networks.push_back( 42 ip4_networks.push_back(
43 net::NetworkInterface("lo", 43 net::NetworkInterface("lo",
44 "lo", 44 "lo",
45 0, 45 0,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 int rv = socket_->Listen(bind_endpoint); 134 int rv = socket_->Listen(bind_endpoint);
135 if (rv < net::OK) 135 if (rv < net::OK)
136 return rv; 136 return rv;
137 socket_->SetMulticastLoopbackMode(false); 137 socket_->SetMulticastLoopbackMode(false);
138 return socket_->JoinGroup(multicast_addr.address()); 138 return socket_->JoinGroup(multicast_addr.address());
139 } 139 }
140 140
141 bool PrivetTrafficDetector::IsSourceAcceptable() const { 141 bool PrivetTrafficDetector::IsSourceAcceptable() const {
142 for (size_t i = 0; i < networks_.size(); ++i) { 142 for (size_t i = 0; i < networks_.size(); ++i) {
143 if (net::IPNumberMatchesPrefix(recv_addr_.address(), networks_[i].address, 143 if (net::IPNumberMatchesPrefix(recv_addr_.address(), networks_[i].address,
144 networks_[i].network_prefix)) { 144 networks_[i].prefix_length)) {
145 return true; 145 return true;
146 } 146 }
147 } 147 }
148 return false; 148 return false;
149 } 149 }
150 150
151 bool PrivetTrafficDetector::IsPrivetPacket(int rv) const { 151 bool PrivetTrafficDetector::IsPrivetPacket(int rv) const {
152 if (rv <= static_cast<int>(sizeof(net::dns_protocol::Header)) || 152 if (rv <= static_cast<int>(sizeof(net::dns_protocol::Header)) ||
153 !IsSourceAcceptable()) { 153 !IsSourceAcceptable()) {
154 return false; 154 return false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 base::Unretained(this))); 189 base::Unretained(this)));
190 } while (rv > 0); 190 } while (rv > 0);
191 191
192 if (rv != net::ERR_IO_PENDING) 192 if (rv != net::ERR_IO_PENDING)
193 return rv; 193 return rv;
194 194
195 return net::OK; 195 return net::OK;
196 } 196 }
197 197
198 } // namespace local_discovery 198 } // namespace local_discovery
OLDNEW
« no previous file with comments | « no previous file | content/common/p2p_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698