From 2e07e696976dafcfc6d93be737b6432b466bdceb Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 18 Feb 2020 19:24:49 +0700 Subject: [PATCH] Added IPv4 and IPv6 support for SOCKS5. --- src/base/net/stratum/Socks5.cpp | 21 +++++++++++++-------- src/base/net/stratum/Socks5.h | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/base/net/stratum/Socks5.cpp b/src/base/net/stratum/Socks5.cpp index 94fce6f36..f27ee0d04 100644 --- a/src/base/net/stratum/Socks5.cpp +++ b/src/base/net/stratum/Socks5.cpp @@ -59,15 +59,15 @@ void xmrig::Client::Socks5::handshake() } -bool xmrig::Client::Socks5::isIPv4(const String &) const +bool xmrig::Client::Socks5::isIPv4(const String &host, sockaddr_storage *addr) const { - return false; + return uv_ip4_addr(host.data(), 0, reinterpret_cast(addr)) == 0; } -bool xmrig::Client::Socks5::isIPv6(const String &) const +bool xmrig::Client::Socks5::isIPv6(const String &host, sockaddr_storage *addr) const { - return false; + return uv_ip6_addr(host.data(), 0, reinterpret_cast(addr)) == 0; } @@ -78,12 +78,17 @@ void xmrig::Client::Socks5::connect() const auto &host = m_client->pool().host(); std::vector buf; + sockaddr_storage addr; - if (isIPv4(host)) { - + if (isIPv4(host, &addr)) { + buf.resize(10); + buf[3] = 0x01; + memcpy(buf.data() + 4, &reinterpret_cast(&addr)->sin_addr, 4); } - else if (isIPv6(host)) { - + else if (isIPv6(host, &addr)) { + buf.resize(22); + buf[3] = 0x04; + memcpy(buf.data() + 4, &reinterpret_cast(&addr)->sin6_addr, 16); } else { buf.resize(host.size() + 7); diff --git a/src/base/net/stratum/Socks5.h b/src/base/net/stratum/Socks5.h index 927a7fc04..74ff66437 100644 --- a/src/base/net/stratum/Socks5.h +++ b/src/base/net/stratum/Socks5.h @@ -44,8 +44,8 @@ private: Ready }; - bool isIPv4(const String &host) const; - bool isIPv6(const String &host) const; + bool isIPv4(const String &host, sockaddr_storage *addr) const; + bool isIPv6(const String &host, sockaddr_storage *addr) const; void connect(); Client *m_client;