Skip to content

Conversation

@diridari
Copy link

Fill HostEntry with localhost and a default loopback address if 'getaddrinfo' returns 'WSANO_DATA'

return result;
}
#if defined(_WIN32)
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

#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

@obiltschnig
Copy link
Member

I don't think Poco should do any name resolution at all outside of that provided by the operating system's network stack.

@diridari
Copy link
Author

@obiltschnig i can not respond to you comment.
I agree with your statement, but in this case Linux and Windows do behave differently.
On linux systems 127.0.0.1 and localhost can be resolved on windows an exception is thrown. See #4988

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can not resolve "localhost" if not Network adapter exists

4 participants