aboutsummaryrefslogtreecommitdiff
path: root/sethostent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sethostent.cpp')
-rw-r--r--sethostent.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/sethostent.cpp b/sethostent.cpp
index 1bd8ab4c..70bb9553 100644
--- a/sethostent.cpp
+++ b/sethostent.cpp
@@ -43,12 +43,15 @@
#include "hostent.h"
#include "resolv_private.h"
+#include "gethostsfile.h"
+#include "hosts_cache.h"
+
constexpr int MAXALIASES = 35;
constexpr int MAXADDRS = 35;
static void sethostent_r(FILE** hf) {
if (!*hf)
- *hf = fopen(_PATH_HOSTS, "re");
+ *hf = fopen(gethostsfile(), "re");
else
rewind(*hf);
}
@@ -69,6 +72,11 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
char* aliases[MAXALIASES];
char* addr_ptrs[MAXADDRS];
+ int rc = hc_gethtbyname(name, af, info);
+ if (rc != NETDB_INTERNAL) {
+ return (rc == NETDB_SUCCESS ? 0 : EAI_NODATA);
+ }
+
// TODO: Wrap the 'hf' into a RAII class or std::shared_ptr and modify the
// sethostent_r()/endhostent_r() to get rid of manually endhostent_r(&hf) everywhere.
FILE* hf = NULL;