diff options
-rw-r--r-- | mdk-stage1/NEWS | 1 | ||||
-rw-r--r-- | mdk-stage1/dns.c | 19 |
2 files changed, 12 insertions, 8 deletions
diff --git a/mdk-stage1/NEWS b/mdk-stage1/NEWS index 0544949cb..e9eaabd8b 100644 --- a/mdk-stage1/NEWS +++ b/mdk-stage1/NEWS @@ -1,6 +1,7 @@ - do not advice long dead pcmcia.img & network.img images (mga#5466) - first attempt at supporting XenBlk discs - switch from gethostbyname() to getaddrinfo() (mga#4056) +- switch from gethostbyaddr() to getnameinfo() 1.65 - load btrfs module to mount btrfs 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__) |