Automatically determine what address to advertise, per-interface #180
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.
This is a rather large change, but it solves a fairly big usability issue.
If you have multiple interfaces, manually supplying a list of IPs isn't enough, as we do not want to advertise the WiFi IP to the Ethernet interface, etc.
Even allowing per-interface lists of IPs causes trouble, as IP addresses can change, and one would have to track that manually.
Besides that, it's nontrivial to get your own addresses if you don't already have it, and having to add a dozen lines or so for something so common seems wasteful.
My proposed solution is to allow None as an address, which is automatically replaced with the IP of whatever device the packet is being sent from. To do this I have bound all the sockets to the individual devices(Other than the listen socket), so that we can send multicasts to specific interfaces.
This causes another problem, in that relying on per-device sockets gets messy when things are dynamic. I resolve this problem by recreating the sockets if the list of interfaces changes. To do this I poll every 3 minutes, but I also refresh the list and retry if a send fails.
This patch has a slight performance hit I'd imagine, because every response now requires "recompiling" the response packet bytes, but MDNS isn't exactly a high datarate application as it is.
Thanks for your time!!