From ad5e523b7f7afcce74810f98ae75b73ba95d6329 Mon Sep 17 00:00:00 2001 From: Yoshinobu Inoue Date: Sat, 15 Jan 2000 03:26:54 +0000 Subject: [PATCH] Support v6 login. --- lib/libutil/logwtmp.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index fd05b55e80d2..26484503b450 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -41,6 +41,7 @@ static const char rcsid[] = #endif /* LIBC_SCCS and not lint */ #include +#include #include #include #include @@ -54,6 +55,11 @@ static const char rcsid[] = #include #include +/* wrapper for KAME-special getnameinfo() */ +#ifndef NI_WITHSCOPEID +#define NI_WITHSCOPEID 0 +#endif + void trimdomain(char *fullhost, int hostsize) { @@ -106,6 +112,8 @@ trimdomain(char *fullhost, int hostsize) } } +#include + void logwtmp(line, name, host) const char *line; @@ -123,15 +131,24 @@ logwtmp(line, name, host) host = fullhost; if (strlen(host) > UT_HOSTSIZE) { - struct hostent *hp = gethostbyname(host); + int error; + struct addrinfo hints, *res; - if (hp != NULL) { - struct in_addr in; - - memmove(&in, hp->h_addr, sizeof(in)); - host = inet_ntoa(in); - } else + bzero(&hints, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_CANONNAME; + error = getaddrinfo(host, NULL, &hints, &res); + if (error != 0 || res->ai_addr == NULL) host = "invalid hostname"; + else { + error = getnameinfo(res->ai_addr, res->ai_addrlen, + fullhost, strlen(fullhost), NULL, 0, + NI_NUMERICHOST|NI_WITHSCOPEID); + if (error != 0) { + fprintf(stderr, "%d", error); + host = "invalid hostname"; + } + } } if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)