From f496333ce02c85e44caf5eb9e72e7b45afd9e925 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Fri, 20 Mar 2020 21:10:26 +0800 Subject: [PATCH] Add host name resolve when adding ShadowsocksR nodes to Surge configs --- src/socket.h | 2 +- src/subexport.cpp | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/socket.h b/src/socket.h index fabe5ba..ed86f27 100644 --- a/src/socket.h +++ b/src/socket.h @@ -48,7 +48,7 @@ int setTimeout(SOCKET s, int timeout); int startConnect(SOCKET sHost, std::string addr, int port); int simpleSend(std::string addr, int port, std::string data); int send_simple(SOCKET sHost, std::string data); -std::string hostnameToIPAddr(std::string host); +std::string hostnameToIPAddr(const std::string &host); int connectSocks5(SOCKET sHost, std::string username, std::string password); int connectThruSocks(SOCKET sHost, std::string host, int port); int connectThruHTTP(SOCKET sHost, std::string username, std::string password, std::string dsthost, int dstport); diff --git a/src/subexport.cpp b/src/subexport.cpp index ec2e93e..6e404dc 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -25,8 +25,7 @@ extern string_array ss_ciphers, ssr_ciphers; string_array clashr_protocols = {"auth_aes128_md5", "auth_aes128_sha1"}; string_array clashr_obfs = {"plain", "http_simple", "http_post", "tls1.2_ticket_auth"}; -/* -std::string hostnameToIPAddr(std::string host) +std::string hostnameToIPAddr(const std::string &host) { int retVal; std::string retAddr; @@ -60,7 +59,6 @@ std::string hostnameToIPAddr(std::string host) freeaddrinfo(retAddrInfo); return retAddr; } -*/ std::string vmessConstruct(std::string add, std::string port, std::string type, std::string id, std::string aid, std::string net, std::string cipher, std::string path, std::string host, std::string edge, std::string tls, int local_port) { @@ -1087,9 +1085,8 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s { return std::move(a) + "\", args=\"" + std::move(b); }); - //std::string ipaddr = (isIPv4(hostname) || isIPv6(hostname)) ? hostname : hostnameToIPAddr(hostname); - //proxy += "\", local-port=" + std::to_string(local_port) + ", addresses=" + ipaddr; - proxy += "\", local-port=" + std::to_string(local_port); + proxy += "\", local-port=" + std::to_string(local_port) + ", addresses=" + ((isIPv4(hostname) || isIPv6(hostname)) ? hostname : hostnameToIPAddr(hostname)); + //proxy += "\", local-port=" + std::to_string(local_port); local_port++; break; case SPEEDTEST_MESSAGE_FOUNDSOCKS: