-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocks5.c
More file actions
38 lines (26 loc) · 936 Bytes
/
socks5.c
File metadata and controls
38 lines (26 loc) · 936 Bytes
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
#include "socks5.h"
int socks5_connect(proxy_client_t *client)
{
char buf[16];
char *buf_p;
//step 1
buf_p = buf;
*buf_p++=0x05; //version
*buf_p++=0x01; //command
*buf_p++=0x00; //0
if(write(client->fd,buf,buf_p-buf) <= 0) return 1;
if(read(client->fd,buf,sizeof(buf)) <= 0) return 1;
if(buf[0] != 0x05 || buf[1] == 0xFF) return 1;
//step 2
buf_p=buf;
*buf_p++=0x05; //version
*buf_p++=0x01; //command
*buf_p++=0x00; //0
*buf_p++=0x01; //address type
memcpy(buf_p,&client->dest_addr,sizeof(client->dest_addr)); buf_p+=sizeof(client->dest_addr); //destination addr
memcpy(buf_p,&client->dest_port,sizeof(client->dest_port)); buf_p+=sizeof(client->dest_port); //destination port
if(write(client->fd,buf,buf_p-buf) <= 0) return 1;
if(read(client->fd,buf,sizeof(buf)) <= 0) return 1;
if(buf[0] != 0x05 || buf[1] != 0x00) return 1;
return 0;
}