Servus icon indicating copy to clipboard operation
Servus copied to clipboard

using DNSServiceGetAddrInfo to resolve IP address from hostname (with interface specification)

Open benkuper opened this issue 5 years ago • 1 comments

Hello, I've been using getaddrinfo() to resolve IP from hostname, but the problem is that getaddrinfo() doesn't allow for specifying a network interface, and multiple devices with same hostname on different interfaces will not work with this method. I couldn't find a generic method to work around this problem, except implementing the Bonjour / Avahi API. DNSServiceGetAddrInfo allows to do that and it would make the library very powerful and complete to have that inside, especially since Bonjour and Avahi already have those methods ready to use.

I have tried myself but the callback of DNSServiceGetAddrInfo was never triggered, I'm not sure why but if someone has more insight on this this would be great !a

benkuper avatar Oct 16 '20 08:10 benkuper

Just for info, I forked and added the piece of code to include servus_port and servus_ip in the data. This is only in the dns-sd implementation, and JM Celerier has made the same for the avahi implementation. Mine is quite dirty so I'm not making a PR for that but there is everything needed to do some proper, complete system for full-info retrieval which would make this library waaaay more useful than only getting the hostname.

https://github.com/benkuper/Servus/commit/fbe6ab4b85ba051e43e51ac3263fa6eeebb7335f#diff-b1586d4d2cda7428bff40ee9f7b7493b6079b60de0fba03e0ea3349aff3e3bf5

Cheers

benkuper avatar Oct 19 '20 15:10 benkuper