From 5ed8ac4a3eac18fbba0962f05d2110e64564e09f Mon Sep 17 00:00:00 2001 From: Marcell Leleszi Date: Sat, 15 Jun 2024 10:41:14 +0200 Subject: [PATCH] Some networking code cleanup --- src/tcp_server.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tcp_server.cpp b/src/tcp_server.cpp index d65da50..2cf9c11 100644 --- a/src/tcp_server.cpp +++ b/src/tcp_server.cpp @@ -28,7 +28,12 @@ TCPServer::TCPServer() : controller{} { [[noreturn]] void TCPServer::start(const std::string &address = "0.0.0.0", int port = 6379) { struct sockaddr_in server_addr {}; server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = INADDR_ANY;// TODO: set address + + if (address == "0.0.0.0") { + server_addr.sin_addr.s_addr = INADDR_ANY; + } else { + inet_pton(AF_INET, address.c_str(), &server_addr.sin_addr); + } server_addr.sin_port = htons(port); if (bind(m_serverFD, (struct sockaddr *) &server_addr, sizeof(server_addr)) != 0) {