diff options
Diffstat (limited to 'toxcore/util.c')
-rw-r--r-- | toxcore/util.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/toxcore/util.c b/toxcore/util.c index 1728ea21..19d464d4 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -10,11 +10,12 @@ | |||
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 | 16 | ||
17 | #include "util.h" | ||
18 | |||
18 | uint64_t now() | 19 | uint64_t now() |
19 | { | 20 | { |
20 | return time(NULL); | 21 | return time(NULL); |
@@ -32,11 +33,6 @@ uint64_t random_64b() | |||
32 | return r; | 33 | return r; |
33 | } | 34 | } |
34 | 35 | ||
35 | bool ipp_eq(IP_Port a, IP_Port b) | ||
36 | { | ||
37 | return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port); | ||
38 | } | ||
39 | |||
40 | bool id_eq(uint8_t *dest, uint8_t *src) | 36 | bool id_eq(uint8_t *dest, uint8_t *src) |
41 | { | 37 | { |
42 | return memcmp(dest, src, CLIENT_ID_SIZE) == 0; | 38 | return memcmp(dest, src, CLIENT_ID_SIZE) == 0; |
@@ -46,3 +42,30 @@ void id_cpy(uint8_t *dest, uint8_t *src) | |||
46 | { | 42 | { |
47 | memcpy(dest, src, CLIENT_ID_SIZE); | 43 | memcpy(dest, src, CLIENT_ID_SIZE); |
48 | } | 44 | } |
45 | |||
46 | #ifdef LOGGING | ||
47 | char logbuffer[512]; | ||
48 | static FILE *logfile = NULL; | ||
49 | void loginit(uint16_t port) | ||
50 | { | ||
51 | if (logfile) | ||
52 | fclose(logfile); | ||
53 | |||
54 | sprintf(logbuffer, "%u-%u.log", ntohs(port), now); | ||
55 | logfile = fopen(logbuffer, "w"); | ||
56 | }; | ||
57 | void loglog(char *text) | ||
58 | { | ||
59 | if (logfile) { | ||
60 | fprintf(logfile, text); | ||
61 | fflush(logfile); | ||
62 | } | ||
63 | }; | ||
64 | void logexit() | ||
65 | { | ||
66 | if (logfile) { | ||
67 | fclose(logfile); | ||
68 | logfile = NULL; | ||
69 | } | ||
70 | }; | ||
71 | #endif | ||