0

Usually, I could ask getaddrinfo for the address of google.com and it will do some DNS queries and finally return me the results.

But now I have a scenario where I want to avoid the DNS lookup but limit the functionality to reading /etc/hosts (or %SystemRoot%\system32\drivers\etc\hosts on Windows) and return an error if the requested entry wasn't found there.

Is there a way to force getaddrinfo (or any other function) to local operation? Or do I have to parse /etc/hosts by myself?

eckes
  • 64,417
  • 29
  • 168
  • 201

1 Answers1

0

For unix, that is configurable in /etc/nsswitch.conf (see hosts file seems to be ignored for discussion).

I don't recall a comparable capability with Windows, though.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105