Should SocketAddress.makeAddressResolvingHost use GetaddrinfoResolver?

I'm trying to gather both IPv4 and IPv6 addresses for a hostname and I noticed that SocketAddress.makeAddressResolvingHost only returns the first result in the linked list returned by getaddrinfo. However GetaddrinfoResolver appears to handle the linked list properly, but sadly it is marked internal.

Anyway it seems like SocketAddress.makeAddressResolvingHost should either wrap GetaddrinfoResolver and return a list of SocketAddresses or maybe GetaddrinfoResolver should be marked public.

This is largely intentional: at this time we are reluctant to expose substantial DNS resolution infrastructure. This is largely because getaddrinfo’s blocking nature make it very hard to use. We want to push people away from doing DNS resolution themselves and towards allowing the framework to do it for them, so that we can migrate the ecosystem onto non-blocking resolvers as that becomes possible.

In my ideal world we’d actually deprecate makeAddressResolvingHost.

Understood. In that case how would you recommend I resolve hostnames into SocketAddresses for use with UDP? Ideally I would like both the ipv4 and ipv6 addresses.

Why do you need to resolve them?

Because AddressedEnvelope needs a SocketAddress

Ah, yeah, ok. In that case, for now I recommend extracting the code from NIO that operates on getaddrinfo into your own package and using that.

In the next few weeks/months I have a plan to update the Resolver interface in NIO to better allow more complex forms of service discovery and to adapt to a streaming interface. When we do that, we can also look at investing time into building out DNS resolution APIs that take advantage of better technologies. At a minimum I’d like to take advantage of asynchronous resolvers such as C-ARES, but ideally we’d be adopting things like the dns-sd API instead which provide a richer experience.

1 Like

Once that new Resolver interface is in place I think the SSWG should consider taking point on building this out.

Sounds good. That's where I landed yesterday, so now I'm able to get both address families even if it's a bit dirty.

Cool - I will keep my eyes open for these developments then. Thanks for your help here.