From ca46c321915798818d6716fb5c2be9f538f2e722 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Thu, 11 Jun 2020 12:29:43 +0200 Subject: Add some socket options to minecraft protocol sockets --- server.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'server.c') diff --git a/server.c b/server.c index 0298491..3cc2398 100644 --- a/server.c +++ b/server.c @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include "main.h" #include "uring.h" @@ -212,7 +215,7 @@ static bool server_local_open(struct cfg *cfg, struct server *scfg, struct server_local *local) { int sfd; - int enable = 1; + int option; int r; sfd = socket(local->addr.storage.ss_family, SOCK_STREAM | SOCK_CLOEXEC, 0); @@ -221,11 +224,25 @@ server_local_open(struct cfg *cfg, struct server *scfg, struct server_local *loc goto out; } - if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) { + option = true; + if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) < 0) { perror("setsockopt"); goto out; } + /* The MC protocol expects the client to send data first */ + /* FIXME: could make this configurable */ + option = true; + if (setsockopt(sfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &option, sizeof(option)) < 0) + perror("setsockopt"); + + /* FIXME: could make this configurable */ + option = true; + if (setsockopt(sfd, IPPROTO_IP, IP_FREEBIND, &option, sizeof(option)) < 0) + perror("setsockopt"); + + socket_set_gaming_options(cfg, sfd); + r = bind(sfd, (struct sockaddr *)&local->addr.storage, local->addr.addrlen); if (r < 0) { perror("bind"); -- cgit v1.2.3