summaryrefslogtreecommitdiff
path: root/core/network.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-03 16:35:44 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-03 16:35:44 -0400
commitccb270add2c3ee1df8301a428e2029939250a9e0 (patch)
treea7cd3f09f16298915dcac03cd66c10dfb6b1bb96 /core/network.c
parent1e17492b783cd9ecfea57ef4cd2112c0fa155538 (diff)
Compiled for windows and fixed stuff accordingly.
Diffstat (limited to 'core/network.c')
-rw-r--r--core/network.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/core/network.c b/core/network.c
index 35257d54..601066cd 100644
--- a/core/network.c
+++ b/core/network.c
@@ -25,26 +25,34 @@
25#include "network.h" 25#include "network.h"
26 26
27 27
28//returns current time in milliseconds since the epoch. 28//returns current UNIX time in microseconds (us).
29uint64_t current_time() 29uint64_t current_time()
30{ 30{
31 uint64_t time; 31 uint64_t time;
32 #ifdef WIN32 32 #ifdef WIN32
33 //TODO: windows version 33 //This probably works fine
34 FILETIME ft;
35 GetSystemTimeAsFileTime(&ft);
36 time = ft.dwHighDateTime;
37 time <<=32;
38 time |= ft.dwLowDateTime;
39 time -= 116444736000000000UL;
40 return time/10;
34 #else 41 #else
35 struct timeval a; 42 struct timeval a;
36 gettimeofday(&a, NULL); 43 gettimeofday(&a, NULL);
37 time = 1000000UL*a.tv_sec + a.tv_usec; 44 time = 1000000UL*a.tv_sec + a.tv_usec;
38 #endif
39 return time; 45 return time;
46 #endif
47
40 48
41} 49}
42 50
43uint32_t random_int() 51uint32_t random_int()
44{ 52{
45 #ifdef WIN32 53 #ifdef WIN32
46 //TODO replace rand with something cryptograhically secure 54 //NOTE: this function comes from libsodium
47 return rand(); 55 return randombytes_random();
48 #else 56 #else
49 return random(); 57 return random();
50 #endif 58 #endif
@@ -69,7 +77,11 @@ int sendpacket(IP_Port ip_port, char * data, uint32_t length)
69int recievepacket(IP_Port * ip_port, char * data, uint32_t * length) 77int recievepacket(IP_Port * ip_port, char * data, uint32_t * length)
70{ 78{
71 ADDR addr; 79 ADDR addr;
80 #ifdef WIN32
81 int addrlen = sizeof(addr);
82 #else
72 uint32_t addrlen = sizeof(addr); 83 uint32_t addrlen = sizeof(addr);
84 #endif
73 (*(int32_t *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); 85 (*(int32_t *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
74 if(*(int32_t *)length <= 0) 86 if(*(int32_t *)length <= 0)
75 { 87 {