X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fstun.cpp;h=62e302fffe299e8f20b1acf3114350669e23014b;hb=afc2bcf340f842111978138a9e04e0b14e5de9fe;hp=4bf2c94c440e2fddeb9d663d0309fd814b4c78dd;hpb=49bdda2cb161f357de715c32bd5cc32a40a0f896;p=novacoin.git diff --git a/src/stun.cpp b/src/stun.cpp index 4bf2c94..62e302f 100644 --- a/src/stun.cpp +++ b/src/stun.cpp @@ -29,7 +29,8 @@ */ #include -#include +#include +#include #include #include #include @@ -49,6 +50,9 @@ #include "ministun.h" +extern int GetRandInt(int nMax); +extern uint64_t GetRand(uint64_t nMax); + /*---------------------------------------------------------------------*/ struct StunSrv { @@ -334,15 +338,20 @@ 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; req->id.id[3] &= 0x55555555; - register char x = 20; + char x = 20; do { uint32_t s_elm = S_block[(uint8_t)randfiller]; randfiller ^= (randfiller << 5) | (randfiller >> (64 - 5)); @@ -447,7 +456,7 @@ static int StunRequest2(int sock, struct sockaddr_in *server, struct sockaddr_in req = (struct stun_header *)reqdata; stun_req_id(req); - int reqlen = 0; + unsigned short reqlen = 0; req->msgtype = 0; req->msglen = 0; req->msglen = htons(reqlen);