-
Notifications
You must be signed in to change notification settings - Fork 1
/
relay.h
57 lines (43 loc) · 1.24 KB
/
relay.h
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
#ifndef RELAY_H
#define RELAY_H
#include <stdbool.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "config.h"
#include "clist.h"
typedef struct _relay_t relay_t;
typedef struct _queue_t queue_t;
typedef union {
struct sockaddr sa;
struct sockaddr_storage _storage;
} sockaddr_t;
struct _relay_t {
int fd;
sockaddr_t remote_sa;
socklen_t remote_sa_len;
char remote_sa_buf[INET6_ADDRSTRLEN];
/* Update remote_sa on every incoming packet with its source address */
bool dynamic_out_addr;
char *local_addr;
char *remote_addr;
queue_t *queue;
/* Reusable buffer for 1st item in send queue */
void *send_buffer;
size_t send_buffer_size;
size_t send_size;
/* Receive buffer */
void *recv_buffer;
size_t recv_size;
relay_t *_prev;
relay_t *_next;
};
relay_t *new_relay(const relay_config_t *config);
void free_relay(relay_t *relay);
ssize_t relay_enqueue(relay_t *relay, const void *buffer, size_t length);
ssize_t relay_receive(relay_t *relay, void **buffer);
int relay_handle(relay_t *relay, const fd_set *rfds, const fd_set *wfds);
void relay_fd_set(relay_t *relay, fd_set *rfds, fd_set *wfds);
#endif