From ec91a3e9a5169f82c85c4c853e5109dd44ef3486 Mon Sep 17 00:00:00 2001 From: Wladimir J. van der Laan Date: Sat, 27 Apr 2013 14:27:05 +0200 Subject: [PATCH] fix !O_NONBLOCK where ~O_NONBLOCK was meant Using ! on a non-zero value will always return 0. Also remove some duplicate and superfluous code in other places. --- src/netbase.cpp | 27 ++++++++++----------------- 1 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index 98cdc27..2df8ad7 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -82,19 +82,14 @@ bool static LookupIntern(const char *pszName, std::vector& vIP, unsign aiHint.ai_socktype = SOCK_STREAM; aiHint.ai_protocol = IPPROTO_TCP; -#ifdef WIN32 -# ifdef USE_IPV6 +#ifdef USE_IPV6 aiHint.ai_family = AF_UNSPEC; -# else +#else aiHint.ai_family = AF_INET; -# endif +#endif +#ifdef WIN32 aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST; #else -# ifdef USE_IPV6 - aiHint.ai_family = AF_UNSPEC; -# else - aiHint.ai_family = AF_INET; -# endif aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST; #endif struct addrinfo *aiRes = NULL; @@ -130,13 +125,12 @@ bool static LookupIntern(const char *pszName, std::vector& vIP, unsign bool LookupHost(const char *pszName, std::vector& vIP, unsigned int nMaxSolutions, bool fAllowLookup) { - std::string str(pszName); - std::string strHost = str; - if (str.empty()) + std::string strHost(pszName); + if (strHost.empty()) return false; - if (boost::algorithm::starts_with(str, "[") && boost::algorithm::ends_with(str, "]")) + if (boost::algorithm::starts_with(strHost, "[") && boost::algorithm::ends_with(strHost, "]")) { - strHost = str.substr(1, str.size() - 2); + strHost = strHost.substr(1, strHost.size() - 2); } return LookupIntern(strHost.c_str(), vIP, nMaxSolutions, fAllowLookup); @@ -233,10 +227,9 @@ bool static Socks5(string strDest, int port, SOCKET& hSocket) return error("Hostname too long"); } char pszSocks5Init[] = "\5\1\0"; - char *pszSocks5 = pszSocks5Init; ssize_t nSize = sizeof(pszSocks5Init) - 1; - ssize_t ret = send(hSocket, pszSocks5, nSize, MSG_NOSIGNAL); + ssize_t ret = send(hSocket, pszSocks5Init, nSize, MSG_NOSIGNAL); if (ret != nSize) { closesocket(hSocket); @@ -425,7 +418,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR) #else fFlags = fcntl(hSocket, F_GETFL, 0); - if (fcntl(hSocket, F_SETFL, fFlags & !O_NONBLOCK) == SOCKET_ERROR) + if (fcntl(hSocket, F_SETFL, fFlags & ~O_NONBLOCK) == SOCKET_ERROR) #endif { closesocket(hSocket); -- 1.7.1