diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-04-19 16:13:30 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-05-04 16:11:54 +0200 |
commit | 933f2715d8ff9548cdf90cd3cdec3bda79b898c2 (patch) | |
tree | f52e3f91176e743a40f28117dbf4b5bc15b359c1 /src/netbase.cpp | |
parent | 60a87bce873ce1f76a80b7b8546e83a0cd4e07a5 (diff) |
SOCKS5 connect via hostname
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r-- | src/netbase.cpp | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp index 3c818f76f5..2c131947bb 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -219,32 +219,15 @@ bool static Socks5(const CService &addrDest, SOCKET& hSocket) closesocket(hSocket); return error("Proxy failed to initialize"); } - char pszSocks5IPv4[] = "\5\1\0\1\0\0\0\0\0\0"; - char pszSocks5IPv6[] = "\5\1\0\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - if (addrDest.IsIPv4()) - { - struct sockaddr_in addr; - addrDest.GetSockAddr(&addr); - memcpy(pszSocks5IPv4 + 4, &addr.sin_addr, 4); - memcpy(pszSocks5IPv4 + 8, &addr.sin_port, 2); - pszSocks5 = pszSocks5IPv4; - nSize = sizeof(pszSocks5IPv4); - } - else - { -#ifdef USE_IPV6 - struct sockaddr_in6 addr; - addrDest.GetSockAddr6(&addr); - memcpy(pszSocks5IPv6 + 4, &addr.sin6_addr, 16); - memcpy(pszSocks5IPv6 + 20, &addr.sin6_port, 2); - pszSocks5 = pszSocks5IPv6; - nSize = sizeof(pszSocks5IPv6); -#else - return error("IPv6 support is not compiled in"); -#endif - } - ret = send(hSocket, pszSocks5, nSize, MSG_NOSIGNAL); - if (ret != nSize) + string strSocks5("\5\1"); + strSocks5 += '\000'; strSocks5 += '\003'; + string strDest = addrDest.ToStringIP(); + strSocks5 += static_cast<char>(std::min((int)strDest.size(), 255)); + strSocks5 += strDest; + strSocks5 += static_cast<char>((addrDest.GetPort() >> 8) & 0xFF); + strSocks5 += static_cast<char>((addrDest.GetPort() >> 0) & 0xFF); + ret = send(hSocket, strSocks5.c_str(), strSocks5.size(), MSG_NOSIGNAL); + if (ret != strSocks5.size()) { closesocket(hSocket); return error("Error sending to proxy"); |