Skip to content

Fix IP _resolve_hostname for Unix #106472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TheBlueOompaLoompa
Copy link

Fix the implementation of _resolve_hostname for the unix ip driver.
Can resolve .local domains now using mDNS.
Fixes #101453

@TheBlueOompaLoompa TheBlueOompaLoompa requested a review from a team as a code owner May 16, 2025 04:08
@TheBlueOompaLoompa TheBlueOompaLoompa changed the title Fix _resolve_hostname for unix Fix _resolve_hostname for unix May 16, 2025
@akien-mga akien-mga requested a review from a team May 16, 2025 09:36
@akien-mga akien-mga changed the title Fix _resolve_hostname for unix Fix IP _resolve_hostname for Unix May 16, 2025
@akien-mga akien-mga added this to the 4.5 milestone May 16, 2025
@akien-mga akien-mga removed the request for review from a team May 16, 2025 09:36
@akien-mga akien-mga added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label May 16, 2025
@akien-mga

This comment was marked as resolved.

@Faless
Copy link
Collaborator

Faless commented May 18, 2025

Is there any reference for the requirement of hints.ai_socktype = SOCK_STREAM; specific to mDNS?
The manual just claims:

This field specifies the preferred socket type, for example SOCK_STREAM or SOCK_DGRAM. Specifying 0 in this field indicates that socket addresses of any type can be returned by getaddrinfo().

And domain resolution is also used in functions that open UDP sockets. It's not clear to me why this would fix the issue when 0 is not working.

@TheBlueOompaLoompa
Copy link
Author

I specified hints.ai_socktype = SOCK_STREAM; initially because it was in an example. I built a test c++ project outside godot, and used the example from the manual.

You are correct that 0 works, and it might make sense to switch it to that. I tested it with just setting to 0 and it works just as well. I'm not sure what advantage any specific option would provide in this situation, or if it even matters at all.

I'm guessing the issue has to do with hints.ai_socktype technically being uninitialized, even though memset should have already set it to 0. I went in with a debugger to investigate, but hints.ai_socktypewas still 0 after getaddrinfo was called. At this point figuring it out would require stepping inside the getaddrinfo function, but that really doesn't seem like an option.

@Faless
Copy link
Collaborator

Faless commented May 19, 2025

I'm guessing the issue has to do with hints.ai_socktype technically being uninitialized, even though memset should have already set it to 0. I went in with a debugger to investigate, but hints.ai_socktypewas still 0 after getaddrinfo was called.

Well, this doesn't make much sense, if the value is properly zeroed by memset, setting it to 0 via the member won't change what's processed by getaddrinfo, so it must produce the same result.

In fact, I just tested resolving a .local domain with 4.4.1 stable and it's working fine for me (Debian 12 Bookworm)

Copy link
Collaborator

@Faless Faless left a comment

Choose a reason for hiding this comment

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

As per the discussion above, the SOCK_STREAM hint is incorrect, and it's not clear why explicitly setting it to 0 works for the OP since we already memset the whole struct to 0.

I've also not been able to reproduce the original issue in my network.

Further investigation and testing is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:network topic:porting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IP.resolve_hostname(_addresses) fails on .local addresses
3 participants