-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocks4.c
24 lines (17 loc) · 916 Bytes
/
socks4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "socks4.h"
int socks4_connect(proxy_client_t *client)
{
char buf[16];
char *buf_p=buf;
*buf_p++ = 0x04; //version
*buf_p++ = 0x01; //command
memcpy(buf_p,&client->dest_port,sizeof(client->dest_port)); buf_p+=sizeof(client->dest_port); //port
memcpy(buf_p,&client->dest_addr,sizeof(client->dest_addr)); buf_p+=sizeof(client->dest_addr); //address
*buf_p++ = 0x00;
//send request
if(write(client->fd,buf,buf_p-buf) <= 0) { log_debug("socks4 write <= 0"); return 1; }
//receive response
if(read(client->fd,buf,sizeof(buf)) <= 0) { log_debug("socks4 read <= 0"); return 1; }
if(buf[0] != 0x00 || buf[1] < 0x5A || buf[1] > 0x5E) { log_debug("socks4 recv is not valid"); return 1; }
return 0;
}