From 6eac5cb704db3b56f35417c2816d749cef1ffcae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 14:47:53 +0000 Subject: [PATCH] Fix IPv4 socket binding on non-Windows systems The IPv4 binding code was incorrectly wrapped in #ifdef _WIN32, causing the server to fall through to IPv6 binding even when IPv4 was explicitly requested with the -4 flag on Linux systems. This fix removes the Windows- specific conditional around the IPv4 binding logic while keeping platform- specific socket close calls. Fixes the issue where pcm-sensor-server with -4 flag would fail to accept connections from curl and wget on Linux. Co-authored-by: rdementi <25432609+rdementi@users.noreply.github.com> --- src/pcm-sensor-server.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pcm-sensor-server.cpp b/src/pcm-sensor-server.cpp index febbf2a1..b060d16b 100644 --- a/src/pcm-sensor-server.cpp +++ b/src/pcm-sensor-server.cpp @@ -1467,7 +1467,6 @@ class Server { int retval = 0; if (useIPv4) { -#ifdef _WIN32 // Use IPv4 struct sockaddr_in serv4; memset(&serv4, 0, sizeof(serv4)); @@ -1479,13 +1478,16 @@ class Server { if ( 1 != ::inet_pton( AF_INET, listenIP_.c_str(), &(serv4.sin_addr) ) ) { DBG( 3, "close clientsocketFD" ); +#ifdef _WIN32 + closesocket(sockfd); +#else ::close(sockfd); +#endif throw std::runtime_error(std::string("Server Constructor: Cannot convert IP string ") + listenIP_ + " to IPv4 address"); } } socklen_t len = sizeof( struct sockaddr_in ); retval = ::bind( sockfd, reinterpret_cast(&serv4), len ); -#endif } else { // Use IPv6 struct sockaddr_in6 serv;