diff options
Diffstat (limited to 'src/fnettrace/fnettrace.h')
-rw-r--r-- | src/fnettrace/fnettrace.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/fnettrace/fnettrace.h b/src/fnettrace/fnettrace.h new file mode 100644 index 000000000..9c34e17ca --- /dev/null +++ b/src/fnettrace/fnettrace.h | |||
@@ -0,0 +1,64 @@ | |||
1 | #ifndef FNETTRACE_H | ||
2 | #define FNETTRACE_H | ||
3 | |||
4 | #include "../include/common.h" | ||
5 | #include <unistd.h> | ||
6 | #include <sys/stat.h> | ||
7 | #include <sys/socket.h> | ||
8 | #include <netinet/in.h> | ||
9 | #include <time.h> | ||
10 | #include <stdarg.h> | ||
11 | |||
12 | //#define NETLOCK_INTERVAL 60 | ||
13 | #define NETLOCK_INTERVAL 60 | ||
14 | #define DISPLAY_INTERVAL 3 | ||
15 | |||
16 | void logprintf(char* fmt, ...); | ||
17 | |||
18 | static inline void ansi_topleft(int tolog) { | ||
19 | char str[] = {0x1b, '[', '1', ';', '1', 'H', '\0'}; | ||
20 | if (tolog) | ||
21 | logprintf("%s", str); | ||
22 | else | ||
23 | printf("%s", str); | ||
24 | fflush(0); | ||
25 | } | ||
26 | |||
27 | static inline void ansi_clrscr(int tolog) { | ||
28 | ansi_topleft(tolog); | ||
29 | char str[] = {0x1b, '[', '0', 'J', '\0'}; | ||
30 | if (tolog) | ||
31 | logprintf("%s", str); | ||
32 | else | ||
33 | printf("%s", str); | ||
34 | fflush(0); | ||
35 | } | ||
36 | |||
37 | static inline void ansi_linestart(int tolog) { | ||
38 | char str[] = {0x1b, '[', '0', 'G', '\0'}; | ||
39 | if (tolog) | ||
40 | logprintf("%s", str); | ||
41 | else | ||
42 | printf("%s", str); | ||
43 | fflush(0); | ||
44 | } | ||
45 | |||
46 | static inline void ansi_clrline(int tolog) { | ||
47 | ansi_linestart(tolog); | ||
48 | char str[] = {0x1b, '[', '0', 'K', '\0'}; | ||
49 | if (tolog) | ||
50 | logprintf("%s", str); | ||
51 | else | ||
52 | printf("%s", str); | ||
53 | fflush(0); | ||
54 | } | ||
55 | |||
56 | static inline uint8_t hash(uint32_t ip) { | ||
57 | uint8_t *ptr = (uint8_t *) &ip; | ||
58 | // simple byte xor | ||
59 | return *ptr ^ *(ptr + 1) ^ *(ptr + 2) ^ *(ptr + 3); | ||
60 | } | ||
61 | |||
62 | |||
63 | |||
64 | #endif \ No newline at end of file | ||