summaryrefslogtreecommitdiff
path: root/toxcore/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/util.c')
-rw-r--r--toxcore/util.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/toxcore/util.c b/toxcore/util.c
index 653e8d5f..ad6a4a83 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -10,9 +10,8 @@
10#endif 10#endif
11 11
12#include <time.h> 12#include <time.h>
13#include <stdint.h>
14#include <stdbool.h>
15 13
14/* for CLIENT_ID_SIZE */
16#include "DHT.h" 15#include "DHT.h"
17#include "util.h" 16#include "util.h"
18 17
@@ -33,11 +32,6 @@ uint64_t random_64b()
33 return r; 32 return r;
34} 33}
35 34
36bool ipp_eq(IP_Port a, IP_Port b)
37{
38 return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port);
39}
40
41bool id_eq(uint8_t *dest, uint8_t *src) 35bool id_eq(uint8_t *dest, uint8_t *src)
42{ 36{
43 return memcmp(dest, src, CLIENT_ID_SIZE) == 0; 37 return memcmp(dest, src, CLIENT_ID_SIZE) == 0;
@@ -88,3 +82,33 @@ int load_state(load_state_callback_func load_state_callback, void *outer,
88 82
89 return length == 0 ? 0 : - 1; 83 return length == 0 ? 0 : - 1;
90}; 84};
85
86#ifdef LOGGING
87time_t starttime = 0;
88char logbuffer[512];
89static FILE *logfile = NULL;
90void loginit(uint16_t port)
91{
92 if (logfile)
93 fclose(logfile);
94
95 sprintf(logbuffer, "%u-%u.log", ntohs(port), now());
96 logfile = fopen(logbuffer, "w");
97 starttime = now();
98};
99void loglog(char *text)
100{
101 if (logfile) {
102 fprintf(logfile, "%4u ", now() - starttime);
103 fprintf(logfile, text);
104 fflush(logfile);
105 }
106};
107void logexit()
108{
109 if (logfile) {
110 fclose(logfile);
111 logfile = NULL;
112 }
113};
114#endif