Search code examples
csocketsnetwork-programminggetaddrinfo

how can I make getaddrinfo return only one result?


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.


Solution

  • 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.