blob: fab092069e11af91a40bd99336c7f758722cf3f1 [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"
[email protected]9eb7b11b2012-03-28 20:19:3111#include "base/sys_byteorder.h"
[email protected]3cd17242009-06-23 02:59:0212#include "net/base/io_buffer.h"
[email protected]3cd17242009-06-23 02:59:0213#include "net/base/net_util.h"
eroman87c53d62015-04-02 06:51:0714#include "net/log/net_log.h"
[email protected]a796bcec2010-03-22 17:17:2615#include "net/socket/client_socket_handle.h"
[email protected]3cd17242009-06-23 02:59:0216
17namespace net {
18
19// Every SOCKS server requests a user-id from the client. It is optional
20// and we send an empty string.
21static const char kEmptyUserId[] = "";
22
[email protected]3cd17242009-06-23 02:59:0223// For SOCKS4, the client sends 8 bytes plus the size of the user-id.
[email protected]76a51ac82009-06-28 07:58:5824static const unsigned int kWriteHeaderSize = 8;
[email protected]3cd17242009-06-23 02:59:0225
[email protected]034d3892011-03-29 04:07:2126// For SOCKS4 the server sends 8 bytes for acknowledgement.
[email protected]76a51ac82009-06-28 07:58:5827static const unsigned int kReadHeaderSize = 8;
[email protected]3cd17242009-06-23 02:59:0228
29// Server Response codes for SOCKS.
30static const uint8 kServerResponseOk = 0x5A;
31static const uint8 kServerResponseRejected = 0x5B;
32static const uint8 kServerResponseNotReachable = 0x5C;
33static const uint8 kServerResponseMismatchedUserId = 0x5D;
34
35static const uint8 kSOCKSVersion4 = 0x04;
36static const uint8 kSOCKSStreamRequest = 0x01;
37
[email protected]034d3892011-03-29 04:07:2138// A struct holding the essential details of the SOCKS4 Server Request.
[email protected]3cd17242009-06-23 02:59:0239// The port in the header is stored in network byte order.
40struct SOCKS4ServerRequest {
41 uint8 version;
42 uint8 command;
43 uint16 nw_port;
44 uint8 ip[4];
45};
mostynb91e0da982015-01-20 19:17:2746static_assert(sizeof(SOCKS4ServerRequest) == kWriteHeaderSize,
47 "socks4 server request struct has incorrect size");
[email protected]3cd17242009-06-23 02:59:0248
[email protected]034d3892011-03-29 04:07:2149// A struct holding details of the SOCKS4 Server Response.
[email protected]3cd17242009-06-23 02:59:0250struct SOCKS4ServerResponse {
51 uint8 reserved_null;
52 uint8 code;
53 uint16 port;
54 uint8 ip[4];
55};
mostynb91e0da982015-01-20 19:17:2756static_assert(sizeof(SOCKS4ServerResponse) == kReadHeaderSize,
57 "socks4 server response struct has incorrect size");
[email protected]3cd17242009-06-23 02:59:0258
[email protected]18ccfdb2013-08-15 00:13:4459SOCKSClientSocket::SOCKSClientSocket(
60 scoped_ptr<ClientSocketHandle> transport_socket,
61 const HostResolver::RequestInfo& req_info,
[email protected]5109c1952013-08-20 18:44:1062 RequestPriority priority,
[email protected]18ccfdb2013-08-15 00:13:4463 HostResolver* host_resolver)
64 : transport_(transport_socket.Pass()),
[email protected]3cd17242009-06-23 02:59:0265 next_state_(STATE_NONE),
[email protected]3cd17242009-06-23 02:59:0266 completed_handshake_(false),
67 bytes_sent_(0),
68 bytes_received_(0),
[email protected]0dc88b32014-03-26 20:12:2869 was_ever_used_(false),
[email protected]76a51ac82009-06-28 07:58:5870 host_resolver_(host_resolver),
[email protected]a2006ece2010-04-23 16:44:0271 host_request_info_(req_info),
[email protected]5109c1952013-08-20 18:44:1072 priority_(priority),
73 net_log_(transport_->socket()->NetLog()) {}
[email protected]3cd17242009-06-23 02:59:0274
75SOCKSClientSocket::~SOCKSClientSocket() {
76 Disconnect();
77}
78
[email protected]83039bb2011-12-09 18:43:5579int SOCKSClientSocket::Connect(const CompletionCallback& callback) {
[email protected]3cd17242009-06-23 02:59:0280 DCHECK(transport_.get());
[email protected]a796bcec2010-03-22 17:17:2681 DCHECK(transport_->socket());
[email protected]3cd17242009-06-23 02:59:0282 DCHECK_EQ(STATE_NONE, next_state_);
[email protected]83039bb2011-12-09 18:43:5583 DCHECK(user_callback_.is_null());
[email protected]3cd17242009-06-23 02:59:0284
85 // If already connected, then just return OK.
86 if (completed_handshake_)
87 return OK;
88
89 next_state_ = STATE_RESOLVE_HOST;
[email protected]5a05c47a2009-11-02 23:25:1990
[email protected]3aa4af042012-06-14 21:02:3191 net_log_.BeginEvent(NetLog::TYPE_SOCKS_CONNECT);
[email protected]3cd17242009-06-23 02:59:0292
93 int rv = DoLoop(OK);
[email protected]5a05c47a2009-11-02 23:25:1994 if (rv == ERR_IO_PENDING) {
[email protected]83039bb2011-12-09 18:43:5595 user_callback_ = callback;
[email protected]5a05c47a2009-11-02 23:25:1996 } else {
[email protected]d7fd1782011-02-08 19:16:4397 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv);
[email protected]5a05c47a2009-11-02 23:25:1998 }
[email protected]3cd17242009-06-23 02:59:0299 return rv;
100}
101
102void SOCKSClientSocket::Disconnect() {
103 completed_handshake_ = false;
[email protected]16a02742010-01-07 22:50:10104 host_resolver_.Cancel();
[email protected]a796bcec2010-03-22 17:17:26105 transport_->socket()->Disconnect();
[email protected]16a02742010-01-07 22:50:10106
107 // Reset other states to make sure they aren't mistakenly used later.
108 // These are the states initialized by Connect().
109 next_state_ = STATE_NONE;
[email protected]dbf036f2011-12-06 23:33:24110 user_callback_.Reset();
[email protected]3cd17242009-06-23 02:59:02111}
112
113bool SOCKSClientSocket::IsConnected() const {
[email protected]a796bcec2010-03-22 17:17:26114 return completed_handshake_ && transport_->socket()->IsConnected();
[email protected]3cd17242009-06-23 02:59:02115}
116
117bool SOCKSClientSocket::IsConnectedAndIdle() const {
[email protected]a796bcec2010-03-22 17:17:26118 return completed_handshake_ && transport_->socket()->IsConnectedAndIdle();
[email protected]3cd17242009-06-23 02:59:02119}
120
[email protected]e4be2dd2010-12-14 00:44:39121const BoundNetLog& SOCKSClientSocket::NetLog() const {
122 return net_log_;
123}
124
[email protected]9b5614a2010-08-25 20:29:45125void SOCKSClientSocket::SetSubresourceSpeculation() {
126 if (transport_.get() && transport_->socket()) {
127 transport_->socket()->SetSubresourceSpeculation();
128 } else {
129 NOTREACHED();
130 }
131}
132
133void SOCKSClientSocket::SetOmniboxSpeculation() {
134 if (transport_.get() && transport_->socket()) {
135 transport_->socket()->SetOmniboxSpeculation();
136 } else {
137 NOTREACHED();
138 }
139}
140
[email protected]0f873e82010-09-02 16:09:01141bool SOCKSClientSocket::WasEverUsed() const {
[email protected]0dc88b32014-03-26 20:12:28142 return was_ever_used_;
[email protected]0f873e82010-09-02 16:09:01143}
144
[email protected]7f7e92392010-10-26 18:29:29145bool SOCKSClientSocket::UsingTCPFastOpen() const {
146 if (transport_.get() && transport_->socket()) {
147 return transport_->socket()->UsingTCPFastOpen();
148 }
149 NOTREACHED();
150 return false;
151}
152
[email protected]2d88e7d2012-07-19 17:55:17153bool SOCKSClientSocket::WasNpnNegotiated() const {
154 if (transport_.get() && transport_->socket()) {
155 return transport_->socket()->WasNpnNegotiated();
156 }
157 NOTREACHED();
158 return false;
159}
160
[email protected]33661e482012-04-03 16:16:26161NextProto SOCKSClientSocket::GetNegotiatedProtocol() const {
162 if (transport_.get() && transport_->socket()) {
163 return transport_->socket()->GetNegotiatedProtocol();
164 }
165 NOTREACHED();
166 return kProtoUnknown;
167}
168
[email protected]2d88e7d2012-07-19 17:55:17169bool SOCKSClientSocket::GetSSLInfo(SSLInfo* ssl_info) {
170 if (transport_.get() && transport_->socket()) {
171 return transport_->socket()->GetSSLInfo(ssl_info);
172 }
173 NOTREACHED();
174 return false;
ttuttle23fdb7b2015-05-15 01:28:03175}
[email protected]2d88e7d2012-07-19 17:55:17176
ttuttle23fdb7b2015-05-15 01:28:03177void SOCKSClientSocket::GetConnectionAttempts(ConnectionAttempts* out) const {
178 out->clear();
[email protected]2d88e7d2012-07-19 17:55:17179}
180
tbansalf82cc8e2015-10-14 20:05:49181int64_t SOCKSClientSocket::GetTotalReceivedBytes() const {
182 return transport_->socket()->GetTotalReceivedBytes();
183}
184
[email protected]3cd17242009-06-23 02:59:02185// Read is called by the transport layer above to read. This can only be done
186// if the SOCKS handshake is complete.
187int SOCKSClientSocket::Read(IOBuffer* buf, int buf_len,
[email protected]3f55aa12011-12-07 02:03:33188 const CompletionCallback& callback) {
189 DCHECK(completed_handshake_);
190 DCHECK_EQ(STATE_NONE, next_state_);
[email protected]83039bb2011-12-09 18:43:55191 DCHECK(user_callback_.is_null());
[email protected]0dc88b32014-03-26 20:12:28192 DCHECK(!callback.is_null());
[email protected]3cd17242009-06-23 02:59:02193
[email protected]0dc88b32014-03-26 20:12:28194 int rv = transport_->socket()->Read(
195 buf, buf_len,
196 base::Bind(&SOCKSClientSocket::OnReadWriteComplete,
197 base::Unretained(this), callback));
198 if (rv > 0)
199 was_ever_used_ = true;
200 return rv;
[email protected]3cd17242009-06-23 02:59:02201}
202
203// Write is called by the transport layer. This can only be done if the
204// SOCKS handshake is complete.
205int SOCKSClientSocket::Write(IOBuffer* buf, int buf_len,
[email protected]83039bb2011-12-09 18:43:55206 const CompletionCallback& callback) {
[email protected]3cd17242009-06-23 02:59:02207 DCHECK(completed_handshake_);
208 DCHECK_EQ(STATE_NONE, next_state_);
[email protected]83039bb2011-12-09 18:43:55209 DCHECK(user_callback_.is_null());
[email protected]0dc88b32014-03-26 20:12:28210 DCHECK(!callback.is_null());
[email protected]3cd17242009-06-23 02:59:02211
[email protected]0dc88b32014-03-26 20:12:28212 int rv = transport_->socket()->Write(
213 buf, buf_len,
214 base::Bind(&SOCKSClientSocket::OnReadWriteComplete,
215 base::Unretained(this), callback));
216 if (rv > 0)
217 was_ever_used_ = true;
218 return rv;
[email protected]3cd17242009-06-23 02:59:02219}
220
[email protected]28b96d1c2014-04-09 12:21:15221int SOCKSClientSocket::SetReceiveBufferSize(int32 size) {
[email protected]a796bcec2010-03-22 17:17:26222 return transport_->socket()->SetReceiveBufferSize(size);
[email protected]d3f66572009-09-09 22:38:04223}
224
[email protected]28b96d1c2014-04-09 12:21:15225int SOCKSClientSocket::SetSendBufferSize(int32 size) {
[email protected]a796bcec2010-03-22 17:17:26226 return transport_->socket()->SetSendBufferSize(size);
[email protected]d3f66572009-09-09 22:38:04227}
228
[email protected]3cd17242009-06-23 02:59:02229void SOCKSClientSocket::DoCallback(int result) {
230 DCHECK_NE(ERR_IO_PENDING, result);
[email protected]83039bb2011-12-09 18:43:55231 DCHECK(!user_callback_.is_null());
[email protected]3cd17242009-06-23 02:59:02232
233 // Since Run() may result in Read being called,
234 // clear user_callback_ up front.
[email protected]83039bb2011-12-09 18:43:55235 DVLOG(1) << "Finished setting up SOCKS handshake";
[email protected]0dc88b32014-03-26 20:12:28236 base::ResetAndReturn(&user_callback_).Run(result);
[email protected]3cd17242009-06-23 02:59:02237}
238
239void SOCKSClientSocket::OnIOComplete(int result) {
[email protected]3cd17242009-06-23 02:59:02240 DCHECK_NE(STATE_NONE, next_state_);
241 int rv = DoLoop(result);
[email protected]5a05c47a2009-11-02 23:25:19242 if (rv != ERR_IO_PENDING) {
[email protected]d7fd1782011-02-08 19:16:43243 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKS_CONNECT, rv);
[email protected]3cd17242009-06-23 02:59:02244 DoCallback(rv);
[email protected]5a05c47a2009-11-02 23:25:19245 }
[email protected]3cd17242009-06-23 02:59:02246}
247
[email protected]0dc88b32014-03-26 20:12:28248void SOCKSClientSocket::OnReadWriteComplete(const CompletionCallback& callback,
249 int result) {
250 DCHECK_NE(ERR_IO_PENDING, result);
251 DCHECK(!callback.is_null());
252
253 if (result > 0)
254 was_ever_used_ = true;
255 callback.Run(result);
256}
257
[email protected]3cd17242009-06-23 02:59:02258int SOCKSClientSocket::DoLoop(int last_io_result) {
259 DCHECK_NE(next_state_, STATE_NONE);
260 int rv = last_io_result;
261 do {
262 State state = next_state_;
263 next_state_ = STATE_NONE;
264 switch (state) {
265 case STATE_RESOLVE_HOST:
266 DCHECK_EQ(OK, rv);
267 rv = DoResolveHost();
268 break;
269 case STATE_RESOLVE_HOST_COMPLETE:
270 rv = DoResolveHostComplete(rv);
271 break;
272 case STATE_HANDSHAKE_WRITE:
273 DCHECK_EQ(OK, rv);
274 rv = DoHandshakeWrite();
275 break;
276 case STATE_HANDSHAKE_WRITE_COMPLETE:
277 rv = DoHandshakeWriteComplete(rv);
278 break;
279 case STATE_HANDSHAKE_READ:
280 DCHECK_EQ(OK, rv);
281 rv = DoHandshakeRead();
282 break;
283 case STATE_HANDSHAKE_READ_COMPLETE:
284 rv = DoHandshakeReadComplete(rv);
285 break;
286 default:
287 NOTREACHED() << "bad state";
288 rv = ERR_UNEXPECTED;
289 break;
290 }
291 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
292 return rv;
293}
294
295int SOCKSClientSocket::DoResolveHost() {
[email protected]3cd17242009-06-23 02:59:02296 next_state_ = STATE_RESOLVE_HOST_COMPLETE;
[email protected]034d3892011-03-29 04:07:21297 // SOCKS4 only supports IPv4 addresses, so only try getting the IPv4
298 // addresses for the target host.
299 host_request_info_.set_address_family(ADDRESS_FAMILY_IPV4);
[email protected]ec08bb22009-08-12 00:25:12300 return host_resolver_.Resolve(
[email protected]5109c1952013-08-20 18:44:10301 host_request_info_,
302 priority_,
303 &addresses_,
[email protected]aa22b242011-11-16 18:58:29304 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)),
305 net_log_);
[email protected]3cd17242009-06-23 02:59:02306}
307
308int SOCKSClientSocket::DoResolveHostComplete(int result) {
[email protected]034d3892011-03-29 04:07:21309 if (result != OK) {
310 // Resolving the hostname failed; fail the request rather than automatically
311 // falling back to SOCKS4a (since it can be confusing to see invalid IP
312 // addresses being sent to the SOCKS4 server when it doesn't support 4A.)
313 return result;
[email protected]3cd17242009-06-23 02:59:02314 }
315
[email protected]034d3892011-03-29 04:07:21316 next_state_ = STATE_HANDSHAKE_WRITE;
[email protected]3cd17242009-06-23 02:59:02317 return OK;
318}
319
320// Builds the buffer that is to be sent to the server.
[email protected]76a51ac82009-06-28 07:58:58321const std::string SOCKSClientSocket::BuildHandshakeWriteBuffer() const {
[email protected]76a51ac82009-06-28 07:58:58322 SOCKS4ServerRequest request;
323 request.version = kSOCKSVersion4;
324 request.command = kSOCKSStreamRequest;
[email protected]9eb7b11b2012-03-28 20:19:31325 request.nw_port = base::HostToNet16(host_request_info_.port());
[email protected]3cd17242009-06-23 02:59:02326
[email protected]7054e78f2012-05-07 21:44:56327 DCHECK(!addresses_.empty());
328 const IPEndPoint& endpoint = addresses_.front();
[email protected]3cd17242009-06-23 02:59:02329
[email protected]034d3892011-03-29 04:07:21330 // We disabled IPv6 results when resolving the hostname, so none of the
331 // results in the list will be IPv6.
332 // TODO(eroman): we only ever use the first address in the list. It would be
333 // more robust to try all the IP addresses we have before
334 // failing the connect attempt.
[email protected]e466aaf2012-12-13 01:46:44335 CHECK_EQ(ADDRESS_FAMILY_IPV4, endpoint.GetFamily());
[email protected]7054e78f2012-05-07 21:44:56336 CHECK_LE(endpoint.address().size(), sizeof(request.ip));
337 memcpy(&request.ip, &endpoint.address()[0], endpoint.address().size());
[email protected]034d3892011-03-29 04:07:21338
[email protected]7054e78f2012-05-07 21:44:56339 DVLOG(1) << "Resolved Host is : " << endpoint.ToStringWithoutPort();
[email protected]3cd17242009-06-23 02:59:02340
[email protected]76a51ac82009-06-28 07:58:58341 std::string handshake_data(reinterpret_cast<char*>(&request),
342 sizeof(request));
343 handshake_data.append(kEmptyUserId, arraysize(kEmptyUserId));
[email protected]3cd17242009-06-23 02:59:02344
[email protected]76a51ac82009-06-28 07:58:58345 return handshake_data;
[email protected]3cd17242009-06-23 02:59:02346}
347
348// Writes the SOCKS handshake data to the underlying socket connection.
349int SOCKSClientSocket::DoHandshakeWrite() {
350 next_state_ = STATE_HANDSHAKE_WRITE_COMPLETE;
351
[email protected]76a51ac82009-06-28 07:58:58352 if (buffer_.empty()) {
353 buffer_ = BuildHandshakeWriteBuffer();
[email protected]3cd17242009-06-23 02:59:02354 bytes_sent_ = 0;
355 }
356
[email protected]76a51ac82009-06-28 07:58:58357 int handshake_buf_len = buffer_.size() - bytes_sent_;
358 DCHECK_GT(handshake_buf_len, 0);
359 handshake_buf_ = new IOBuffer(handshake_buf_len);
360 memcpy(handshake_buf_->data(), &buffer_[bytes_sent_],
361 handshake_buf_len);
[email protected]83039bb2011-12-09 18:43:55362 return transport_->socket()->Write(
[email protected]90499482013-06-01 00:39:50363 handshake_buf_.get(),
364 handshake_buf_len,
[email protected]83039bb2011-12-09 18:43:55365 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)));
[email protected]3cd17242009-06-23 02:59:02366}
367
368int SOCKSClientSocket::DoHandshakeWriteComplete(int result) {
[email protected]3cd17242009-06-23 02:59:02369 if (result < 0)
370 return result;
371
[email protected]76a51ac82009-06-28 07:58:58372 // We ignore the case when result is 0, since the underlying Write
373 // may return spurious writes while waiting on the socket.
374
[email protected]3cd17242009-06-23 02:59:02375 bytes_sent_ += result;
[email protected]76a51ac82009-06-28 07:58:58376 if (bytes_sent_ == buffer_.size()) {
[email protected]3cd17242009-06-23 02:59:02377 next_state_ = STATE_HANDSHAKE_READ;
[email protected]76a51ac82009-06-28 07:58:58378 buffer_.clear();
379 } else if (bytes_sent_ < buffer_.size()) {
[email protected]3cd17242009-06-23 02:59:02380 next_state_ = STATE_HANDSHAKE_WRITE;
381 } else {
382 return ERR_UNEXPECTED;
383 }
384
385 return OK;
386}
387
388int SOCKSClientSocket::DoHandshakeRead() {
[email protected]3cd17242009-06-23 02:59:02389 next_state_ = STATE_HANDSHAKE_READ_COMPLETE;
390
[email protected]76a51ac82009-06-28 07:58:58391 if (buffer_.empty()) {
[email protected]3cd17242009-06-23 02:59:02392 bytes_received_ = 0;
393 }
394
[email protected]76a51ac82009-06-28 07:58:58395 int handshake_buf_len = kReadHeaderSize - bytes_received_;
396 handshake_buf_ = new IOBuffer(handshake_buf_len);
[email protected]90499482013-06-01 00:39:50397 return transport_->socket()->Read(
398 handshake_buf_.get(),
399 handshake_buf_len,
400 base::Bind(&SOCKSClientSocket::OnIOComplete, base::Unretained(this)));
[email protected]3cd17242009-06-23 02:59:02401}
402
403int SOCKSClientSocket::DoHandshakeReadComplete(int result) {
[email protected]3cd17242009-06-23 02:59:02404 if (result < 0)
405 return result;
[email protected]76a51ac82009-06-28 07:58:58406
407 // The underlying socket closed unexpectedly.
408 if (result == 0)
409 return ERR_CONNECTION_CLOSED;
410
[email protected]d5a309592010-02-05 02:22:52411 if (bytes_received_ + result > kReadHeaderSize) {
[email protected]9e743cd2010-03-16 07:03:53412 // TODO(eroman): Describe failure in NetLog.
[email protected]d5a309592010-02-05 02:22:52413 return ERR_SOCKS_CONNECTION_FAILED;
414 }
[email protected]3cd17242009-06-23 02:59:02415
[email protected]76a51ac82009-06-28 07:58:58416 buffer_.append(handshake_buf_->data(), result);
[email protected]3cd17242009-06-23 02:59:02417 bytes_received_ += result;
[email protected]76a51ac82009-06-28 07:58:58418 if (bytes_received_ < kReadHeaderSize) {
[email protected]3cd17242009-06-23 02:59:02419 next_state_ = STATE_HANDSHAKE_READ;
420 return OK;
421 }
422
[email protected]76a51ac82009-06-28 07:58:58423 const SOCKS4ServerResponse* response =
424 reinterpret_cast<const SOCKS4ServerResponse*>(buffer_.data());
[email protected]3cd17242009-06-23 02:59:02425
426 if (response->reserved_null != 0x00) {
427 LOG(ERROR) << "Unknown response from SOCKS server.";
[email protected]d5a309592010-02-05 02:22:52428 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02429 }
430
[email protected]3cd17242009-06-23 02:59:02431 switch (response->code) {
432 case kServerResponseOk:
433 completed_handshake_ = true;
434 return OK;
435 case kServerResponseRejected:
436 LOG(ERROR) << "SOCKS request rejected or failed";
[email protected]d5a309592010-02-05 02:22:52437 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02438 case kServerResponseNotReachable:
439 LOG(ERROR) << "SOCKS request failed because client is not running "
440 << "identd (or not reachable from the server)";
[email protected]d5a309592010-02-05 02:22:52441 return ERR_SOCKS_CONNECTION_HOST_UNREACHABLE;
[email protected]3cd17242009-06-23 02:59:02442 case kServerResponseMismatchedUserId:
443 LOG(ERROR) << "SOCKS request failed because client's identd could "
444 << "not confirm the user ID string in the request";
[email protected]d5a309592010-02-05 02:22:52445 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02446 default:
447 LOG(ERROR) << "SOCKS server sent unknown response";
[email protected]d5a309592010-02-05 02:22:52448 return ERR_SOCKS_CONNECTION_FAILED;
[email protected]3cd17242009-06-23 02:59:02449 }
450
451 // Note: we ignore the last 6 bytes as specified by the SOCKS protocol
452}
453
[email protected]a3528692012-06-08 00:11:42454int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const {
[email protected]a796bcec2010-03-22 17:17:26455 return transport_->socket()->GetPeerAddress(address);
[email protected]3cd17242009-06-23 02:59:02456}
[email protected]3cd17242009-06-23 02:59:02457
[email protected]e7f74da2011-04-19 23:49:35458int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const {
459 return transport_->socket()->GetLocalAddress(address);
460}
461
[email protected]3cd17242009-06-23 02:59:02462} // namespace net