-
Notifications
You must be signed in to change notification settings - Fork 115
/
main.h
95 lines (83 loc) · 2.37 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* main.h
* Copyright (C) 2019, basil
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MAIN_H
#define __MAIN_H
#define PROGNAME "Tallow"
#define STR2(s) #s
#define STR(s) STR2(s)
#define TOR_PORT 49097
#define TOR_ICON 49001
#define ADDR0(a) ((a) >> 24)
#define ADDR1(a) (((a) >> 16) & 0xFF)
#define ADDR2(a) (((a) >> 8) & 0xFF)
#define ADDR3(a) ((a) & 0xFF)
#define MAX_PACKET 4096
#define RED 1
#define GREEN 2
#define BLUE 3
#define YELLOW 4
#define MAGENTA 5
#define CYAN 6
extern void status(const char *message, ...);
extern void warning(const char *message, ...);
// Options:
extern bool option_force_socks4a;
extern bool option_force_web_only;
// Locking functions:
static inline HANDLE create_lock(void)
{
HANDLE lock = CreateMutex(NULL, FALSE, NULL);
if (lock == NULL)
{
warning("failed to create lock");
exit(EXIT_FAILURE);
}
return lock;
}
static inline void lock(HANDLE lock)
{
DWORD result = WaitForSingleObject(lock, INFINITE);
if (result != WAIT_OBJECT_0)
{
warning("failed to acquire lock");
exit(EXIT_FAILURE);
}
}
static inline void unlock(HANDLE lock)
{
if (!ReleaseMutex(lock))
{
warning("failed to release lock");
exit(EXIT_FAILURE);
}
}
// (Strong) random number:
errno_t __cdecl rand_s(unsigned int *);
static inline unsigned random(void)
{
unsigned r;
if (rand_s(&r) != 0)
{
warning("failed to get random number");
exit(EXIT_FAILURE);
}
return r;
}
// Debugging:
extern void debug(int color, const char *event, const char *message, ...);
#endif