From: Sami Kerola Date: Thu, 29 Sep 2016 18:30:02 +0000 (+0100) Subject: misc: improve random initialization X-Git-Tag: v0.88~24^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F151%2Fhead;p=thirdparty%2Fmtr.git misc: improve random initialization Typical linux pid range is 2^15, which is not a lot as a entropy sourcee. This change uses full 32 bits when random is initialized. Signed-off-by: Sami Kerola --- diff --git a/mtr.c b/mtr.c index 6b214b4..377283c 100644 --- a/mtr.c +++ b/mtr.c @@ -46,6 +46,7 @@ #include #include #include +#include #include "mtr.h" #include "mtr-curses.h" @@ -611,6 +612,13 @@ static void parse_mtr_options (struct mtr_ctl *ctl, char *string) optind = 0; } +static void init_rand(void) +{ + struct timeval tv; + + gettimeofday(&tv, 0); + srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); +} extern int main(int argc, char **argv) { @@ -662,7 +670,7 @@ extern int main(int argc, char **argv) atexit(close_stdout); /* reset the random seed */ - srand (getpid()); + init_rand(); display_detect(&ctl, &argc, &argv); ctl.display_mode = DisplayModeDefault;