blob: 1676c1bf4a9770c3fef416da6ff3df0ed170b592 (
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
|
#ifndef POTD_FORWARD_H
#define POTD_FORWARD_H 1
#include "socket.h"
struct forward_ctx;
typedef int (*init_cb) (struct forward_ctx *ctx);
typedef int (*on_listen_cb) (struct forward_ctx *ctx, const char *host,
const char *port);
typedef int (*on_shutdown_cb) (struct forward_ctx *ctx);
typedef struct fwd_callbacks {
on_listen_cb on_listen;
on_shutdown_cb on_shutdown;
} fwd_callbacks;
typedef enum forward_type {
FT_NONE = 0, FT_CLIENT, FT_SERVER
} forward_type;
typedef struct forward_ctx {
forward_type fwd_type;
fwd_callbacks fwd_cbs;
psocket sock;
char host_buf[NI_MAXHOST], service_buf[NI_MAXSERV];
void *data;
} forward_ctx;
int fwd_init_ctx(forward_ctx **ctx, init_cb init_fn);
int fwd_setup_client(forward_ctx *ctx, const char *host, const char *port);
int fwd_setup_server(forward_ctx *ctx, const char *listen_addr,
const char *listen_port);
int fwd_validate_ctx(const forward_ctx *ctx);
int fwd_connect_sock(forward_ctx *ctx, psocket *fwd_client);
int fwd_listen_sock(forward_ctx *ctx, psocket *fwd_server);
#endif
|