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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 output_buffer_(reinterpret_cast<SOCKET_ADDRESS_LIST*>( | 51 output_buffer_(reinterpret_cast<SOCKET_ADDRESS_LIST*>( |
52 malloc(buffer_size_))), | 52 malloc(buffer_size_))), |
53 success_(false) { | 53 success_(false) { |
54 input_buffer_->iAddressCount = list.size(); | 54 input_buffer_->iAddressCount = list.size(); |
55 SOCKADDR_STORAGE* storage = reinterpret_cast<SOCKADDR_STORAGE*>( | 55 SOCKADDR_STORAGE* storage = reinterpret_cast<SOCKADDR_STORAGE*>( |
56 input_buffer_->Address + input_buffer_->iAddressCount); | 56 input_buffer_->Address + input_buffer_->iAddressCount); |
57 | 57 |
58 for (size_t i = 0; i < list.size(); ++i) { | 58 for (size_t i = 0; i < list.size(); ++i) { |
59 IPEndPoint ipe = list[i]; | 59 IPEndPoint ipe = list[i]; |
60 // Addresses must be sockaddr_in6. | 60 // Addresses must be sockaddr_in6. |
61 if (ipe.GetFamily() == AF_INET) { | 61 if (ipe.GetFamily() == ADDRESS_FAMILY_IPV4) { |
62 ipe = IPEndPoint(ConvertIPv4NumberToIPv6Number(ipe.address()), | 62 ipe = IPEndPoint(ConvertIPv4NumberToIPv6Number(ipe.address()), |
63 ipe.port()); | 63 ipe.port()); |
64 } | 64 } |
65 | 65 |
66 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(storage + i); | 66 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(storage + i); |
67 socklen_t addr_len = sizeof(SOCKADDR_STORAGE); | 67 socklen_t addr_len = sizeof(SOCKADDR_STORAGE); |
68 bool result = ipe.ToSockAddr(addr, &addr_len); | 68 bool result = ipe.ToSockAddr(addr, &addr_len); |
69 DCHECK(result); | 69 DCHECK(result); |
70 input_buffer_->Address[i].lpSockaddr = addr; | 70 input_buffer_->Address[i].lpSockaddr = addr; |
71 input_buffer_->Address[i].iSockaddrLength = addr_len; | 71 input_buffer_->Address[i].iSockaddrLength = addr_len; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 AddressSorterWinXP() {} | 158 AddressSorterWinXP() {} |
159 virtual ~AddressSorterWinXP() {} | 159 virtual ~AddressSorterWinXP() {} |
160 | 160 |
161 // AddressSorter: | 161 // AddressSorter: |
162 virtual void Sort(const AddressList& list, | 162 virtual void Sort(const AddressList& list, |
163 const CallbackType& callback) const OVERRIDE { | 163 const CallbackType& callback) const OVERRIDE { |
164 AddressList list_ipv4; | 164 AddressList list_ipv4; |
165 AddressList list_ipv6; | 165 AddressList list_ipv6; |
166 for (size_t i = 0; i < list.size(); ++i) { | 166 for (size_t i = 0; i < list.size(); ++i) { |
167 const IPEndPoint& ipe = list[i]; | 167 const IPEndPoint& ipe = list[i]; |
168 if (ipe.GetFamily() == AF_INET) { | 168 if (ipe.GetFamily() == ADDRESS_FAMILY_IPV4) { |
169 list_ipv4.push_back(ipe); | 169 list_ipv4.push_back(ipe); |
170 } else { | 170 } else { |
171 list_ipv6.push_back(ipe); | 171 list_ipv6.push_back(ipe); |
172 } | 172 } |
173 } | 173 } |
174 if (!list_ipv6.empty()) { | 174 if (!list_ipv6.empty()) { |
175 sorter_.Sort(list_ipv6, base::Bind(&MergeResults, callback, list_ipv4)); | 175 sorter_.Sort(list_ipv6, base::Bind(&MergeResults, callback, list_ipv4)); |
176 } else { | 176 } else { |
177 NOTREACHED() << "Should not be called with IPv4-only addresses."; | 177 NOTREACHED() << "Should not be called with IPv4-only addresses."; |
178 callback.Run(true, list); | 178 callback.Run(true, list); |
(...skipping 10 matching lines...) Expand all Loading... |
189 | 189 |
190 // static | 190 // static |
191 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { | 191 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { |
192 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 192 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
193 return scoped_ptr<AddressSorter>(new AddressSorterWinXP()); | 193 return scoped_ptr<AddressSorter>(new AddressSorterWinXP()); |
194 return scoped_ptr<AddressSorter>(new AddressSorterWin()); | 194 return scoped_ptr<AddressSorter>(new AddressSorterWin()); |
195 } | 195 } |
196 | 196 |
197 } // namespace net | 197 } // namespace net |
198 | 198 |
OLD | NEW |