blob: 75eb36a76d73d8a9b6968ea6b31810a2d6effd22 [file] [log] [blame]
[email protected]9eb7b11b2012-03-28 20:19:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]3cd17242009-06-23 02:59:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/socket/socks_client_socket.h"
6
7#include "base/basictypes.h"
[email protected]aa22b242011-11-16 18:58:298#include "base/bind.h"
[email protected]0dc88b32014-03-26 20:12:289#include "base/callback_helpers.h"
[email protected]3cd17242009-06-23 02:59:0210#include "base/compiler_specific.h"
vadimt0e2715e2014-12-08 20:51:2311#include "base/profiler/scoped_tracker.h"
[email protected]9eb7b11b2012-03-28 20:19:3112#include "base/sys_byteorder.h"
[email protected]3cd17242009-06-23 02:59:0213#include "net/base/io_buffer.h"
[email protected]9e743cd2010-03-16 07:03:5314#include "net/base/net_log.h"
[email protected]3cd17242009-06-23 02:59:0215#include "net/base/net_util.h"
[email protected]a796bcec2010-03-22 17:17:2616#include "net/socket/client_socket_handle.h"
[email protected]3cd17242009-06-23 02:59:0217
18namespace net {
19
20// Every SOCKS server requests a user-id from the client. It is optional
21// and we send an empty string.
22static const char kEmptyUserId[] = "";
23
[email protected]3cd17242009-06-23 02:59:0224// For SOCKS4, the client sends 8 bytes plus the size of the user-id.
[email protected]76a51ac82009-06-28 07:58:5825static const unsigned int kWriteHeaderSize = 8;
[email protected]3cd17242009-06-23 02:59:0226
[email protected]034d3892011-03-29 04:07:2127// For SOCKS4 the server sends 8 bytes for acknowledgement.
[email protected]76a51ac82009-06-28 07:58:5828static const unsigned int kReadHeaderSize = 8;
[email protected]3cd17242009-06-23 02:59:0229
30// Server Response codes for SOCKS.
31static const uint8 kServerResponseOk = 0x5A;
32static const uint8 kServerResponseRejected = 0x5B;
33static const uint8 kServerResponseNotReachable = 0x5C;
34static const uint8 kServerResponseMismatchedUserId = 0x5D;
35
36static const uint8 kSOCKSVersion4 = 0x04;
37static const uint8 kSOCKSStreamRequest = 0x01;
38
[email protected]034d3892011-03-29 04:07:2139// A struct holding the essential details of the SOCKS4 Server Request.
[email protected]3cd17242009-06-23 02:59:0240// The port in the header is stored in network byte order.
41struct SOCKS4ServerRequest {
42 uint8 version;
43 uint8 command;
44 uint16 nw_port;
45 uint8 ip[4];
46};
mostynb91e0da982015-01-20 19:17:2747static_assert(sizeof(SOCKS4ServerRequest) == kWriteHeaderSize,
48 "socks4 server request struct has incorrect size");
[email protected]3cd17242009-06-23 02:59:0249
[email protected]034d3892011-03-29 04:07:2150// A struct holding details of the SOCKS4 Server Response.
[email protected]3cd17242009-06-23 02:59:0251struct SOCKS4ServerResponse {
52 uint8 reserved_null;
53 uint8 code;
54 uint16 port;
55 uint8 ip[4];
56};
mostynb91e0da982015-01-20 19:17:2757static_assert(sizeof(SOCKS4ServerResponse) == kReadHeaderSize,
58 "socks4 server response struct has incorrect size");
[email protected]3cd17242009-06-23 02:59:0259
[email protected]18ccfdb2013-08-15 00:13:4460SOCKSClientSocket::SOCKSClientSocket(
61 scoped_ptr<ClientSocketHandle> transport_socket,
62 const HostResolver::RequestInfo& req_info,
[email protected]5109c1952013-08-20 18:44:1063 RequestPriority priority,
[email protected]18ccfdb2013-08-15 00:13:4464 HostResolver* host_resolver)
65 : transport_(transport_socket.Pass()),
[email protected]3cd17242009-06-23 02:59:0266 next_state_(STATE_NONE),
[email protected]3cd17242009-06-23 02:59:0267 completed_handshake_(false),
68 bytes_sent_(0),
69 bytes_received_(0),
[email protected]0dc88b32014-03-26 20:12:2870 was_ever_used_(false),
[email protected]76a51ac82009-06-28 07:58:5871 host_resolver_(host_resolver),
[email protected]a2006ece2010-04-23 16:44:0272 host_request_info_(req_info),
[email protected]5109c1952013-08-20 18:44:1073 priority_(priority),
74 net_log_(transport_->socket()->NetLog()) {}
[email protected]3cd17242009-06-23 02:59:0275
76SOCKSClientSocket::~SOCKSClientSocket() {
77 Disconnect();
78}
79
[email protected]83039bb2011-12-09 18:43:5580int SOCKSClientSocket::Connect(const CompletionCallback& callback) {
[email protected]3cd17242009-06-23 02:59:0281 DCHECK(transport_.get());
[email protected]a796bcec2010-03-22 17:17:2682 DCHECK(transport_->socket());
[email protected]3cd17242009-06-23 02:59:0283 DCHECK_EQ(STATE_NONE, next_state_);
[email protected]83039bb2011-12-09 18:43:5584 DCHECK(user_callback_.is_null());
[email protected]3cd17242009-06-23 02:59:0285
86 // If already connected, then just return OK.
87 if (completed_handshake_)
88 return OK;
89
90 next_state_ = STATE_RESOLVE_HOST;
[email protected]5a05c47a2009-11-02 23:25:1991
[email protected]3aa4af042012-06-14 21:02:3192 net_log_.BeginEvent(NetLog::TYPE_SOCKS_CONNECT);
[email protected]3cd17242009-06-23 02:59:0293
94 int rv = DoLoop(OK);
[email protected]5a05c47a2009-11-02 23:25:1995 if (rv == ERR_IO_PENDING) {
[email protected]83039bb2011-12-09 18:43:5596 user_callback_ = callback;
[email protected]5a05c47a2009-11-02 23:25:1997 } else {
[email protected]d7fd1782011-02-08 19:16:4398 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv);
[email protected]5a05c47a2009-11-02 23:25:1999 }
[email protected]3cd17242009-06-23 02:59:02100 return rv;
101}
102
103void SOCKSClientSocket::Disconnect() {
104 completed_handshake_ = false;
[email protected]16a02742010-01-07 22:50:10105 host_resolver_.Cancel();
[email protected]a796bcec2010-03-22 17:17:26106 transport_->socket()->Disconnect();
[email protected]16a02742010-01-07 22:50:10107
108 // Reset other states to make sure they aren't mistakenly used later.
109 // These are the states initialized by Connect().
110 next_state_ = STATE_NONE;
[email protected]dbf036f2011-12-06 23:33:24111 user_callback_.Reset();
[email protected]3cd17242009-06-23 02:59:02112}
113
114bool SOCKSClientSocket::IsConnected() const {
[email protected]a796bcec2010-03-22 17:17:26115 return completed_handshake_ && transport_->socket()->IsConnected();
[email protected]3cd17242009-06-23 02:59:02116}
117
118bool SOCKSClientSocket::IsConnectedAndIdle() const {
[email protected]a796bcec2010-03-22 17:17:26119 return completed_handshake_ && transport_->socket()->IsConnectedAndIdle();
[email protected]3cd17242009-06-23 02:59:02120}
121
[email protected]e4be2dd2010-12-14 00:44:39122const BoundNetLog& SOCKSClientSocket::NetLog() const {
123 return net_log_;
124}
125
[email protected]9b5614a2010-08-25 20:29:45126void SOCKSClientSocket::SetSubresourceSpeculation() {
127 if (transport_.get() && transport_->socket()) {
128 transport_->socket()->SetSubresourceSpeculation();
129 } else {
130 NOTREACHED();
131 }
132}
133
134void SOCKSClientSocket::SetOmniboxSpeculation() {
135 if (transport_.get() && transport_->socket()) {
136 transport_->socket()->SetOmniboxSpeculation();
137 } else {
138 NOTREACHED();
139 }
140}
141
[email protected]0f873e82010-09-02 16:09:01142bool SOCKSClientSocket::WasEverUsed() const {
[email protected]0dc88b32014-03-26 20:12:28143 return was_ever_used_;
[email protected]0f873e82010-09-02 16:09:01144}
145
[email protected]7f7e92392010-10-26 18:29:29146bool SOCKSClientSocket::UsingTCPFastOpen() const {
147 if (transport_.get() && transport_->socket()) {
148 return transport_->socket()->UsingTCPFastOpen();
149 }
150 NOTREACHED();
151 return false;
152}
153
[email protected]2d88e7d2012-07-19 17:55:17154bool SOCKSClientSocket::WasNpnNegotiated() const {
155 if (transport_.get() && transport_->socket()) {
156 return transport_->socket()->WasNpnNegotiated();
157 }
158 NOTREACHED();
159 return false;
160}
161
[email protected]33661e482012-04-03 16:16:26162NextProto SOCKSClientSocket::GetNegotiatedProtocol() const {
163 if (transport_.get() && transport_->socket()) {
164 return transport_->socket()->GetNegotiatedProtocol();
165 }
166 NOTREACHED();
167 return kProtoUnknown;
168}
169
[email protected]2d88e7d2012-07-19 17:55:17170bool SOCKSClientSocket::GetSSLInfo(SSLInfo* ssl_info) {
171 if (transport_.get() && transport_->socket()) {
172 return transport_->socket()->GetSSLInfo(ssl_info);
173 }
174 NOTREACHED();
175 return false;
176
177}
178
[email protected]3cd17242009-06-23 02:59:02179// Read is called by the transport layer above to read. This can only be done
180// if the SOCKS handshake is complete.
181int SOCKSClientSocket::Read(IOBuffer* buf, int buf_len,
[email protected]3f55aa12011-12-07 02:03:33182 const CompletionCallback& callback) {
183 DCHECK(completed_handshake_);
184 DCHECK_EQ(STATE_NONE, next_state_);
[email protected]83039bb2011-12-09 18:43:55185 DCHECK(user_callback_.is_null());
[email protected]0dc88b32014-03-26 20:12:28186 DCHECK(!callback.is_null());
[email protected]3cd17242009-06-23 02:59:02187
[email protected]0dc88b32014-03-26 20:12:28188 int rv = transport_->socket()->Read(
189 buf, buf_len,
190 base::Bind(&SOCKSClientSocket::OnReadWriteComplete,
191 base::Unretained(this), callback));
192 if (rv > 0)
193 was_ever_used_ = true;
194 return rv;
[email protected]3cd17242009-06-23 02:59:02195}
196
197// Write is called by the transport layer. This can only be done if the
198// SOCKS handshake is complete.
199int SOCKSClientSocket::Write(IOBuffer* buf, int buf_len,
[email protected]83039bb2011-12-09 18:43:55200 const CompletionCallback& callback) {
[email protected]3cd17242009-06-23 02:59:02201 DCHECK(completed_handshake_);
202 DCHECK_EQ(STATE_NONE, next_state_);
[email protected]83039bb2011-12-09 18:43:55203 DCHECK(user_callback_.is_null());
[email protected]0dc88b32014-03-26 20:12:28204 DCHECK(!callback.is_null());
[email protected]3cd17242009-06-23 02:59:02205
[email protected]0dc88b32014-03-26 20:12:28206 int rv = transport_->socket()->Write(
207 buf, buf_len,
208 base::Bind(&SOCKSClientSocket::OnReadWriteComplete,
209 base::Unretained(this), callback));
210 if (rv > 0)
211 was_ever_used_ = true;
212 return rv;
[email protected]3cd17242009-06-23 02:59:02213}
214
[email protected]28b96d1c2014-04-09 12:21:15215int SOCKSClientSocket::SetReceiveBufferSize(int32 size) {
[email protected]a796bcec2010-03-22 17:17:26216 return transport_->socket()->SetReceiveBufferSize(size);
[email protected]d3f66572009-09-09 22:38:04217}
218
[email protected]28b96d1c2014-04-09 12:21:15219int SOCKSClientSocket::SetSendBufferSize(int32 size) {
[email protected]a796bcec2010-03-22 17:17:26220 return transport_->socket()->SetSendBufferSize(size);
[email protected]d3f66572009-09-09 22:38:04221}
222
[email protected]3cd17242009-06-23 02:59:02223void SOCKSClientSocket::DoCallback(int result) {
224 DCHECK_NE(ERR_IO_PENDING, result);
[email protected]83039bb2011-12-09 18:43:55225 DCHECK(!user_callback_.is_null());
[email protected]3cd17242009-06-23 02:59:02226
227 // Since Run() may result in Read being called,
228 // clear user_callback_ up front.
[email protected]83039bb2011-12-09 18:43:55229 DVLOG(1) << "Finished setting up SOCKS handshake";
[email protected]0dc88b32014-03-26 20:12:28230 base::ResetAndReturn(&user_callback_).Run(result);
[email protected]3cd17242009-06-23 02:59:02231}
232
233void SOCKSClientSocket::OnIOComplete(int result) {
vadimt0e2715e2014-12-08 20:51:23234 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed.
235 tracked_objects::ScopedTracker tracking_profile(
236 FROM_HERE_WITH_EXPLICIT_FUNCTION(
237 "436634 SOCKSClientSocket::OnIOComplete"));
238
[email protected]3cd17242009-06-23 02:59:02239 DCHECK_NE(STATE_NONE, next_state_);
240 int rv = DoLoop(result);
[email protected]5a05c47a2009-11-02 23:25:19241 if (rv != ERR_IO_PENDING) {
[email protected]d7fd1782011-02-08 19:16:43242 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv);
[email protected]3cd17242009-06-23 02:59:02243 DoCallback(rv);
[email protected]5a05c47a2009-11-02 23:25:19244 }
[email protected]3cd17242009-06-23 02:59:02245}
246
[email protected]0dc88b32014-03-26 20:12:28247void SOCKSClientSocket::OnReadWriteComplete(const CompletionCallback& callback,
248 int result) {
249 DCHECK_NE(ERR_IO_PENDING, result);
250 DCHECK(!callback.is_null());
251
252 if (result > 0)
253 was_ever_used_ = true;
254 callback.Run(result);
255}
256
[email protected]3cd17242009-06-23 02:59:02257int SOCKSClientSocket::DoLoop(int last_io_result) {
258 DCHECK_NE(next_state_, STATE_NONE);
259 int rv = last_io_result;
260 do {
261 State state = next_state_;
262 next_state_ = STATE_NONE;
263 switch (state) {
264 case STATE_RESOLVE_HOST:
265 DCHECK_EQ(OK, rv);
266 rv = DoResolveHost();
267 break;
268 case STATE_RESOLVE_HOST_COMPLETE:
269 rv = DoResolveHostComplete(rv);
270 break;
271 case STATE_HANDSHAKE_WRITE:
272 DCHECK_EQ(OK, rv);
273 rv = DoHandshakeWrite();
274 break;
275 case STATE_HANDSHAKE_WRITE_COMPLETE:
276 rv = DoHandshakeWriteComplete(rv);
277 break;
278 case STATE_HANDSHAKE_READ:
279 DCHECK_EQ(OK, rv);
280 rv = DoHandshakeRead();
281 break;
282 case STATE_HANDSHAKE_READ_COMPLETE:
283 rv = DoHandshakeReadComplete(rv);
284 break;
285 default:
286 NOTREACHED() << "bad state";
287 rv = ERR_UNEXPECTED;
288 break;
289 }
290 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
291 return rv;
292}
293
294int SOCKSClientSocket::DoResolveHost() {
[email protected]3cd17242009-06-23 02:59:02295 next_state_ = STATE_RESOLVE_HOST_COMPLETE;
[email protected]034d3892011-03-29 04:07:21296 // SOCKS4 only supports IPv4 addresses, so only try getting the IPv4
297 // addresses for the target host.
298 host_request_info_.set_address_family(ADDRESS_FAMILY_IPV4);
[email protected]ec08bb22009-08-12 00:25:12299 return host_resolver_.Resolve(
[email protected]5109c1952013-08-20 18:44:10300 host_request_info_,
301 priority_,
302 &addresses_,
[email protected]aa22b242011-11-16 18:58:29303 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)),
304 net_log_);
[email protected]3cd17242009-06-23 02:59:02305}
306
307int SOCKSClientSocket::DoResolveHostComplete(int result) {
[email protected]034d3892011-03-29 04:07:21308 if (result != OK) {
309 // Resolving the hostname failed; fail the request rather than automatically
310 // falling back to SOCKS4a (since it can be confusing to see invalid IP
311 // addresses being sent to the SOCKS4 server when it doesn't support 4A.)
312 return result;
[email protected]3cd17242009-06-23 02:59:02313 }
314
[email protected]034d3892011-03-29 04:07:21315 next_state_ = STATE_HANDSHAKE_WRITE;
[email protected]3cd17242009-06-23 02:59:02316 return OK;
317}
318
319// Builds the buffer that is to be sent to the server.
[email protected]76a51ac82009-06-28 07:58:58320const std::string SOCKSClientSocket::BuildHandshakeWriteBuffer() const {
[email protected]76a51ac82009-06-28 07:58:58321 SOCKS4ServerRequest request;
322 request.version = kSOCKSVersion4;
323 request.command = kSOCKSStreamRequest;
[email protected]9eb7b11b2012-03-28 20:19:31324 request.nw_port = base::HostToNet16(host_request_info_.port());
[email protected]3cd17242009-06-23 02:59:02325
[email protected]7054e78f2012-05-07 21:44:56326 DCHECK(!addresses_.empty());
327 const IPEndPoint& endpoint = addresses_.front();
[email protected]3cd17242009-06-23 02:59:02328
[email protected]034d3892011-03-29 04:07:21329 // We disabled IPv6 results when resolving the hostname, so none of the
330 // results in the list will be IPv6.
331 // TODO(eroman): we only ever use the first address in the list. It would be
332 // more robust to try all the IP addresses we have before
333 // failing the connect attempt.
[email protected]e466aaf2012-12-13 01:46:44334 CHECK_EQ(ADDRESS_FAMILY_IPV4, endpoint.GetFamily());
[email protected]7054e78f2012-05-07 21:44:56335 CHECK_LE(endpoint.address().size(), sizeof(request.ip));
336 memcpy(&request.ip, &endpoint.address()[0], endpoint.address().size());
[email protected]034d3892011-03-29 04:07:21337
[email protected]7054e78f2012-05-07 21:44:56338 DVLOG(1) << "Resolved Host is : " << endpoint.ToStringWithoutPort();
[email protected]3cd17242009-06-23 02:59:02339
[email protected]76a51ac82009-06-28 07:58:58340 std::string handshake_data(reinterpret_cast<char*>(&request),
341 sizeof(request));
342 handshake_data.append(kEmptyUserId, arraysize(kEmptyUserId));
[email protected]3cd17242009-06-23 02:59:02343
[email protected]76a51ac82009-06-28 07:58:58344 return handshake_data;
[email protected]3cd17242009-06-23 02:59:02345}
346
347// Writes the SOCKS handshake data to the underlying socket connection.
348int SOCKSClientSocket::DoHandshakeWrite() {
349 next_state_ = STATE_HANDSHAKE_WRITE_COMPLETE;
350
[email protected]76a51ac82009-06-28 07:58:58351 if (buffer_.empty()) {
352 buffer_ = BuildHandshakeWriteBuffer();
[email protected]3cd17242009-06-23 02:59:02353 bytes_sent_ = 0;
354 }
355
[email protected]76a51ac82009-06-28 07:58:58356 int handshake_buf_len = buffer_.size() - bytes_sent_;
357 DCHECK_GT(handshake_buf_len, 0);
358 handshake_buf_ = new IOBuffer(handshake_buf_len);
359 memcpy(handshake_buf_->data(), &buffer_[bytes_sent_],
360 handshake_buf_len);
[email protected]83039bb2011-12-09 18:43:55361 return transport_->socket()->Write(
[email protected]90499482013-06-01 00:39:50362 handshake_buf_.get(),
363 handshake_buf_len,
[email protected]83039bb2011-12-09 18:43:55364 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)));
[email protected]3cd17242009-06-23 02:59:02365}
366
367int SOCKSClientSocket::DoHandshakeWriteComplete(int result) {
[email protected]3cd17242009-06-23 02:59:02368 if (result < 0)
369 return result;
370
[email protected]76a51ac82009-06-28 07:58:58371 // We ignore the case when result is 0, since the underlying Write
372 // may return spurious writes while waiting on the socket.
373
[email protected]3cd17242009-06-23 02:59:02374 bytes_sent_ += result;
[email protected]76a51ac82009-06-28 07:58:58375 if (bytes_sent_ == buffer_.size()) {
[email protected]3cd17242009-06-23 02:59:02376 next_state_ = STATE_HANDSHAKE_READ;
[email protected]76a51ac82009-06-28 07:58:58377 buffer_.clear();
378 } else if (bytes_sent_ < buffer_.size()) {
[email protected]3cd17242009-06-23 02:59:02379 next_state_ = STATE_HANDSHAKE_WRITE;
380 } else {
381 return ERR_UNEXPECTED;
382 }
383
384 return OK;
385}
386
387int SOCKSClientSocket::DoHandshakeRead() {
[email protected]3cd17242009-06-23 02:59:02388 next_state_ = STATE_HANDSHAKE_READ_COMPLETE;
389
[email protected]76a51ac82009-06-28 07:58:58390 if (buffer_.empty()) {
[email protected]3cd17242009-06-23 02:59:02391 bytes_received_ = 0;
392 }
393
[email protected]76a51ac82009-06-28 07:58:58394 int handshake_buf_len = kReadHeaderSize - bytes_received_;
395 handshake_buf_ = new IOBuffer(handshake_buf_len);
[email protected]90499482013-06-01 00:39:50396 return transport_->socket()->Read(
397 handshake_buf_.get(),
398 handshake_buf_len,
399 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)));
[email protected]3cd17242009-06-23 02:59:02400}
401
402int SOCKSClientSocket::DoHandshakeReadComplete(int result) {
[email protected]3cd17242009-06-23 02:59:02403 if (result < 0)
404 return result;
[email protected]76a51ac82009-06-28 07:58:58405
406 // The underlying socket closed unexpectedly.
407 if (result == 0)
408 return ERR_CONNECTION_CLOSED;
409
[email protected]d5a309592010-02-05 02:22:52410 if (bytes_received_ + result > kReadHeaderSize) {
[email protected]9e743cd2010-03-16 07:03:53411 // TODO(eroman): Describe failure in NetLog.
[email protected]d5a309592010-02-05 02:22:52412 return ERR_SOCKS_CONNECTION_FAILED;
413 }
[email protected]3cd17242009-06-23 02:59:02414
[email protected]76a51ac82009-06-28 07:58:58415 buffer_.append(handshake_buf_->data(), result);
[email protected]3cd17242009-06-23 02:59:02416 bytes_received_ += result;
[email protected]76a51ac82009-06-28 07:58:58417 if (bytes_received_ < kReadHeaderSize) {
[email protected]3cd17242009-06-23 02:59:02418 next_state_ = STATE_HANDSHAKE_READ;
419 return OK;
420 }
421
[email protected]76a51ac82009-06-28 07:58:58422 const SOCKS4ServerResponse* response =
423 reinterpret_cast<const SOCKS4ServerResponse*>(buffer_.data());
[email protected]3cd17242009-06-23 02:59:02424
425 if (response->reserved_null != 0x00) {
426 LOG(ERROR) << "Unknown response from SOCKS server.";
[email protected]d5a309592010-02-05 02:22:52427 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02428 }
429
[email protected]3cd17242009-06-23 02:59:02430 switch (response->code) {
431 case kServerResponseOk:
432 completed_handshake_ = true;
433 return OK;
434 case kServerResponseRejected:
435 LOG(ERROR) << "SOCKS request rejected or failed";
[email protected]d5a309592010-02-05 02:22:52436 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02437 case kServerResponseNotReachable:
438 LOG(ERROR) << "SOCKS request failed because client is not running "
439 << "identd (or not reachable from the server)";
[email protected]d5a309592010-02-05 02:22:52440 return ERR_SOCKS_CONNECTION_HOST_UNREACHABLE;
[email protected]3cd17242009-06-23 02:59:02441 case kServerResponseMismatchedUserId:
442 LOG(ERROR) << "SOCKS request failed because client's identd could "
443 << "not confirm the user ID string in the request";
[email protected]d5a309592010-02-05 02:22:52444 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02445 default:
446 LOG(ERROR) << "SOCKS server sent unknown response";
[email protected]d5a309592010-02-05 02:22:52447 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02448 }
449
450 // Note: we ignore the last 6 bytes as specified by the SOCKS protocol
451}
452
[email protected]a3528692012-06-08 00:11:42453int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const {
[email protected]a796bcec2010-03-22 17:17:26454 return transport_->socket()->GetPeerAddress(address);
[email protected]3cd17242009-06-23 02:59:02455}
[email protected]3cd17242009-06-23 02:59:02456
[email protected]e7f74da2011-04-19 23:49:35457int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const {
458 return transport_->socket()->GetLocalAddress(address);
459}
460
[email protected]3cd17242009-06-23 02:59:02461} // namespace net