mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 09:34:19 +00:00
secure_rand() as replacement for client source port generation
This commit is contained in:
parent
5a2ee37891
commit
f3f33904f7
|
@ -2547,6 +2547,13 @@ void secure_random_fill(void *bytes, size_t length)
|
|||
#endif
|
||||
}
|
||||
|
||||
int secure_rand()
|
||||
{
|
||||
int i;
|
||||
secure_random_fill(&i, sizeof(i));
|
||||
return i;
|
||||
}
|
||||
|
||||
#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