tor_multipath_voip/src/socks5.h

115 lines
2 KiB
C
Raw Normal View History

2019-02-08 16:37:02 +00:00
#pragma once
2019-02-08 13:28:39 +00:00
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <string.h>
#include "net_tools.h"
2019-03-21 12:01:48 +00:00
#include "evt_core.h"
2019-02-08 13:28:39 +00:00
2019-02-15 14:45:56 +00:00
enum socks5_state {
SOCKS5_STATE_NEW,
SOCKS5_STATE_ACK,
SOCKS5_STATE_RDY,
SOCKS5_STATE_ERR
};
2019-02-08 13:28:39 +00:00
enum cmd {
CMD_CONNECT = 0x01,
CMD_BIND = 0x02,
CMD_UDP_ASSOCIATE = 0x03
};
enum atyp {
ATYP_IPV4 = 0x01,
ATYP_DOMAINNAME = 0x03,
ATYP_IPV6 = 0x04
};
2019-03-21 17:43:38 +00:00
enum ver {
VER_SOCKS5 = 0x05
};
enum methods {
METHOD_NOAUTH = 0x00,
METHOD_GSSAPI = 0x01,
METHOD_USERPASS = 0x02,
METHOD_NOACCEPT = 0xff
};
2019-02-08 13:28:39 +00:00
union socks5_addr {
struct {
uint8_t len;
char* str;
} dns;
uint8_t ipv4[4];
uint8_t ipv6[16];
};
enum socks5_rep {
SOCKS5_REP_SUCCESS,
SOCKS5_REP_GENERAL_FAILURE,
SOCKS5_REP_CONOTALLOWED,
SOCKS5_REP_NETUNREACH,
SOCKS5_REP_HOSTUNREACH,
SOCKS5_REP_COREFUSED,
SOCKS5_REP_TTLEXP,
SOCKS5_REP_CMDNOTSUP,
SOCKS5_REP_ADDRNOTSUP
};
2019-02-13 14:32:38 +00:00
static char* rep_msg[] = {
2019-02-12 20:45:15 +00:00
"Succeeded",
"General SOCKS server failure",
"Connection not allowed by ruleset",
"Network unreachable",
"Host unreachable",
"Connection refused",
"TTL expired",
"Command not supported",
"Address type not supported"
};
2019-02-08 13:28:39 +00:00
/*
* RFC 1928 Messages
* https://tools.ietf.org/html/rfc1928
*/
struct client_handshake {
uint8_t ver;
uint8_t nmethods;
uint8_t methods[255];
};
struct server_handshake {
uint8_t ver;
uint8_t method;
};
struct client_request {
uint8_t ver;
uint8_t cmd;
uint8_t rsv;
uint8_t atyp;
uint8_t dst_addr_len;
char* dst_addr;
uint16_t port;
};
struct server_reply {
uint8_t ver;
uint8_t rep;
uint8_t rsv;
uint8_t atyp;
union socks5_addr bind_addr;
uint16_t port;
};
2019-03-21 12:01:48 +00:00
int socks5_handshake_syn(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo);
2019-02-15 14:45:56 +00:00
int socks5_handshake_ack(int sock);
2019-02-12 20:45:15 +00:00
int socks5_connect_dns(int sock, char* addr, uint16_t port);
int socks5_reply(int sock);
char* socks5_rep (enum socks5_rep rep);