Skip to content

Commit bf9266e

Browse files
committed
Use Socks5ErrorString() to decode error responses from socks proxy.
1 parent 94fd1d8 commit bf9266e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/netbase.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ struct ProxyCredentials
291291
std::string password;
292292
};
293293

294+
std::string Socks5ErrorString(int err)
295+
{
296+
switch(err) {
297+
case 0x01: return "general failure";
298+
case 0x02: return "connection not allowed";
299+
case 0x03: return "network unreachable";
300+
case 0x04: return "host unreachable";
301+
case 0x05: return "connection refused";
302+
case 0x06: return "TTL expired";
303+
case 0x07: return "protocol error";
304+
case 0x08: return "address type not supported";
305+
default: return "unknown";
306+
}
307+
}
308+
294309
/** Connect using SOCKS5 (as described in RFC1928) */
295310
static bool Socks5(const std::string& strDest, int port, const ProxyCredentials *auth, SOCKET& hSocket)
296311
{
@@ -382,18 +397,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
382397
if (pchRet2[1] != 0x00) {
383398
// Failures to connect to a peer that are not proxy errors
384399
CloseSocket(hSocket);
385-
switch (pchRet2[1])
386-
{
387-
case 0x01: LogPrintf("Socks5() connect to %s:%d failed: general failure\n", strDest, port); break;
388-
case 0x02: LogPrintf("Socks5() connect to %s:%d failed: connection not allowed\n", strDest, port); break;
389-
case 0x03: LogPrintf("Socks5() connect to %s:%d failed: network unreachable\n", strDest, port); break;
390-
case 0x04: LogPrintf("Socks5() connect to %s:%d failed: host unreachable\n", strDest, port); break;
391-
case 0x05: LogPrintf("Socks5() connect to %s:%d failed: connection refused\n", strDest, port); break;
392-
case 0x06: LogPrintf("Socks5() connect to %s:%d failed: TTL expired\n", strDest, port); break;
393-
case 0x07: LogPrintf("Socks5() connect to %s:%d failed: protocol error\n", strDest, port); break;
394-
case 0x08: LogPrintf("Socks5() connect to %s:%d failed: address type not supported\n", strDest, port); break;
395-
default: LogPrintf("Socks5() connect to %s:%d failed: unknown\n", strDest, port);
396-
}
400+
LogPrintf("Socks5() connect to %s:%d failed: %s\n", strDest, port, Socks5ErrorString(pchRet2[1]));
397401
return false;
398402
}
399403
if (pchRet2[2] != 0x00) {

0 commit comments

Comments
 (0)