OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |