Project

General

Profile

Bug #16 ยป 0001-Adding-preseending-to-rands.patch

Pablo Rincon, 12/30/2009 07:05 PM

View differences:

src/defrag.c
#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"
......
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. */
src/flow.c
}
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;
src/util-time.c
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;
}
src/util-time.h
void TimeModeSetLive(void);
void TimeModeSetOffline (void);
unsigned int TimeRandPreseed(void);
#endif /* __UTIL_TIME_H__ */
    (1-1/1)