| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/address_sorter.h" | 5 #include "net/dns/address_sorter.h" |
| 6 | 6 |
| 7 #include <winsock2.h> | 7 #include <winsock2.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 malloc(buffer_size_))), | 53 malloc(buffer_size_))), |
| 54 success_(false) { | 54 success_(false) { |
| 55 input_buffer_->iAddressCount = list.size(); | 55 input_buffer_->iAddressCount = list.size(); |
| 56 SOCKADDR_STORAGE* storage = reinterpret_cast<SOCKADDR_STORAGE*>( | 56 SOCKADDR_STORAGE* storage = reinterpret_cast<SOCKADDR_STORAGE*>( |
| 57 input_buffer_->Address + input_buffer_->iAddressCount); | 57 input_buffer_->Address + input_buffer_->iAddressCount); |
| 58 | 58 |
| 59 for (size_t i = 0; i < list.size(); ++i) { | 59 for (size_t i = 0; i < list.size(); ++i) { |
| 60 IPEndPoint ipe = list[i]; | 60 IPEndPoint ipe = list[i]; |
| 61 // Addresses must be sockaddr_in6. | 61 // Addresses must be sockaddr_in6. |
| 62 if (ipe.GetFamily() == ADDRESS_FAMILY_IPV4) { | 62 if (ipe.GetFamily() == ADDRESS_FAMILY_IPV4) { |
| 63 ipe = IPEndPoint(ConvertIPv4NumberToIPv6Number(ipe.address()), | 63 ipe = IPEndPoint(ConvertIPv4NumberToIPv6Number(ipe.address().bytes()), |
| 64 ipe.port()); | 64 ipe.port()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(storage + i); | 67 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(storage + i); |
| 68 socklen_t addr_len = sizeof(SOCKADDR_STORAGE); | 68 socklen_t addr_len = sizeof(SOCKADDR_STORAGE); |
| 69 bool result = ipe.ToSockAddr(addr, &addr_len); | 69 bool result = ipe.ToSockAddr(addr, &addr_len); |
| 70 DCHECK(result); | 70 DCHECK(result); |
| 71 input_buffer_->Address[i].lpSockaddr = addr; | 71 input_buffer_->Address[i].lpSockaddr = addr; |
| 72 input_buffer_->Address[i].iSockaddrLength = addr_len; | 72 input_buffer_->Address[i].iSockaddrLength = addr_len; |
| 73 } | 73 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (success_) { | 109 if (success_) { |
| 110 list.reserve(output_buffer_->iAddressCount); | 110 list.reserve(output_buffer_->iAddressCount); |
| 111 for (int i = 0; i < output_buffer_->iAddressCount; ++i) { | 111 for (int i = 0; i < output_buffer_->iAddressCount; ++i) { |
| 112 IPEndPoint ipe; | 112 IPEndPoint ipe; |
| 113 bool result = | 113 bool result = |
| 114 ipe.FromSockAddr(output_buffer_->Address[i].lpSockaddr, | 114 ipe.FromSockAddr(output_buffer_->Address[i].lpSockaddr, |
| 115 output_buffer_->Address[i].iSockaddrLength); | 115 output_buffer_->Address[i].iSockaddrLength); |
| 116 DCHECK(result) << "Unable to roundtrip between IPEndPoint and " | 116 DCHECK(result) << "Unable to roundtrip between IPEndPoint and " |
| 117 << "SOCKET_ADDRESS!"; | 117 << "SOCKET_ADDRESS!"; |
| 118 // Unmap V4MAPPED IPv6 addresses so that Happy Eyeballs works. | 118 // Unmap V4MAPPED IPv6 addresses so that Happy Eyeballs works. |
| 119 if (IsIPv4Mapped(ipe.address())) { | 119 if (IsIPv4Mapped(ipe.address().bytes())) { |
| 120 ipe = IPEndPoint(ConvertIPv4MappedToIPv4(ipe.address()), | 120 ipe = IPEndPoint(ConvertIPv4MappedToIPv4(ipe.address().bytes()), |
| 121 ipe.port()); | 121 ipe.port()); |
| 122 } | 122 } |
| 123 list.push_back(ipe); | 123 list.push_back(ipe); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 callback_.Run(success_, list); | 126 callback_.Run(success_, list); |
| 127 } | 127 } |
| 128 | 128 |
| 129 const CallbackType callback_; | 129 const CallbackType callback_; |
| 130 const size_t buffer_size_; | 130 const size_t buffer_size_; |
| 131 scoped_ptr<SOCKET_ADDRESS_LIST, base::FreeDeleter> input_buffer_; | 131 scoped_ptr<SOCKET_ADDRESS_LIST, base::FreeDeleter> input_buffer_; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 // static | 194 // static |
| 195 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { | 195 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { |
| 196 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 196 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 197 return scoped_ptr<AddressSorter>(new AddressSorterWinXP()); | 197 return scoped_ptr<AddressSorter>(new AddressSorterWinXP()); |
| 198 return scoped_ptr<AddressSorter>(new AddressSorterWin()); | 198 return scoped_ptr<AddressSorter>(new AddressSorterWin()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace net | 201 } // namespace net |
| 202 | 202 |
| OLD | NEW |