summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'mdk-stage1/dns.c')
-rw-r--r--mdk-stage1/dns.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/mdk-stage1/dns.c b/mdk-stage1/dns.c
index 05f21a14a..488b4844e 100644
--- a/mdk-stage1/dns.c
+++ b/mdk-stage1/dns.c
@@ -75,19 +75,22 @@ int mygethostbyname(char * name, struct in_addr * addr)
char * mygethostbyaddr(char * ipnum)
{
- struct in_addr in;
- struct hostent * host;
+ struct sockaddr_in sa;
+ char hbuf[NI_MAXHOST];
/* prevent from timeouts */
if (_res.nscount == 0)
return NULL;
+
+ memset(&sa, 0, sizeof sa);
+ sa.sin_family = AF_INET;
- if (!inet_aton(ipnum, &in))
- return NULL;
- host = gethostbyaddr(&(in.s_addr), sizeof(in.s_addr) /* INADDRSZ */, AF_INET);
- if (host && host->h_name)
- return host->h_name;
- return NULL;
+ if (inet_pton(AF_INET, ipnum, &sa.sin_addr) != 1)
+ return NULL;
+
+ if (getnameinfo((struct sockaddr*)&sa, sizeof(sa), hbuf, sizeof(hbuf), NULL, 0, 0 |NI_NAMEREQD) == 0) //NI_NUMERICHOST NI_NAMEREQD
+ return strdup(hbuf);
+ else return NULL;
}
#elif defined(__GLIBC__)