Question

I want to use getaddrinfo() but get only the first result.

more specifically, I want the function to first scan the hosts file and fetch the first result found, and only if not found in hosts I want to query the dns server.

is it possible?

thanks.

Was it helpful?

Solution 2

The order on how resolving hosts is done is define in /etc/host.conf using the keyword order:

order

This keyword specifies how host lookups are to be performed. It should be followed by one or more lookup methods, separated by commas. Valid methods are bind, hosts, and nis.

However I doubt you can restrict the number of results to 1 per this configuration directly.

OTHER TIPS

You can't. It behaves as documented. You only have to use one result: that's up to you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top