summaryrefslogtreecommitdiffstats
path: root/term-utils/agetty.c
diff options
context:
space:
mode:
authorSami Kerola2012-10-12 23:11:16 +0200
committerKarel Zak2012-10-22 10:14:36 +0200
commit74b3df85f7f8d3a34a0b97c02413dd602a7b12c8 (patch)
tree6f68bf9661f67baed1ac5124575ab6475828fafb /term-utils/agetty.c
parentlogger: replace gethostbyname() with getaddrinfo() (diff)
downloadkernel-qcow2-util-linux-74b3df85f7f8d3a34a0b97c02413dd602a7b12c8.tar.gz
kernel-qcow2-util-linux-74b3df85f7f8d3a34a0b97c02413dd602a7b12c8.tar.xz
kernel-qcow2-util-linux-74b3df85f7f8d3a34a0b97c02413dd602a7b12c8.zip
agetty: replace gethostbyname() with getaddrinfo()
The gethostbyname() is legacy function which may be withdrawn in a future. Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/gethostbyname.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/agetty.c')
-rw-r--r--term-utils/agetty.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 9bb0fd753..e53a70188 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -1331,18 +1331,30 @@ static void do_prompt(struct options *op, struct termios *tp)
char *hn = xgethostname();
if (hn) {
- struct hostent *ht;
char *dot = strchr(hn, '.');
+ char *cn = hn;
+ struct addrinfo *res = NULL;
if ((op->flags & F_LONGHNAME) == 0) {
if (dot)
*dot = '\0';
- write_all(STDOUT_FILENO, hn, strlen(hn));
- } else if (dot == NULL && (ht = gethostbyname(hn)))
- write_all(STDOUT_FILENO, ht->h_name, strlen(ht->h_name));
- else
- write_all(STDOUT_FILENO, hn, strlen(hn));
+
+ } else if (dot == NULL) {
+ struct addrinfo hints;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_CANONNAME;
+
+ if (!getaddrinfo(hn, NULL, &hints, &res)
+ && res && res->ai_canonname)
+ cn = res->ai_canonname;
+ }
+
+ write_all(STDOUT_FILENO, cn, strlen(cn));
write_all(STDOUT_FILENO, " ", 1);
+
+ if (res)
+ freeaddrinfo(res);
free(hn);
}
}