diff options
-rw-r--r-- | src/lib/libc/net/res_random.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/lib/libc/net/res_random.c b/src/lib/libc/net/res_random.c index f6956bdd36..3767d9315f 100644 --- a/src/lib/libc/net/res_random.c +++ b/src/lib/libc/net/res_random.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: res_random.c,v 1.2 1997/04/19 09:53:25 provos Exp $ */ | 1 | /* $OpenBSD: res_random.c,v 1.3 1997/04/19 10:07:01 provos Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
@@ -67,7 +67,6 @@ | |||
67 | #include <unistd.h> | 67 | #include <unistd.h> |
68 | #include <stdlib.h> | 68 | #include <stdlib.h> |
69 | #include <string.h> | 69 | #include <string.h> |
70 | #include <time.h> | ||
71 | 70 | ||
72 | #define RU_OUT 180 /* Time after wich will be reseeded */ | 71 | #define RU_OUT 180 /* Time after wich will be reseeded */ |
73 | #define RU_MAX 30000 /* Uniq cycle, avoid blackjack prediction */ | 72 | #define RU_MAX 30000 /* Uniq cycle, avoid blackjack prediction */ |
@@ -89,8 +88,9 @@ static u_int16_t ru_a, ru_b; | |||
89 | static u_int16_t ru_g; | 88 | static u_int16_t ru_g; |
90 | static u_int16_t ru_counter = 0; | 89 | static u_int16_t ru_counter = 0; |
91 | static u_int16_t ru_msb = 0; | 90 | static u_int16_t ru_msb = 0; |
92 | static time_t ru_reseed; | 91 | static long ru_reseed; |
93 | static u_int32_t tmp; /* Storage for unused random */ | 92 | static u_int32_t tmp; /* Storage for unused random */ |
93 | static struct timeval tv; | ||
94 | 94 | ||
95 | static u_int32_t pmod __P((u_int32_t, u_int32_t, u_int32_t)); | 95 | static u_int32_t pmod __P((u_int32_t, u_int32_t, u_int32_t)); |
96 | static void res_initid __P((void)); | 96 | static void res_initid __P((void)); |
@@ -171,7 +171,8 @@ res_initid() | |||
171 | ru_g = pmod(RU_GEN,j,RU_N); | 171 | ru_g = pmod(RU_GEN,j,RU_N); |
172 | ru_counter = 0; | 172 | ru_counter = 0; |
173 | 173 | ||
174 | ru_reseed = time(NULL) + RU_OUT; | 174 | gettimeofday(&tv, NULL); |
175 | ru_reseed = tv.tv_sec + RU_OUT; | ||
175 | ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; | 176 | ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; |
176 | } | 177 | } |
177 | 178 | ||
@@ -180,7 +181,8 @@ res_randomid() | |||
180 | { | 181 | { |
181 | int i, n; | 182 | int i, n; |
182 | 183 | ||
183 | if (ru_counter >= RU_MAX || time(NULL) > ru_reseed) | 184 | gettimeofday(&tv, NULL); |
185 | if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed) | ||
184 | res_initid(); | 186 | res_initid(); |
185 | 187 | ||
186 | if (!tmp) | 188 | if (!tmp) |
@@ -211,6 +213,7 @@ main(int argc, char **argv) | |||
211 | 213 | ||
212 | printf("Generator: %d\n", ru_g); | 214 | printf("Generator: %d\n", ru_g); |
213 | printf("Seed: %d\n", ru_seed); | 215 | printf("Seed: %d\n", ru_seed); |
216 | printf("Reseed at %ld\n", ru_reseed); | ||
214 | printf("Ru_X: %d\n", ru_x); | 217 | printf("Ru_X: %d\n", ru_x); |
215 | printf("Ru_A: %d\n", ru_a); | 218 | printf("Ru_A: %d\n", ru_a); |
216 | printf("Ru_B: %d\n", ru_b); | 219 | printf("Ru_B: %d\n", ru_b); |