Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Net/include/Poco/Net/HostEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class Net_API HostEntry
/// Creates the HostEntry from the data in an addrinfo structure.
#endif

#if defined(POCO_VXWORKS)
HostEntry(const std::string& name, const IPAddress& addr);
#endif
/// Creates the HostEntry from pre defined data


HostEntry(const HostEntry& entry);
/// Creates the HostEntry by copying another one.
Expand Down
18 changes: 17 additions & 1 deletion Net/src/DNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "Poco/Unicode.h"
#include <cstring>


#if defined(POCO_HAVE_LIBRESOLV)
#include <resolv.h>
#endif
Expand Down Expand Up @@ -83,6 +82,16 @@ HostEntry DNS::hostByName(const std::string& hostname, unsigned
freeaddrinfo(pAI);
return result;
}
#if defined(POCO_OS_FAMILY_WINDOWS)
else if(rc == WSANO_DATA && hostname == "localhost") // no data record found and is local host
{
#if defined(POCO_HAVE_IPv6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to default to IPv6 solely based on it being present on the system where poco was compiled. Not even the presence of IPv6 on the runtime system would warrant it being default, given the prevalence of IPv4.

Bottom line, I would prefer this to be decided at runtime, based on an additional function argument, defaulting to IPv4.

Copy link
Author

@diridari diridari Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aleks-f Since this is an edge case i am not sure if a addition argument wouldn't confuse users.
Does an function exists, that determines if ipv6 is available?
Otherwise i would use 127.0.0.1

return HostEntry("localhost", Poco::Net::IPAddress("::1"));
#else
return HostEntry("localhost",Poco::Net::IPAddress("127.0.0.1"));
#endif // ipv6
}
#endif // _WIN32
else
{
aierror(rc, hostname);
Expand Down Expand Up @@ -132,6 +141,13 @@ HostEntry DNS::hostByAddress(const IPAddress& address, unsigned
freeaddrinfo(pAI);
return result;
}
#if defined(POCO_OS_FAMILY_WINDOWS)
else if(rc == WSANO_DATA && address.isLoopback()) // no data record found and is local host
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense putting this condition first, before checking the "localhost" hostname?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would say checking the rc value is much cheaper than checking for localhost or loopback and is less common.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologise for not being clear enough.

In line 86 (above) it is first checked if the hostname is localhost and if that is not true then in line 145 is is checked if the device is a loopback.

From the logic point of view, what shall be the order? localhost first of loopback first? Or it does not matter?

Copy link
Author

@diridari diridari Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matejk Those are different methods:
First is 'DNS::hostByName()' line 63-114, second is 'DNS::hostByAddress' from line 117-176

{
return HostEntry("localhost", address);
}
#endif // _WIN32

else
{
aierror(rc, address.toString());
Expand Down
4 changes: 0 additions & 4 deletions Net/src/HostEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ HostEntry::HostEntry(struct addrinfo* ainfo)
#endif // POCO_HAVE_IPv6


#if defined(POCO_VXWORKS)


HostEntry::HostEntry(const std::string& name, const IPAddress& addr):
_name(name)
Expand All @@ -113,8 +111,6 @@ HostEntry::HostEntry(const std::string& name, const IPAddress& addr):
}


#endif // POCO_VXWORKS


HostEntry::HostEntry(const HostEntry& entry):
_name(entry._name),
Expand Down
Loading