X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fnet.cpp;h=ab079cfcff177c87c1d8ed1084c24b252bac826b;hb=428f94b5411bf51b6e77d611daa709dfbb063966;hp=0c166ebcf04ab6730ac7aa0b3f000873b6f795f0;hpb=17a6c72f2ee4421c07d002983a1f11645b008934;p=novacoin.git diff --git a/src/net.cpp b/src/net.cpp index 0c166eb..ab079cf 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -35,6 +35,17 @@ void ThreadMapPort2(void* parg); #endif void ThreadDNSAddressSeed2(void* parg); +// Fix for ancient MinGW versions, that don't have defined these in ws2tcpip.h. +// Todo: Can be removed when our pull-tester is upgraded to a modern MinGW version. +#ifdef WIN32 +#ifndef PROTECTION_LEVEL_UNRESTRICTED +#define PROTECTION_LEVEL_UNRESTRICTED 10 +#endif +#ifndef IPV6_PROTECTION_LEVEL +#define IPV6_PROTECTION_LEVEL 23 +#endif +#endif + struct LocalServiceInfo { int nScore; int nPort; @@ -307,7 +318,7 @@ extern int GetExternalIPbySTUN(uint64_t rnd, struct sockaddr_in *mapped, const c bool GetMyExternalIP(CNetAddr& ipRet) { struct sockaddr_in mapped; - uint64_t rnd = UINT64_MAX; + uint64_t rnd = std::numeric_limits::max(); const char *srv; int rc = GetExternalIPbySTUN(rnd, &mapped, &srv); if(rc >= 0) { @@ -1749,18 +1760,16 @@ bool BindListenPort(const CService &addrBind, string& strError) return false; } +#ifndef WIN32 #ifdef SO_NOSIGPIPE // Different way of disabling SIGPIPE on BSD setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int)); #endif - -#ifndef WIN32 // Allow binding if the port is still in TIME_WAIT state after - // the program was closed and restarted. Not an issue on windows. + // the program was closed and restarted. Not an issue on windows! setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int)); #endif - #ifdef WIN32 // Set to non-blocking, incoming connections will also inherit this if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) == SOCKET_ERROR) @@ -1785,10 +1794,8 @@ bool BindListenPort(const CService &addrBind, string& strError) #endif #endif #ifdef WIN32 - int nProtLevel = 10 /* PROTECTION_LEVEL_UNRESTRICTED */; - int nParameterId = 23 /* IPV6_PROTECTION_LEVEl */; - // this call is allowed to fail - setsockopt(hListenSocket, IPPROTO_IPV6, nParameterId, (const char*)&nProtLevel, sizeof(int)); + int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED; + setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int)); #endif } #endif @@ -1801,6 +1808,7 @@ bool BindListenPort(const CService &addrBind, string& strError) else strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %d, %s)"), addrBind.ToString().c_str(), nErr, strerror(nErr)); printf("%s\n", strError.c_str()); + closesocket(hListenSocket); return false; } printf("Bound to %s\n", addrBind.ToString().c_str()); @@ -1810,6 +1818,7 @@ bool BindListenPort(const CService &addrBind, string& strError) { strError = strprintf("Error: Listening for incoming connections failed (listen returned error %d)", WSAGetLastError()); printf("%s\n", strError.c_str()); + closesocket(hListenSocket); return false; }