mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #396 from east/securerand
secure_rand() as replacement for client source port generation
This commit is contained in:
commit
eaafe4ca05
|
@ -2547,6 +2547,13 @@ void secure_random_fill(void *bytes, size_t length)
|
|||
#endif
|
||||
}
|
||||
|
||||
int secure_rand()
|
||||
{
|
||||
unsigned int i;
|
||||
secure_random_fill(&i, sizeof(i));
|
||||
return (int)(i%RAND_MAX);
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1383,6 +1383,12 @@ int secure_random_init();
|
|||
*/
|
||||
void secure_random_fill(void *bytes, size_t length);
|
||||
|
||||
/*
|
||||
Function: secure_rand
|
||||
Returns random int (replacement for rand()).
|
||||
*/
|
||||
int secure_rand();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2582,10 +2582,10 @@ void CClient::Run()
|
|||
}
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
BindAddr.port = (rand() % 64511) + 1024;
|
||||
BindAddr.port = (secure_rand() % 64511) + 1024;
|
||||
while(!m_NetClient[i].Open(BindAddr, 0))
|
||||
{
|
||||
BindAddr.port = (rand() % 64511) + 1024;
|
||||
BindAddr.port = (secure_rand() % 64511) + 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3255,6 +3255,12 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
dbg_enable_threaded();
|
||||
#endif
|
||||
|
||||
if(secure_random_init() != 0)
|
||||
{
|
||||
dbg_msg("secure", "could not initialize secure RNG");
|
||||
return -1;
|
||||
}
|
||||
|
||||
CClient *pClient = CreateClient();
|
||||
IKernel *pKernel = IKernel::Create();
|
||||
pKernel->RegisterInterface(pClient);
|
||||
|
|
Loading…
Reference in a new issue