X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fstun.cpp;h=1ab410e2ec035ae90aefce28a211d967d3a79c41;hb=3814af1ef1a10f25e7a76929edfd3abdb0ab791d;hp=f724eaaf78981a5c2c2eca2ccc0e643e44384f22;hpb=196cd7a443bc09ac1485cce0e82e472a46a78152;p=novacoin.git diff --git a/src/stun.cpp b/src/stun.cpp index f724eaa..1ab410e 100644 --- a/src/stun.cpp +++ b/src/stun.cpp @@ -29,7 +29,8 @@ */ #include -#include +#include +#include #include #include #include @@ -41,16 +42,17 @@ #include #include #endif -#ifndef _MSC_VER +#ifndef WIN32 #include -#else -#include #endif #include #include #include "ministun.h" +extern int GetRandInt(int nMax); +extern uint64_t GetRand(uint64_t nMax); + /*---------------------------------------------------------------------*/ struct StunSrv { @@ -336,10 +338,15 @@ static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp) } /* helper function to generate a random request id */ -static uint64_t randfiller; +static uint64_t randfiller = GetRand(std::numeric_limits::max()); static void stun_req_id(struct stun_header *req) { const uint64_t *S_block = (const uint64_t *)StunSrvList; + req->id.id[0] = GetRandInt(std::numeric_limits::max()); + req->id.id[1] = GetRandInt(std::numeric_limits::max()); + req->id.id[2] = GetRandInt(std::numeric_limits::max()); + req->id.id[3] = GetRandInt(std::numeric_limits::max()); + req->id.id[0] |= 0x55555555; req->id.id[1] &= 0x55555555; req->id.id[2] |= 0x55555555; @@ -509,10 +516,10 @@ static int StunRequest(const char *host, uint16_t port, struct sockaddr_in *mapp int rc = -3; if(bind(sock, (struct sockaddr*)&client, sizeof(client)) >= 0) rc = StunRequest2(sock, &server, mapped); -#ifndef _MSC_VER +#ifndef WIN32 close(sock); #else - _close(sock); + closesocket(sock); #endif return rc; } // StunRequest