summaryrefslogtreecommitdiff
path: root/main.h
diff options
context:
space:
mode:
authorGDR! <gdr@go2.pl>2014-11-16 03:54:56 +0100
committerGDR! <gdr@go2.pl>2014-11-16 03:54:56 +0100
commitc311fb3bdd2c26c347c2dd734f97003ac0538037 (patch)
tree09ec99c8722049f77b08db307e8a5388aa7cb029 /main.h
parent9b523f2b826dea54613f2eac78f754c9772841b6 (diff)
TCP works, yay
Diffstat (limited to 'main.h')
-rw-r--r--main.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/main.h b/main.h
new file mode 100644
index 0000000..4f2187d
--- /dev/null
+++ b/main.h
@@ -0,0 +1,85 @@
1#ifndef _MAIN_H
2#define _MAIN_H
3
4#include <arpa/inet.h>
5#include <errno.h>
6#include <netdb.h>
7#include <netinet/in.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <sys/socket.h>
12#include <sys/time.h>
13#include <sys/types.h>
14#include <time.h>
15#include <tox/tox.h>
16#include <unistd.h>
17
18#include "util.h"
19#include "uthash.h"
20
21#define READ_BUFFER_SIZE 1024
22
23#define PROTOCOL_MAGIC_V1 0xa26a
24#define PROTOCOL_MAGIC PROTOCOL_MAGIC_V1
25#define PROTOCOL_MAGIC_HIGH (PROTOCOL_MAGIC >> 8)
26#define PROTOCOL_MAGIC_LOW (PROTOCOL_MAGIC & 0xff)
27#define PACKET_TYPE_PONG 0x0100
28#define PACKET_TYPE_PING 0x0108
29#define PACKET_TYPE_REQUESTTUNNEL 0x0602
30#define PACKET_TYPE_ACKTUNNEL 0x0610
31#define PACKET_TYPE_TCP 0x0600
32#define PACKET_TYPE_TCP_FIN 0x0601
33
34#define INT16_AT(array,pos) ( (*((array)+(pos)))*256 + (*((array)+(pos)+1)) )
35#define BYTE2(number) (((number) / 256) & 0xff)
36#define BYTE1(number) ((number)&0xff)
37
38/* Offset of the data buffer in the packet */
39#define PROTOCOL_BUFFER_OFFSET 8
40#define PROTOCOL_MAX_PACKET_SIZE (READ_BUFFER_SIZE + PROTOCOL_BUFFER_OFFSET)
41
42typedef struct tunnel_t {
43 /* The forwarded socket fd */
44 int sockfd;
45 /* Connection ID, must be int because of uthash */
46 int connid;
47 /* Friend number of remote end */
48 int32_t friendnumber;
49
50 UT_hash_handle hh;
51} tunnel;
52
53typedef struct protocol_frame_t {
54 uint32_t friendnumber;
55
56 /* Fields actually found in the protocol */
57 uint16_t magic;
58 uint16_t packet_type;
59 uint16_t connid;
60 uint16_t data_length;
61 const uint8_t *data;
62} protocol_frame;
63
64
65/**** GLOBAL VARIABLES ****/
66extern Tox *tox;
67/* Whether we're a client */
68extern int client_mode;
69/* Just send a ping and exit */
70extern int ping_mode;
71/* Open a local port and forward it */
72extern int client_local_port_mode;
73/* Forward stdin/stdout to remote machine - SSH ProxyCommand mode */
74extern int client_pipe_mode;
75/* Remote Tox ID in client mode */
76extern char *remote_tox_id;
77/* Ports and hostname for port forwarding */
78extern int remote_port;
79extern char *remote_host;
80extern int local_port;
81
82extern int select_nfds;
83
84int parse_lossless_packet(void *sender_uc, const uint8_t *data, uint32_t len);
85#endif