diff options
author | shin <shin@FreeBSD.org> | 2000-01-15 03:26:54 +0000 |
---|---|---|
committer | shin <shin@FreeBSD.org> | 2000-01-15 03:26:54 +0000 |
commit | aebe3f8e9d8e671e853e66ec9054d37066c13339 (patch) | |
tree | 9625d4fdc1fe8b49e3e0bbb34caf664891d90196 /lib/libutil | |
parent | af62fb2de857c569df950db8e4b7c76372166501 (diff) | |
download | FreeBSD-src-aebe3f8e9d8e671e853e66ec9054d37066c13339.zip FreeBSD-src-aebe3f8e9d8e671e853e66ec9054d37066c13339.tar.gz |
Support v6 login.
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/logwtmp.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index fd05b55..2648450 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 <sys/param.h> +#include <sys/socket.h> #include <sys/types.h> #include <sys/file.h> #include <sys/stat.h> @@ -54,6 +55,11 @@ static const char rcsid[] = #include <unistd.h> #include <utmp.h> +/* 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 <stdio.h> + 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); - - if (hp != NULL) { - struct in_addr in; + int error; + struct addrinfo hints, *res; - 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) |