Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Side by Side Diff: net/dns/address_sorter_win.cc

Issue 11528012: [net] Make IPEndPoint::GetFamily() return AddressFamily and add GetSockAddrFamily() to be used when… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update uses of GetFamily in net/dns/ Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/ip_endpoint.cc ('k') | net/dns/dns_config_service_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « net/base/ip_endpoint.cc ('k') | net/dns/dns_config_service_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698