OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/socks5_client_socket.h" | 5 #include "net/socket/socks5_client_socket.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/sys_byteorder.h" |
12 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
13 #include "net/base/net_log.h" | 14 #include "net/base/net_log.h" |
14 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
15 #include "net/base/sys_addrinfo.h" | 16 #include "net/base/sys_addrinfo.h" |
16 #include "net/socket/client_socket_handle.h" | 17 #include "net/socket/client_socket_handle.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 const unsigned int SOCKS5ClientSocket::kGreetReadHeaderSize = 2; | 21 const unsigned int SOCKS5ClientSocket::kGreetReadHeaderSize = 2; |
21 const unsigned int SOCKS5ClientSocket::kWriteHeaderSize = 10; | 22 const unsigned int SOCKS5ClientSocket::kWriteHeaderSize = 10; |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 358 |
358 handshake->push_back(kEndPointDomain); // The type of the address. | 359 handshake->push_back(kEndPointDomain); // The type of the address. |
359 | 360 |
360 DCHECK_GE(static_cast<size_t>(0xFF), host_request_info_.hostname().size()); | 361 DCHECK_GE(static_cast<size_t>(0xFF), host_request_info_.hostname().size()); |
361 | 362 |
362 // First add the size of the hostname, followed by the hostname. | 363 // First add the size of the hostname, followed by the hostname. |
363 handshake->push_back(static_cast<unsigned char>( | 364 handshake->push_back(static_cast<unsigned char>( |
364 host_request_info_.hostname().size())); | 365 host_request_info_.hostname().size())); |
365 handshake->append(host_request_info_.hostname()); | 366 handshake->append(host_request_info_.hostname()); |
366 | 367 |
367 uint16 nw_port = htons(host_request_info_.port()); | 368 uint16 nw_port = base::HostToNet16(host_request_info_.port()); |
368 handshake->append(reinterpret_cast<char*>(&nw_port), sizeof(nw_port)); | 369 handshake->append(reinterpret_cast<char*>(&nw_port), sizeof(nw_port)); |
369 return OK; | 370 return OK; |
370 } | 371 } |
371 | 372 |
372 // Writes the SOCKS handshake data to the underlying socket connection. | 373 // Writes the SOCKS handshake data to the underlying socket connection. |
373 int SOCKS5ClientSocket::DoHandshakeWrite() { | 374 int SOCKS5ClientSocket::DoHandshakeWrite() { |
374 next_state_ = STATE_HANDSHAKE_WRITE_COMPLETE; | 375 next_state_ = STATE_HANDSHAKE_WRITE_COMPLETE; |
375 | 376 |
376 if (buffer_.empty()) { | 377 if (buffer_.empty()) { |
377 int rv = BuildHandshakeWriteBuffer(&buffer_); | 378 int rv = BuildHandshakeWriteBuffer(&buffer_); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 498 |
498 int SOCKS5ClientSocket::GetPeerAddress(AddressList* address) const { | 499 int SOCKS5ClientSocket::GetPeerAddress(AddressList* address) const { |
499 return transport_->socket()->GetPeerAddress(address); | 500 return transport_->socket()->GetPeerAddress(address); |
500 } | 501 } |
501 | 502 |
502 int SOCKS5ClientSocket::GetLocalAddress(IPEndPoint* address) const { | 503 int SOCKS5ClientSocket::GetLocalAddress(IPEndPoint* address) const { |
503 return transport_->socket()->GetLocalAddress(address); | 504 return transport_->socket()->GetLocalAddress(address); |
504 } | 505 } |
505 | 506 |
506 } // namespace net | 507 } // namespace net |
OLD | NEW |