Adding preseending to rands

remotes/origin/master-1.0.x
Pablo Rincon 15 years ago committed by Victor Julien
parent b2ee780788
commit 6224c30548

@ -26,6 +26,7 @@
#include "decode-ipv6.h"
#include "util-hashlist.h"
#include "util-pool.h"
#include "util-time.h"
#include "util-print.h"
#include "util-debug.h"
#include "util-fix_checksum.h"
@ -1265,7 +1266,10 @@ void
DefragInit(void)
{
/* Initialize random value for hashing and hash table size. */
defrag_hash_rand = rand();
unsigned int seed = TimeRandPreseed();
/* set defaults */
defrag_hash_rand = (int)( DEFAULT_DEFRAG_HASH_SIZE * (rand_r(&seed) / RAND_MAX + 1.0)) ; /* XXX seed rand */
defrag_hash_size = DEFAULT_DEFRAG_HASH_SIZE;
/* Allocate the DefragContext. */

@ -436,8 +436,10 @@ void FlowInitConfig (char quiet)
}
SCMutexInit(&flow_memuse_mutex, NULL);
unsigned int seed = TimeRandPreseed();
/* set defaults */
flow_config.hash_rand = rand(); /* XXX seed rand */
flow_config.hash_rand = (int)( FLOW_DEFAULT_HASHSIZE * (rand_r(&seed) / RAND_MAX + 1.0)) ; /* XXX seed rand */
flow_config.hash_size = FLOW_DEFAULT_HASHSIZE;
flow_config.memcap = FLOW_DEFAULT_MEMCAP;
flow_config.prealloc = FLOW_DEFAULT_PREALLOC;

@ -79,3 +79,19 @@ void TimeSetIncrementTime(uint32_t tv_sec) {
TimeSet(&tv);
}
/**
* \brief create a seed number to pass to rand() , rand_r(), and similars
*/
unsigned int TimeRandPreseed(void) {
/* preseed rand() */
time_t now = time ( 0 );
unsigned char *p = (unsigned char *)&now;
unsigned seed = 0;
size_t ind;
for ( ind = 0; ind < sizeof now; ind++ )
seed = seed * ( UCHAR_MAX + 2U ) + p[ind];
return seed;
}

@ -10,5 +10,7 @@ void TimeSetIncrementTime(uint32_t);
void TimeModeSetLive(void);
void TimeModeSetOffline (void);
unsigned int TimeRandPreseed(void);
#endif /* __UTIL_TIME_H__ */

Loading…
Cancel
Save