From e3f72b4d227d438cb66df91304ff24700be5e0d0 Mon Sep 17 00:00:00 2001
From: Benny Baumann <BenBE@geshi.org>
Date: Sun, 19 Feb 2023 22:15:31 +0100
Subject: [PATCH] chg: Handle all protocol variants for incoming client
 connections

---
 src/net/tcp_server_socket.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/net/tcp_server_socket.cpp b/src/net/tcp_server_socket.cpp
index 461028a..e938ac5 100644
--- a/src/net/tcp_server_socket.cpp
+++ b/src/net/tcp_server_socket.cpp
@@ -97,9 +97,10 @@ void tcp_server_socket::await_raw_socket_incomming(
 ) {
     MARK_UNUSED(ass);
 
-    struct sockaddr_in client_addr;
+    struct sockaddr_storage client_addr;
     socklen_t client_len = sizeof(client_addr);
     int client_fd_raw = accept(socket.get(), (struct sockaddr*)&client_addr, &client_len);
+    socketaddr address{client_addr};
 
     if (client_fd_raw < 0) {
         throw netio_exception("Unable to bind incoming client");
@@ -113,9 +114,6 @@ void tcp_server_socket::await_raw_socket_incomming(
         throw netio_exception("Failed to set socket mode. fcntl resulted in error:" + std::to_string(errno));
     }
 
-    const std::string address = inet_ntoa(client_addr.sin_addr);
-    const uint16_t port = ntohs(client_addr.sin_port);
-
     // Generate client object from fd and announce it
     this->number_of_connected_clients++;
     using namespace std::placeholders;
@@ -129,10 +127,10 @@ void tcp_server_socket::await_raw_socket_incomming(
     }
 
     if (this->max_number_of_simulataneusly_allowed_clients == 0 || this->get_number_of_connected_clients() <= this->max_number_of_simulataneusly_allowed_clients) {
-        this->client_listener(tcp_client(std::bind(&tcp_server_socket::client_destructed_cb, this, _1), auto_fd(client_fd_raw), address, port));
+        this->client_listener(tcp_client(std::bind(&tcp_server_socket::client_destructed_cb, this, _1), auto_fd(client_fd_raw), address));
     } else {
         if (this->overflow_client_listener != nullptr) {
-            this->overflow_client_listener(tcp_client(std::bind(&tcp_server_socket::client_destructed_cb, this, _1), auto_fd(client_fd_raw), address, port));
+            this->overflow_client_listener(tcp_client(std::bind(&tcp_server_socket::client_destructed_cb, this, _1), auto_fd(client_fd_raw), address));
         }
     }
 }
-- 
GitLab