Merge pull request #2583 from laanwj/2013_04_netbase_bitfield

netbase: fix !O_NONBLOCK where ~O_NONBLOCK was meant
This commit is contained in:
Pieter Wuille 2013-04-29 16:36:51 -07:00
commit 1c621e70be
1 changed files with 10 additions and 17 deletions

View File

@ -72,19 +72,14 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
aiHint.ai_socktype = SOCK_STREAM; aiHint.ai_socktype = SOCK_STREAM;
aiHint.ai_protocol = IPPROTO_TCP; aiHint.ai_protocol = IPPROTO_TCP;
#ifdef WIN32 #ifdef USE_IPV6
# ifdef USE_IPV6
aiHint.ai_family = AF_UNSPEC; aiHint.ai_family = AF_UNSPEC;
# else #else
aiHint.ai_family = AF_INET; aiHint.ai_family = AF_INET;
# endif #endif
#ifdef WIN32
aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST; aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
#else #else
# ifdef USE_IPV6
aiHint.ai_family = AF_UNSPEC;
# else
aiHint.ai_family = AF_INET;
# endif
aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST; aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
#endif #endif
struct addrinfo *aiRes = NULL; struct addrinfo *aiRes = NULL;
@ -119,13 +114,12 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup) bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
{ {
std::string str(pszName); std::string strHost(pszName);
std::string strHost = str; if (strHost.empty())
if (str.empty())
return false; 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); return LookupIntern(strHost.c_str(), vIP, nMaxSolutions, fAllowLookup);
@ -222,10 +216,9 @@ bool static Socks5(string strDest, int port, SOCKET& hSocket)
return error("Hostname too long"); return error("Hostname too long");
} }
char pszSocks5Init[] = "\5\1\0"; char pszSocks5Init[] = "\5\1\0";
char *pszSocks5 = pszSocks5Init;
ssize_t nSize = sizeof(pszSocks5Init) - 1; 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) if (ret != nSize)
{ {
closesocket(hSocket); closesocket(hSocket);
@ -414,7 +407,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR) if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
#else #else
fFlags = fcntl(hSocket, F_GETFL, 0); 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 #endif
{ {
closesocket(hSocket); closesocket(hSocket);