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/printing/cloud_print/privet_traffic_detector.h" | 5 #include "chrome/browser/printing/cloud_print/privet_traffic_detector.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 133 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
134 socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source())); | 134 socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source())); |
135 net::IPEndPoint multicast_addr = net::GetMDnsIPEndPoint(address_family_); | 135 net::IPEndPoint multicast_addr = net::GetMDnsIPEndPoint(address_family_); |
136 net::IPAddressNumber address_any(multicast_addr.address().size()); | 136 net::IPAddressNumber address_any(multicast_addr.address().size()); |
137 net::IPEndPoint bind_endpoint(address_any, multicast_addr.port()); | 137 net::IPEndPoint bind_endpoint(address_any, multicast_addr.port()); |
138 socket_->AllowAddressReuse(); | 138 socket_->AllowAddressReuse(); |
139 int rv = socket_->Listen(bind_endpoint); | 139 int rv = socket_->Listen(bind_endpoint); |
140 if (rv < net::OK) | 140 if (rv < net::OK) |
141 return rv; | 141 return rv; |
142 socket_->SetMulticastLoopbackMode(false); | 142 socket_->SetMulticastLoopbackMode(false); |
143 return socket_->JoinGroup(multicast_addr.address()); | 143 return socket_->JoinGroup(multicast_addr.address().bytes()); |
144 } | 144 } |
145 | 145 |
146 bool PrivetTrafficDetector::IsSourceAcceptable() const { | 146 bool PrivetTrafficDetector::IsSourceAcceptable() const { |
147 for (size_t i = 0; i < networks_.size(); ++i) { | 147 for (size_t i = 0; i < networks_.size(); ++i) { |
148 if (net::IPNumberMatchesPrefix(recv_addr_.address(), networks_[i].address, | 148 if (net::IPNumberMatchesPrefix(recv_addr_.address().bytes(), |
| 149 networks_[i].address, |
149 networks_[i].prefix_length)) { | 150 networks_[i].prefix_length)) { |
150 return true; | 151 return true; |
151 } | 152 } |
152 } | 153 } |
153 return false; | 154 return false; |
154 } | 155 } |
155 | 156 |
156 bool PrivetTrafficDetector::IsPrivetPacket(int rv) const { | 157 bool PrivetTrafficDetector::IsPrivetPacket(int rv) const { |
157 if (rv <= static_cast<int>(sizeof(net::dns_protocol::Header)) || | 158 if (rv <= static_cast<int>(sizeof(net::dns_protocol::Header)) || |
158 !IsSourceAcceptable()) { | 159 !IsSourceAcceptable()) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 base::Unretained(this))); | 195 base::Unretained(this))); |
195 } while (rv > 0); | 196 } while (rv > 0); |
196 | 197 |
197 if (rv != net::ERR_IO_PENDING) | 198 if (rv != net::ERR_IO_PENDING) |
198 return rv; | 199 return rv; |
199 | 200 |
200 return net::OK; | 201 return net::OK; |
201 } | 202 } |
202 | 203 |
203 } // namespace cloud_print | 204 } // namespace cloud_print |
OLD | NEW |