-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathproto.h
131 lines (111 loc) · 2.96 KB
/
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef __PROTO_H__
#define __PROTO_H__
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h> // close()
#include <arpa/inet.h>
// VERSION
#define VERSION 0x05
#define AUTH_VERSION 0x01
// Method
#define NO_AUTHENTICATION_REQUIRED 0x00
#define GSSAPI 0x01
#define USERNAME_PASSWORD 0x02
#define NO_ACCEPTABLE_METHODS 0xff
// Status
#define AUTH_SUCCESS 0x00
#define AUTH_FAILURE 0x01
// Command
#define CONNECT 0x01
#define BIND 0x02
#define UDP 0x03
// Address type
#define IPV4 0x01
#define DOMAIN 0x03
#define IPV6 0x04
// Reply
#define SUCCEEDED 0x00
#define GENERAL_SOCKS_SERVER_FAILURE 0x01
#define CONNECTION_NOT_ALLOWED_BY_RULESET 0x02
#define NETWORK_UNREACHABLE 0x03
#define HOST_UNREACHABLE 0x04
#define CONNECTION_REFUSED 0x05
#define TTL_EXPIRED 0x06
#define COMMAND_NOT_SUPPORTED 0x07
#define ADDRESS_TYPE_NOT_SUPPORTED 0x08
// Length limit
#define MAX_ULEN 255
#define MAX_PLEN 255
#define MAX_METHOD_REQUEST_LEN 257
#define MIN_METHOD_REQUEST_LEN 3
#define MAX_AUTH_REQUEST_LEN 513
#define MIN_AUTH_REQUEST_LEN 5
#define MAX_SOCKS_REQUEST_LEN 69
#define MIN_SOCKS_REQUEST_LEN 10
#define MAX_SOCKS_REPLY_LEN MAX_SOCKS_REQUEST_LEN
// Size
#define METHOD_REPLY_SIZE 2
#define AUTH_STATUS_SIZE 2
#define DGRAM_IPV4_SIZE 10
#define SOCKS_REPLY_SIZE_IPV4 MIN_SOCKS_REQUEST_LEN
// version identifier/method selection message
struct method_request {
uint8_t ver;
uint8_t nmethods;
uint8_t methods[];
};
// method selection message
struct method_reply {
uint8_t ver;
uint8_t method;
};
struct auth_request {
uint8_t ver;
uint8_t ulen;
uint8_t uname[];
};
struct auth_status {
uint8_t ver;
uint8_t status;
};
union dst_or_bnd {
struct {
in_addr_t addr;
in_port_t port;
} ipv4;
struct {
uint8_t len;
uint8_t str[];
} domain;
struct {
uint8_t addr[16];
in_port_t port;
} ipv6;
};
struct socks_request {
uint8_t ver;
uint8_t cmd;
uint8_t rsv;
uint8_t atyp;
union dst_or_bnd dst;
};
struct socks_reply {
uint8_t ver;
uint8_t rep;
uint8_t rsv;
uint8_t atyp;
union dst_or_bnd bnd;
};
struct datagram {
uint16_t rsv;
uint8_t frag;
uint8_t atyp;
union dst_or_bnd dst;
};
bool method_exists(struct method_request * method_req, uint8_t method);
void get_uname_passwd(struct auth_request * req, uint8_t * ulen, uint8_t ** uname, uint8_t * plen, uint8_t ** passwd);
in_addr_t get_dst_addr(union dst_or_bnd * dst, uint8_t atyp);
in_port_t get_dst_port(union dst_or_bnd * dst, uint8_t atyp);
uint8_t * get_payload(struct datagram * dgram, int buflen, int * len);
#endif /* __PROTO_H__ */