Commit 22728db0 authored by HiPhish's avatar HiPhish

Change seed generation

Using srandomdev is not portable, instead we read from the stream
"/dev/random" to get enough random bytes for the seed.
parent 9812479d
......@@ -35,6 +35,10 @@ static int handle_args(int argc, char **argv);
*/
static void print_usage(int error);
/** Get a suitable value for seeding. */
static unsigned int get_random_seed();
int main(int argc, char **argv) {
int return_val = R_SUCCES;
......@@ -62,7 +66,7 @@ static int handle_args(int argc, char **argv) {
char *delimiter = " ";
/* Set a safe seed */
srandomdev();
srandom(get_random_seed());
/* Loop over the arguments */
for (int i = 1; i < argc; ++i) {
......@@ -88,7 +92,7 @@ static int handle_args(int argc, char **argv) {
srandom(seed);
} else if (strcmp(arg, "--no-seed") == 0 || strcmp(arg, "-S") == 0) {
srandomdev();
srandom(get_random_seed());
} else if (strcmp(arg, "--delimiter") == 0 || (strcmp(arg, "-d") == 0)) {
/* There must be an argument after this */
if (++i == argc) {
......@@ -159,6 +163,14 @@ static int handle_args(int argc, char **argv) {
return R_SUCCES;
}
static unsigned int get_random_seed() {
unsigned seed = 0;
FILE *random = fopen("/dev/random", "rb");
fread(&seed, sizeof seed, 1, random);
fclose(random);
return seed;
}
static void print_usage(int error) {
/* Map error codes to error messages */
char *error_msg[] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment