Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions redir.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <netinet/tcp.h>

#ifdef USE_TCP_WRAPPERS
#include <tcpd.h>
Expand Down Expand Up @@ -977,6 +978,19 @@ static int server_socket(char *addr, int port, int fail)
exit(1);
}

/* Enable TCP keepalive to detect broken connections */
int keepalive = 1;
rc = setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive));
if (rc != 0) {
if (fail) {
close(sd);
return -1;
}

ERR("Failed setting socket option SO_KEEPALIVE: %s", strerror(errno));
exit(1);
}
DBG("TCP keepalive enabled using system defaults");
/*
* Try to bind the address to the socket.
*/
Expand Down