Skip to content

Commit

Permalink
Properly handle unknown "localhost" in DVPSIPCClient.
Browse files Browse the repository at this point in the history
The request to resolve the hostname "localhost" to an IPv4 address
may fail under certain circumstances (e.g. in a IPv6 only environment).
This situation is now handled properly.

Thanks to Oliver Klerx <[email protected]> for the bug report and patch.
  • Loading branch information
eichelberg committed Dec 18, 2024
1 parent 28a6e30 commit 2e1b34b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dcmpstat/libsrc/dvpsmsg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,18 @@ void DVPSIPCClient::requestConnection()
{
if (connection) return; // connection already open

OFSockAddr server;
OFStandard::getAddressByHostname("localhost", AF_INET, server);
if (server.size() == 0) return;

#ifdef _WIN32
SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET) return;
#else
int s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) return;
#endif
OFSockAddr server;
OFStandard::getAddressByHostname("localhost", AF_INET, server);

server.setPort(OFstatic_cast(unsigned short, htons(OFstatic_cast(unsigned short, port))));

if (connect(s, server.getSockaddr(), server.size()) < 0)
Expand Down

0 comments on commit 2e1b34b

Please sign in to comment.