| 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 "net/dns/mdns_client.h" | 5 #include "net/dns/mdns_client.h" |
| 6 | 6 |
| 7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/base/net_util.h" | 8 #include "net/base/net_util.h" |
| 9 #include "net/base/network_interfaces.h" | 9 #include "net/base/network_interfaces.h" |
| 10 #include "net/dns/dns_protocol.h" | 10 #include "net/dns/dns_protocol.h" |
| 11 #include "net/dns/mdns_client_impl.h" | 11 #include "net/dns/mdns_client_impl.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const char kMDnsMulticastGroupIPv4[] = "224.0.0.251"; | 17 const char kMDnsMulticastGroupIPv4[] = "224.0.0.251"; |
| 18 const char kMDnsMulticastGroupIPv6[] = "FF02::FB"; | 18 const char kMDnsMulticastGroupIPv6[] = "FF02::FB"; |
| 19 | 19 |
| 20 IPEndPoint GetMDnsIPEndPoint(const char* address) { | 20 IPEndPoint GetMDnsIPEndPoint(const char* address) { |
| 21 IPAddressNumber multicast_group_number; | 21 IPAddressNumber multicast_group_number; |
| 22 bool success = ParseIPLiteralToNumber(address, | 22 bool success = ParseIPLiteralToNumber(address, |
| 23 &multicast_group_number); | 23 &multicast_group_number); |
| 24 DCHECK(success); | 24 DCHECK(success); |
| 25 return IPEndPoint(multicast_group_number, | 25 return IPEndPoint(multicast_group_number, |
| 26 dns_protocol::kDefaultPortMulticast); | 26 dns_protocol::kDefaultPortMulticast); |
| 27 } | 27 } |
| 28 | 28 |
| 29 int Bind(const IPEndPoint& multicast_addr, | 29 int Bind(const IPEndPoint& multicast_addr, |
| 30 uint32 interface_index, | 30 uint32_t interface_index, |
| 31 DatagramServerSocket* socket) { | 31 DatagramServerSocket* socket) { |
| 32 IPAddressNumber address_any(multicast_addr.address().size()); | 32 IPAddressNumber address_any(multicast_addr.address().size()); |
| 33 IPEndPoint bind_endpoint(address_any, multicast_addr.port()); | 33 IPEndPoint bind_endpoint(address_any, multicast_addr.port()); |
| 34 | 34 |
| 35 socket->AllowAddressReuse(); | 35 socket->AllowAddressReuse(); |
| 36 socket->SetMulticastInterface(interface_index); | 36 socket->SetMulticastInterface(interface_index); |
| 37 | 37 |
| 38 int rv = socket->Listen(bind_endpoint); | 38 int rv = socket->Listen(bind_endpoint); |
| 39 if (rv < OK) | 39 if (rv < OK) |
| 40 return rv; | 40 return rv; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 std::sort(interfaces.begin(), interfaces.end()); | 81 std::sort(interfaces.begin(), interfaces.end()); |
| 82 // Interfaces could have multiple addresses. Filter out duplicate entries. | 82 // Interfaces could have multiple addresses. Filter out duplicate entries. |
| 83 interfaces.erase(std::unique(interfaces.begin(), interfaces.end()), | 83 interfaces.erase(std::unique(interfaces.begin(), interfaces.end()), |
| 84 interfaces.end()); | 84 interfaces.end()); |
| 85 return interfaces; | 85 return interfaces; |
| 86 } | 86 } |
| 87 | 87 |
| 88 scoped_ptr<DatagramServerSocket> CreateAndBindMDnsSocket( | 88 scoped_ptr<DatagramServerSocket> CreateAndBindMDnsSocket( |
| 89 AddressFamily address_family, | 89 AddressFamily address_family, |
| 90 uint32 interface_index) { | 90 uint32_t interface_index) { |
| 91 scoped_ptr<DatagramServerSocket> socket( | 91 scoped_ptr<DatagramServerSocket> socket( |
| 92 new UDPServerSocket(NULL, NetLog::Source())); | 92 new UDPServerSocket(NULL, NetLog::Source())); |
| 93 | 93 |
| 94 IPEndPoint multicast_addr = GetMDnsIPEndPoint(address_family); | 94 IPEndPoint multicast_addr = GetMDnsIPEndPoint(address_family); |
| 95 int rv = Bind(multicast_addr, interface_index, socket.get()); | 95 int rv = Bind(multicast_addr, interface_index, socket.get()); |
| 96 if (rv != OK) { | 96 if (rv != OK) { |
| 97 socket.reset(); | 97 socket.reset(); |
| 98 VLOG(1) << "Bind failed, endpoint=" << multicast_addr.ToStringWithoutPort() | 98 VLOG(1) << "Bind failed, endpoint=" << multicast_addr.ToStringWithoutPort() |
| 99 << ", error=" << rv; | 99 << ", error=" << rv; |
| 100 } | 100 } |
| 101 return socket.Pass(); | 101 return socket.Pass(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace net | 104 } // namespace net |
| OLD | NEW |