Non-blocking network address resolution (gethostbyname or getaddrinfo)?

Using the classic nsswitch.conf configuration:

hosts: files dns 

Trying to resolve the name using gethostbyname (or getaddrinfo ) may take some time if DNS is not responding (or is poorly configured).

Is there a way to set the timeout in nsswitch.conf or use an alternative api that controls the timeout?

+6
source share
1 answer

There is getaddrinfo_a , but it is Linux-specific GNU glibc. Alternatively, you can create a stream and call getaddrinfo. Do not use gethostbyname in a stream, as it is not thread safe .

+5
source

All Articles