1
0
mirror of https://github.com/moparisthebest/sslh synced 2024-11-24 10:02:16 -05:00

set IP_FREEBIND if available to bind to non-existent interfaces

This commit is contained in:
Yves Rutschle 2014-02-09 13:29:49 +01:00
parent 5998c9ec1a
commit 67c34a7460
3 changed files with 16 additions and 4 deletions

View File

@ -10,6 +10,9 @@ vNEXT:
actual errors if connections are dropped before
getting to getpeername).
Set IP_FREEDBIND if available to bind to addresses
that don't yet exist.
v1.15: 27JUL2013
Added --transparent option for transparent proxying.
See README for iptables magic and capability

View File

@ -62,7 +62,7 @@ int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list)
{
struct sockaddr_storage *saddr;
struct addrinfo *addr;
int i, res, reuse;
int i, res, one;
int num_addr = 0;
for (addr = addr_list; addr; addr = addr->ai_next)
@ -83,9 +83,14 @@ int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list)
(*sockfd)[i] = socket(saddr->ss_family, SOCK_STREAM, 0);
check_res_dumpdie((*sockfd)[i], addr, "socket");
reuse = 1;
res = setsockopt((*sockfd)[i], SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse));
check_res_dumpdie(res, addr, "setsockopt");
one = 1;
res = setsockopt((*sockfd)[i], SOL_SOCKET, SO_REUSEADDR, (char*)&one, sizeof(one));
check_res_dumpdie(res, addr, "setsockopt(SO_REUSEADDR)");
if (IP_FREEBIND) {
res = setsockopt((*sockfd)[i], IPPROTO_IP, IP_FREEBIND, (char*)&one, sizeof(one));
check_res_dumpdie(res, addr, "setsockopt(IP_FREEBIND)");
}
res = bind((*sockfd)[i], addr->ai_addr, addr->ai_addrlen);
check_res_dumpdie(res, addr, "bind");

View File

@ -49,6 +49,10 @@
#define TRACE
#endif
#ifndef IP_FREEBIND
#define IP_FREEBIND 0
#endif
enum connection_state {
ST_PROBING=1, /* Waiting for timeout to find where to forward */
ST_SHOVELING /* Connexion is established */