summaryrefslogtreecommitdiffstats
path: root/src/net-proxy.h
blob: 27d7124cadca4db764c67b62e2de925ce98198e3 (plain)
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

#ifndef NET_PROXY_H
#define NET_PROXY_H

#include <sys/select.h>
#include <arpa/inet.h>

#include "trans.h"

#define TSNIF_NP_PORT (5555)
enum {
	TSNIF_NP_UDP_CLIENT = 0x1,
	TSNIF_NP_UDP_SERVER = 0x2,
	TSNIF_NP_TCP_CLIENT = 0x4,
	TSNIF_NP_TCP_SERVER = 0x8,
};

enum {
	TSNIF_NP_PROT_UDP,
	TSNIF_NP_PROT_TCP,
	TSNIF_NP_PROT_MAX,
};

#define TSNIF_NP_CLIENT (TSNIF_NP_UDP_CLIENT | TSNIF_NP_TCP_CLIENT)
#define TSNIF_NP_SERVER (TSNIF_NP_UDP_SERVER | TSNIF_NP_TCP_SERVER)
#define TSNIF_NP_UDP (TSNIF_NP_UDP_CLIENT | TSNIF_NP_UDP_SERVER)
#define TSNIF_NP_TCP (TSNIF_NP_TCP_CLIENT | TSNIF_NP_TCP_SERVER)

struct tsnif_np_args {
	char *host;
	int port;
	int flags;
};

struct tsnif_udp_client {
	struct tsnif_term *term;
	struct sockaddr_in sa;
	int connected;
};

struct tsnif_np_handle {
	/* udp properties */
	int fd_udp;
	struct tsnif_udp_client udp_client;

	/* tcp properties */
	int fd_tcp;

	int flags;
};

struct tsnif_np_msg {
	struct trans_msg msg;
	char data[0];
};

struct tsnif_handle;

typedef int(*init_server_t)(struct tsnif_handle*, struct tsnif_np_args *args);
typedef int(*init_client_t)(struct tsnif_handle*, struct tsnif_np_args *args);
typedef int(*close_t)(struct tsnif_handle*);
typedef int(*send_t)(struct tsnif_handle*, struct trans_msg *msg);
typedef int(*process_t)(struct tsnif_handle*);

struct tsnif_np_prot {
	init_server_t init_server;
	init_client_t init_client;
	close_t close;
	send_t send;
	process_t process;
};

int tsnif_np_init(struct tsnif_handle *h, struct tsnif_np_args *np);
int tsnif_np_fd(struct tsnif_handle *h, fd_set *set);
int tsnif_np_process(struct tsnif_handle *h, fd_set *set);
int tsnif_np_close(struct tsnif_handle *h);
int tsnif_np_send_client(struct tsnif_handle *h, struct trans_msg *msg);
int tsnif_np_send_server(struct tsnif_handle *h, struct trans_msg *msg);
void tsnif_np_args(struct tsnif_np_args *args, int flag, char *host);
int tsnif_np_dispatch(struct tsnif_handle *h, struct trans_msg *msg);

#endif /* NET_PROXY_H */