Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 720
mpromonet Avatar asked Feb 25 '14 11:02

mpromonet


Video Answer


1 Answers

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.

like image 148
Sjoerd Avatar answered Oct 29 '22 04:10

Sjoerd