SOCKS5 connect via hostname

pull/2/merge
Pieter Wuille 13 years ago
parent 60a87bce87
commit 933f2715d8

@ -219,32 +219,15 @@ bool static Socks5(const CService &addrDest, SOCKET& hSocket)
closesocket(hSocket); closesocket(hSocket);
return error("Proxy failed to initialize"); return error("Proxy failed to initialize");
} }
char pszSocks5IPv4[] = "\5\1\0\1\0\0\0\0\0\0"; string strSocks5("\5\1");
char pszSocks5IPv6[] = "\5\1\0\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; strSocks5 += '\000'; strSocks5 += '\003';
if (addrDest.IsIPv4()) string strDest = addrDest.ToStringIP();
{ strSocks5 += static_cast<char>(std::min((int)strDest.size(), 255));
struct sockaddr_in addr; strSocks5 += strDest;
addrDest.GetSockAddr(&addr); strSocks5 += static_cast<char>((addrDest.GetPort() >> 8) & 0xFF);
memcpy(pszSocks5IPv4 + 4, &addr.sin_addr, 4); strSocks5 += static_cast<char>((addrDest.GetPort() >> 0) & 0xFF);
memcpy(pszSocks5IPv4 + 8, &addr.sin_port, 2); ret = send(hSocket, strSocks5.c_str(), strSocks5.size(), MSG_NOSIGNAL);
pszSocks5 = pszSocks5IPv4; if (ret != strSocks5.size())
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)
{ {
closesocket(hSocket); closesocket(hSocket);
return error("Error sending to proxy"); return error("Error sending to proxy");

Loading…
Cancel
Save