Reputation: 11942
Using a classic nsswitch.conf configuration :
hosts: files dns
Trying to resolve a name using gethostbyname (or getaddrinfo) could take a while if the DNS does not answer (or is badly configured).
Is there a way to configure a timeout in nsswitch.conf or use an alternative api that manage a timeout ?
Upvotes: 8
Views: 11539
Reputation: 75619
There is getaddrinfo_a, but it is Linux-specific GNU glibc specific. Alternatively, you can spawn a thread and call getaddrinfo in it. Don't use gethostbyname in a thread, as it is not thread-safe.
Upvotes: 9