summaryrefslogtreecommitdiffstats
path: root/mdk-stage1
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2012-06-01 17:25:09 +0000
committerThierry Vignaud <tv@mageia.org>2012-06-01 17:25:09 +0000
commitbcd9a5cc02067ecdf47059673037c91de8a9d63e (patch)
tree7ccc7cf0ca348526321f92c4d6bd7196c0d9b4fb /mdk-stage1
parent7d3e2e64804dd41b6a4c3383a30c255c79e3639c (diff)
downloaddrakx-backup-do-not-use-bcd9a5cc02067ecdf47059673037c91de8a9d63e.tar
drakx-backup-do-not-use-bcd9a5cc02067ecdf47059673037c91de8a9d63e.tar.gz
drakx-backup-do-not-use-bcd9a5cc02067ecdf47059673037c91de8a9d63e.tar.bz2
drakx-backup-do-not-use-bcd9a5cc02067ecdf47059673037c91de8a9d63e.tar.xz
drakx-backup-do-not-use-bcd9a5cc02067ecdf47059673037c91de8a9d63e.zip
(mygethostbyname) switch from gethostbyname() to getaddrinfo()
(mga#4056) note that (? in the old days ?), gethostbyname() from dietlibc didn't supported domain handling
Diffstat (limited to 'mdk-stage1')
-rw-r--r--mdk-stage1/NEWS1
-rw-r--r--mdk-stage1/dns.c37
2 files changed, 24 insertions, 14 deletions
diff --git a/mdk-stage1/NEWS b/mdk-stage1/NEWS
index 816a92452..0544949cb 100644
--- a/mdk-stage1/NEWS
+++ b/mdk-stage1/NEWS
@@ -1,5 +1,6 @@
- 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)
1.65
- load btrfs module to mount btrfs
diff --git a/mdk-stage1/dns.c b/mdk-stage1/dns.c
index 63d801c62..05f21a14a 100644
--- a/mdk-stage1/dns.c
+++ b/mdk-stage1/dns.c
@@ -39,29 +39,38 @@
int mygethostbyname(char * name, struct in_addr * addr)
{
- struct hostent * h;
+ struct addrinfo hints, *res, *p;
+ int status;
+ char ipstr[INET6_ADDRSTRLEN];
+
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_INET; //AF_UNSPEC for both IPv4 & IPv6
+ hints.ai_socktype = SOCK_STREAM;
/* prevent from timeouts */
if (_res.nscount == 0)
return -1;
- h = gethostbyname(name);
-
- if (!h && domain) {
- // gethostbyname from dietlibc doesn't support domain handling
- char fully_qualified[500];
- sprintf(fully_qualified, "%s.%s", name, domain);
- h = gethostbyname(fully_qualified);
+ if ((status = getaddrinfo(name, NULL, &hints, &res)) != 0) {
+ log_message("getaddrinfo: %s\n", gai_strerror(status));
+ return -1;
}
- if (h && h->h_addr_list && (h->h_addr_list)[0]) {
- memcpy(addr, (h->h_addr_list)[0], sizeof(*addr));
- log_message("is-at: %s", inet_ntoa(*addr));
- return 0;
+ for (p = res;p != NULL; p = p->ai_next) {
+ void *tmp_addr;
+
+ struct sockaddr_in *ipv = (struct sockaddr_in *)p->ai_addr;
+ tmp_addr = &(ipv->sin_addr);
+
+ /* convert the IP to a string: */
+ inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
+
+ memcpy(addr, tmp_addr, sizeof(*addr));
+ log_message("is-at: %s\n", inet_ntoa(*addr));
}
- log_message("unknown host %s", name);
- return -1;
+ freeaddrinfo(res); // free the linked list
+ return 0;
}
char * mygethostbyaddr(char * ipnum)