| 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 "cloud_print/gcp20/prototype/dns_sd_server.h" | 5 #include "cloud_print/gcp20/prototype/dns_sd_server.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 net::IPAddressNumber local_ip_any; | 116 net::IPAddressNumber local_ip_any; |
| 117 bool success = net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_any); | 117 bool success = net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_any); |
| 118 DCHECK(success); | 118 DCHECK(success); |
| 119 | 119 |
| 120 net::IPAddressNumber multicast_dns_ip_address; | 120 net::IPAddressNumber multicast_dns_ip_address; |
| 121 success = net::ParseIPLiteralToNumber(kDefaultIpAddressMulticast, | 121 success = net::ParseIPLiteralToNumber(kDefaultIpAddressMulticast, |
| 122 &multicast_dns_ip_address); | 122 &multicast_dns_ip_address); |
| 123 DCHECK(success); | 123 DCHECK(success); |
| 124 | 124 |
| 125 | 125 |
| 126 socket_.reset(new net::UDPSocket(net::DatagramSocket::DEFAULT_BIND, | 126 socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source())); |
| 127 net::RandIntCallback(), NULL, | |
| 128 net::NetLog::Source())); | |
| 129 | 127 |
| 130 net::IPEndPoint local_address = net::IPEndPoint(local_ip_any, | 128 net::IPEndPoint local_address = net::IPEndPoint(local_ip_any, |
| 131 kDefaultPortMulticast); | 129 kDefaultPortMulticast); |
| 132 multicast_address_ = net::IPEndPoint(multicast_dns_ip_address, | 130 multicast_address_ = net::IPEndPoint(multicast_dns_ip_address, |
| 133 kDefaultPortMulticast); | 131 kDefaultPortMulticast); |
| 134 | 132 |
| 135 socket_->AllowAddressReuse(); | 133 socket_->AllowAddressReuse(); |
| 136 | 134 |
| 137 int status = socket_->Bind(local_address); | 135 int status = socket_->Listen(local_address); |
| 138 if (status < 0) | 136 if (status < 0) |
| 139 return false; | 137 return false; |
| 140 | 138 |
| 141 socket_->SetMulticastLoopbackMode(false); | 139 socket_->SetMulticastLoopbackMode(false); |
| 142 status = socket_->JoinGroup(multicast_dns_ip_address); | 140 status = socket_->JoinGroup(multicast_dns_ip_address); |
| 143 | 141 |
| 144 if (status < 0) | 142 if (status < 0) |
| 145 return false; | 143 return false; |
| 146 | |
| 147 DCHECK(socket_->is_connected()); | |
| 148 | |
| 149 return true; | 144 return true; |
| 150 } | 145 } |
| 151 | 146 |
| 152 void DnsSdServer::ProcessMessage(int len, net::IOBufferWithSize* buf) { | 147 void DnsSdServer::ProcessMessage(int len, net::IOBufferWithSize* buf) { |
| 153 VLOG(1) << "Received new message with length: " << len; | 148 VLOG(1) << "Received new message with length: " << len; |
| 154 | 149 |
| 155 // Parse the message. | 150 // Parse the message. |
| 156 DnsPacketParser parser(buf->data(), len); | 151 DnsPacketParser parser(buf->data(), len); |
| 157 | 152 |
| 158 if (!parser.IsValid()) // Was unable to parse header. | 153 if (!parser.IsValid()) // Was unable to parse header. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 316 |
| 322 uint32 DnsSdServer::GetCurrentTLL() const { | 317 uint32 DnsSdServer::GetCurrentTLL() const { |
| 323 uint32 current_ttl = (time_until_live_ - base::Time::Now()).InSeconds(); | 318 uint32 current_ttl = (time_until_live_ - base::Time::Now()).InSeconds(); |
| 324 if (time_until_live_ < base::Time::Now() || current_ttl == 0) { | 319 if (time_until_live_ < base::Time::Now() || current_ttl == 0) { |
| 325 // This should not be reachable. But still we don't need to fail. | 320 // This should not be reachable. But still we don't need to fail. |
| 326 current_ttl = 1; // Service is still alive. | 321 current_ttl = 1; // Service is still alive. |
| 327 LOG(ERROR) << "|current_ttl| was equal to zero."; | 322 LOG(ERROR) << "|current_ttl| was equal to zero."; |
| 328 } | 323 } |
| 329 return current_ttl; | 324 return current_ttl; |
| 330 } | 325 } |
| OLD | NEW |