-
Notifications
You must be signed in to change notification settings - Fork 5
/
transockproxy.h
91 lines (76 loc) · 2.28 KB
/
transockproxy.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
/*
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, version 2 of the License only.
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/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <fnmatch.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <string.h>
#include <strings.h>
#include <pthread.h>
#include <signal.h>
#ifdef GNUTLS
#include <gnutls/gnutls.h>
#endif
/* This must be at least enough to hold HTTP headers. */
#define BUFFERSIZE 8192
enum Proto {
INVALID,
DIRECT,
SOCKS4,
SOCKS4A,
SOCKS5
};
struct Mapping {
const char* pattern;
enum Proto proto;
union {
struct sockaddr_in proxy;
char iface[sizeof(struct sockaddr_in)];
};
};
extern volatile sig_atomic_t exitflag;
extern volatile sig_atomic_t running;
extern enum Proto defproto;
extern struct sockaddr_in defaddr;
extern struct Mapping** mappings;
extern int mappingcount;
#ifdef GNUTLS
extern char* certfile;
extern char* keyfile;
#endif
void gnutlsinit();
void gnutlspostinit();
void readconfig(struct sockaddr_in* laddr, struct sockaddr_in* ssladdr);
void* connthread(void* arg);
void* gnutlsthread(void* arg);
int writeall(int fd, const char* buffer, int size);
void sighandle(int sig);
const struct Mapping* findserver(const char* host);
int directconnect(int csock, int ssock, char* host, const char* defport, const struct Mapping* map);
int socks4connect(int csock, int ssock, char* host, unsigned short defport);
int socks4aconnect(int csock, int ssock, char* host, unsigned short defport);
int socks5connect(int csock, int ssock, char* host, unsigned short defport);
#ifdef DAEMON
#define log(a...)
#define warn(a...)
#else
#define log(a...) printf(a)
#define warn(a...) fprintf(stderr, a)
#endif