diff options
author | irungentoo <irungentoo@gmail.com> | 2013-06-27 17:19:09 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-06-27 17:19:09 -0400 |
commit | 3986206de89f7094ba1300e72a7a46916bae7ff4 (patch) | |
tree | 5b97a5d2d3c325d3b7e9259b0587c08431e2b731 /core | |
parent | 87633f663134127b84fbc61828bfba491e149f6a (diff) |
Added a function.
Diffstat (limited to 'core')
-rw-r--r-- | core/network.c | 14 | ||||
-rw-r--r-- | core/network.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/core/network.c b/core/network.c index 81da3f1b..a20b02f6 100644 --- a/core/network.c +++ b/core/network.c | |||
@@ -40,6 +40,16 @@ uint64_t current_time() | |||
40 | 40 | ||
41 | } | 41 | } |
42 | 42 | ||
43 | int random_int() | ||
44 | { | ||
45 | #ifdef WIN32 | ||
46 | //TODO replace rand with a more random windows function | ||
47 | return rand(); | ||
48 | #else | ||
49 | return random(); | ||
50 | #endif | ||
51 | } | ||
52 | |||
43 | //our UDP socket, a global variable. | 53 | //our UDP socket, a global variable. |
44 | static int sock; | 54 | static int sock; |
45 | 55 | ||
@@ -87,7 +97,11 @@ int init_networking(IP ip ,uint16_t port) | |||
87 | { | 97 | { |
88 | return -1; | 98 | return -1; |
89 | } | 99 | } |
100 | |||
101 | #else | ||
102 | srandom((uint32_t)current_time()); | ||
90 | #endif | 103 | #endif |
104 | srand((uint32_t)current_time()); | ||
91 | 105 | ||
92 | //initialize our socket | 106 | //initialize our socket |
93 | sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); | 107 | sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
diff --git a/core/network.h b/core/network.h index 24f7281d..da92837d 100644 --- a/core/network.h +++ b/core/network.h | |||
@@ -79,6 +79,9 @@ typedef struct | |||
79 | //returns current time in milleseconds since the epoch. | 79 | //returns current time in milleseconds since the epoch. |
80 | uint64_t current_time(); | 80 | uint64_t current_time(); |
81 | 81 | ||
82 | //return a random number | ||
83 | int random_int(); | ||
84 | |||
82 | //Basic network functions: | 85 | //Basic network functions: |
83 | 86 | ||
84 | //Function to send packet(data) of length length to ip_port | 87 | //Function to send packet(data) of length length to ip_port |