diff options
author | Coren[m] <Break@Ocean> | 2013-09-10 20:55:05 +0200 |
---|---|---|
committer | Coren[m] <Break@Ocean> | 2013-09-10 20:55:05 +0200 |
commit | 3ae7460853b6777e18f213b316d43cef6c5a603e (patch) | |
tree | f18cc1d542ded6b073ec5dc8b57bc9953a246ca8 /toxcore/util.c | |
parent | f267266bf611570c6e79dfb800e97396151ff870 (diff) |
util.*:
- added logging functions, default off
tox.h:
- added includes for sockaddr_in/6
network.c:
- added logging functions, default off (#define in util.h)
- IPv6: activating site-local all-nodes multicast address (i.e. IPv6 equivalent of broadcast)
Diffstat (limited to 'toxcore/util.c')
-rw-r--r-- | toxcore/util.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/toxcore/util.c b/toxcore/util.c index ff366a07..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); |
@@ -41,3 +42,30 @@ void id_cpy(uint8_t *dest, uint8_t *src) | |||
41 | { | 42 | { |
42 | memcpy(dest, src, CLIENT_ID_SIZE); | 43 | memcpy(dest, src, CLIENT_ID_SIZE); |
43 | } | 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 | ||