Add KEEPALIVE in TCP so clients can't fool us anymore. - bitreich-httpd - Bitreich HTTPD service
HTML git clone git://bitreich.org/bitreich-httpd git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/bitreich-httpd
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
DIR LICENSE
---
DIR commit 5dd0fad01a989756640fbf34f281dd1955ed6383
DIR parent e2069310e74b6847ed353161af40d5fc4b7fabc1
HTML Author: Christoph Lohmann <20h@r-36.net>
Date: Tue, 14 Oct 2025 22:37:47 +0200
Add KEEPALIVE in TCP so clients can't fool us anymore.
Diffstat:
M bitreich-httpd.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
---
DIR diff --git a/bitreich-httpd.c b/bitreich-httpd.c
@@ -187,7 +187,7 @@ main(int argc, char *argv[])
char *wwwbase, *wwwindex, *request, *ctype, *path, *le_file,
*le_base, clienth[NI_MAXHOST], clientp[NI_MAXSERV], *zuccbase,
*requested, *header, *headerval, *hosthdr;
- int rlen, i, user_agent_script_pid, isxfirefoxai;
+ int rlen, i, user_agent_script_pid, isxfirefoxai, flags;
struct sockaddr_storage clt;
socklen_t cltlen = sizeof(clt);
time_t tim;
@@ -201,6 +201,12 @@ main(int argc, char *argv[])
le_base = "/br/www/uacme";
zuccbase = "/br/www/zuccless";
+ /*
+ * Try to set keepalive in case we have some socket on stdin.
+ */
+ flags = 1;
+ setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
+
if (!getpeername(0, (struct sockaddr *)&clt, &cltlen)) {
if (getnameinfo((struct sockaddr *)&clt, cltlen, clienth,
sizeof(clienth), clientp, sizeof(clientp),