summaryrefslogtreecommitdiff
path: root/src/libnet_prand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnet_prand.c')
-rw-r--r--src/libnet_prand.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/libnet_prand.c b/src/libnet_prand.c
index d62a24c..915a4d6 100644
--- a/src/libnet_prand.c
+++ b/src/libnet_prand.c
@@ -1,6 +1,4 @@
/*
- * $Id: libnet_prand.c,v 1.7 2004/01/28 19:45:00 mike Exp $
- *
* libnet
* libnet_prand.c - pseudo-random number generation
*
@@ -29,24 +27,33 @@
* SUCH DAMAGE.
*
*/
-
+
#include "common.h"
+#ifdef _WIN32
+#include <wincrypt.h>
+#include <time.h>
+
+#else
+#include <sys/time.h> /* gettimeofday() */
+#endif
+
+
int
libnet_seed_prand(libnet_t *l)
{
- #if !(__WIN32__)
+#ifndef WIN32
struct timeval seed;
- #endif
+#endif
if (l == NULL)
- {
+ {
return (-1);
- }
+ }
- #if __WIN32__
+#ifdef WIN32
srand((unsigned)time(NULL));
- #else
+#else
if (gettimeofday(&seed, NULL) == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
@@ -58,7 +65,7 @@ libnet_seed_prand(libnet_t *l)
* More entropy then just seeding with time(2).
*/
srandom((unsigned)(seed.tv_sec ^ seed.tv_usec));
- #endif
+#endif
return (1);
}
@@ -71,17 +78,16 @@ uint32_t
libnet_get_prand(int mod)
{
uint32_t n; /* 0 to 4,294,967,295 */
-#ifndef _WIN32
+#ifndef WIN32
n = random();
#else
- HCRYPTPROV hProv = 0;
- CryptAcquireContext(&hProv,
- 0, 0, PROV_RSA_FULL,
- CRYPT_VERIFYCONTEXT);
-
- CryptGenRandom(hProv,
- sizeof(n), (BYTE*)&n);
- CryptReleaseContext(hProv, 0);
+ HCRYPTPROV hProv = 0;
+
+ CryptAcquireContext(&hProv,
+ 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
+
+ CryptGenRandom(hProv, sizeof(n), (BYTE*)&n);
+ CryptReleaseContext(hProv, 0);
#endif
switch (mod)
{
@@ -101,4 +107,4 @@ libnet_get_prand(int mod)
return (0); /* NOTTREACHED */
}
-/* EOF */
+/* EOF */ \ No newline at end of file