fix: smarter host IP determination for mDNS #38
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Serving
.local
aliases over mDNS requires broadcasting the IP address of the host machine, so that other devices on the network can connect to it. Previous to this PR, localias would do lookups by trying to lookup{hostname}.local
. As reported in #34, and previously in #20 and #21, this had a variety of issues and did not work consistently.This PR attemtps to fix this problem once and for all by finding the host's IP by iterating through the network interfaces and looking for non-loopback IPV4 addresses. I tested that this fixes the problem reported in #34 by manually setting my hostname to
something.fritz.box
, seeing thatlocalias
would fail to determine the IP address, then running this code and seeing that it worked correctly.In addition to the IPV4 addresses that are found, this code also broadcasts
127.0.0.1
and::1
so that DNS requests on macOS respond instantly. For some reason, if an IPV6 address is not included in the mDNS response, runningcurl myhost.local
will always have a 5-6 second delay on macOS. I can't explain it but I have a workaround.