mpromonet
mpromonet

Reputation: 11942

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

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

Answers (1)

Sjoerd
Sjoerd

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

Related Questions