1 /*
2  *  tcpproxy
3  *
4  *  tcpproxy is a simple tcp connection proxy which combines the
5  *  features of rinetd and 6tunnel. tcpproxy supports IPv4 and
6  *  IPv6 and also supports connections from IPv6 to IPv4
7  *  endpoints and vice versa.
8  *
9  *
10  *  Copyright (C) 2010-2015 Christian Pointner <equinox@spreadspace.org>
11  *
12  *  This file is part of tcpproxy.
13  *
14  *  tcpproxy is free software: you can redistribute it and/or modify
15  *  it under the terms of the GNU General Public License as published by
16  *  the Free Software Foundation, either version 3 of the License, or
17  *  any later version.
18  *
19  *  tcpproxy is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *  GNU General Public License for more details.
23  *
24  *  You should have received a copy of the GNU General Public License
25  *  along with tcpproxy. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef TCPPROXY_listener_h_INCLUDED
29 #define TCPPROXY_listener_h_INCLUDED
30 
31 #include <sys/select.h>
32 
33 #include "slist.h"
34 #include "tcp.h"
35 #include "clients.h"
36 
37 enum listener_state_enum { NEW, ACTIVE, ZOMBIE };
38 typedef enum listener_state_enum listener_state_t;
39 
40 typedef struct {
41   int fd_;
42   tcp_endpoint_t local_end_;
43   tcp_endpoint_t remote_end_;
44   tcp_endpoint_t source_end_;
45   listener_state_t state_;
46 } listener_t;
47 
48 void listeners_delete_element(void* e);
49 
50 typedef slist_t listeners_t;
51 
52 int listeners_init(listeners_t* list);
53 void listeners_clear(listeners_t* list);
54 int listeners_add(listeners_t* list, const char* laddr, resolv_type_t lrt, const char* lport, const char* raddr, resolv_type_t rrt, const char* rport, const char* saddr);
55 int listeners_update(listeners_t* list);
56 void listeners_revert(listeners_t* list);
57 void listeners_remove(listeners_t* list, int fd);
58 listener_t* listeners_find(listeners_t* list, int fd);
59 void listeners_print(listeners_t* list);
60 
61 void listeners_read_fds(listeners_t* list, fd_set* set, int* max_fd);
62 int listeners_handle_accept(listeners_t* list, clients_t* clients, fd_set* set);
63 
64 #endif
65