-
Notifications
You must be signed in to change notification settings - Fork 0
/
socks_proto.h
90 lines (76 loc) · 1.82 KB
/
socks_proto.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
#ifndef SOCKS_PROTO_H
#define SOCKS_PROTO_H
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include "task.h"
typedef union {
uint8_t ipv4[4];
uint8_t ipv6[16];
struct {
char name[256]; // 255 + 1 for ending '\0'
uint8_t name_len;
} domain;
} host_union;
typedef unsigned int socks5_state_type;
typedef union {
uint8_t header[2];
struct {
uint8_t methods[256];
unsigned char nmethods;
} methods;
uint8_t response[2];
} auth_context_union;
typedef union {
uint8_t header[4];
struct {
unsigned char cmd;
unsigned char rep;
union {
struct {
host_union host;
uint16_t port;
unsigned char addr_type;
} request_addr;
struct {
char domain_name[256];
char port_str[6]; // max len = 5 (for 65535) +1 for ending '\0'
struct addrinfo hints;
struct addrinfo *res;
} getaddrinfo_args;
struct {
struct sockaddr_storage addr;
socklen_t addr_len;
} connect_addr;
} conn;
} req;
uint8_t response[10];
} request_context_union;
typedef union {
auth_context_union auth;
request_context_union req;
} socks5_context_union;
typedef struct {
task_struct task;
int client_sockfd;
int connect_sockfd;
struct {
socks5_state_type state;
socks5_context_union ctx;
} socks5_ctx;
} socks5_arg_struct;
typedef enum {
SOCKS5_RES_TASK = 0,
SOCKS5_RES_ERROR = 1,
SOCKS5_RES_DONE = 2,
} socks5_result_enum;
#define socks5_result_enum_count 3
typedef unsigned int socks5_result_type;
void socks5_init(socks5_arg_struct *socks5_arg, int client_sockfd);
socks5_result_type socks5(socks5_arg_struct *socks5_arg);
void socks5_close_all(socks5_arg_struct *socks5_arg);
int get_client_sockfd(socks5_arg_struct *socks5_arg);
int get_connect_sockfd(socks5_arg_struct *socks5_arg);
task_struct *get_task(socks5_arg_struct *socks5_arg);
#endif/*SOCKS_PROTO_H*/