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

Side by Side Diff: net/socket/socks_client_socket.cc

Issue 10309002: Reimplements net::AddressList without struct addrinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_EXPORT to *PortOnAddressList. Created 8 years, 7 months 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
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/socket/socks_client_socket.h" 5 #include "net/socket/socks_client_socket.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "net/base/net_log.h" 12 #include "net/base/net_log.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/base/sys_addrinfo.h"
15 #include "net/socket/client_socket_handle.h" 14 #include "net/socket/client_socket_handle.h"
16 15
17 namespace net { 16 namespace net {
18 17
19 // Every SOCKS server requests a user-id from the client. It is optional 18 // Every SOCKS server requests a user-id from the client. It is optional
20 // and we send an empty string. 19 // and we send an empty string.
21 static const char kEmptyUserId[] = ""; 20 static const char kEmptyUserId[] = "";
22 21
23 // For SOCKS4, the client sends 8 bytes plus the size of the user-id. 22 // For SOCKS4, the client sends 8 bytes plus the size of the user-id.
24 static const unsigned int kWriteHeaderSize = 8; 23 static const unsigned int kWriteHeaderSize = 8;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 return OK; 299 return OK;
301 } 300 }
302 301
303 // Builds the buffer that is to be sent to the server. 302 // Builds the buffer that is to be sent to the server.
304 const std::string SOCKSClientSocket::BuildHandshakeWriteBuffer() const { 303 const std::string SOCKSClientSocket::BuildHandshakeWriteBuffer() const {
305 SOCKS4ServerRequest request; 304 SOCKS4ServerRequest request;
306 request.version = kSOCKSVersion4; 305 request.version = kSOCKSVersion4;
307 request.command = kSOCKSStreamRequest; 306 request.command = kSOCKSStreamRequest;
308 request.nw_port = base::HostToNet16(host_request_info_.port()); 307 request.nw_port = base::HostToNet16(host_request_info_.port());
309 308
310 const struct addrinfo* ai = addresses_.head(); 309 DCHECK(!addresses_.empty());
311 DCHECK(ai); 310 const IPEndPoint& ipe = addresses_.front();
312 311
313 // We disabled IPv6 results when resolving the hostname, so none of the 312 // We disabled IPv6 results when resolving the hostname, so none of the
314 // results in the list will be IPv6. 313 // results in the list will be IPv6.
315 // TODO(eroman): we only ever use the first address in the list. It would be 314 // TODO(eroman): we only ever use the first address in the list. It would be
316 // more robust to try all the IP addresses we have before 315 // more robust to try all the IP addresses we have before
317 // failing the connect attempt. 316 // failing the connect attempt.
318 CHECK_EQ(AF_INET, ai->ai_addr->sa_family); 317 CHECK_EQ(AF_INET, ipe.GetFamily());
319 struct sockaddr_in* ipv4_host = 318 memcpy(&request.ip, &ipe.address()[0], ipe.address().size());
eroman 2012/05/04 01:08:41 I'm not sure how I feel about this... The assumpti
szym 2012/05/04 02:38:29 Currently, IPAddressNumber stores data in same ord
eroman 2012/05/04 04:20:22 My paranoia stems from doing a memcpy() from a sou
320 reinterpret_cast<struct sockaddr_in*>(ai->ai_addr);
321 memcpy(&request.ip, &ipv4_host->sin_addr, sizeof(ipv4_host->sin_addr));
322 319
323 DVLOG(1) << "Resolved Host is : " << NetAddressToString(ai); 320 DVLOG(1) << "Resolved Host is : " << ipe.ToStringWithoutPort();
324 321
325 std::string handshake_data(reinterpret_cast<char*>(&request), 322 std::string handshake_data(reinterpret_cast<char*>(&request),
326 sizeof(request)); 323 sizeof(request));
327 handshake_data.append(kEmptyUserId, arraysize(kEmptyUserId)); 324 handshake_data.append(kEmptyUserId, arraysize(kEmptyUserId));
328 325
329 return handshake_data; 326 return handshake_data;
330 } 327 }
331 328
332 // Writes the SOCKS handshake data to the underlying socket connection. 329 // Writes the SOCKS handshake data to the underlying socket connection.
333 int SOCKSClientSocket::DoHandshakeWrite() { 330 int SOCKSClientSocket::DoHandshakeWrite() {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 432
436 int SOCKSClientSocket::GetPeerAddress(AddressList* address) const { 433 int SOCKSClientSocket::GetPeerAddress(AddressList* address) const {
437 return transport_->socket()->GetPeerAddress(address); 434 return transport_->socket()->GetPeerAddress(address);
438 } 435 }
439 436
440 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { 437 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const {
441 return transport_->socket()->GetLocalAddress(address); 438 return transport_->socket()->GetLocalAddress(address);
442 } 439 }
443 440
444 } // namespace net 441 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698