Skip to content

2.1.0+commit.fcaac03

Compare
Choose a tag to compare
@github-actions github-actions released this 19 Sep 19:59
· 2 commits to main since this release
fcaac03
fix: smarter host IP determination for mDNS (#38)

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
https://github.com/peterldowns/localias/issues/34, and previously in
https://github.com/peterldowns/localias/issues/20 and
https://github.com/peterldowns/localias/issues/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 that `localias` 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, running `curl myhost.local` will always have a 5-6 second
delay on macOS. I can't explain it but I have a workaround.