From fd850072e807af92d7bbe6e9788ad1512ed52986 Mon Sep 17 00:00:00 2001 From: ume Date: Mon, 28 Jan 2002 14:50:07 +0000 Subject: Log wtmp according to an address family properly. Reported by: matusita Reviewed by: matusita MFC after: 1 week --- libexec/ftpd/logwtmp.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'libexec/ftpd/logwtmp.c') diff --git a/libexec/ftpd/logwtmp.c b/libexec/ftpd/logwtmp.c index 2ac57d1..185d92d 100644 --- a/libexec/ftpd/logwtmp.c +++ b/libexec/ftpd/logwtmp.c @@ -52,6 +52,7 @@ static const char rcsid[] = #include #include #include +#include #include "extern.h" static int fd = -1; @@ -62,31 +63,18 @@ static int fd = -1; * after login, but before logout). */ void -ftpd_logwtmp(line, name, host) - char *line, *name, *host; +ftpd_logwtmp(line, name, addr) + char *line, *name; + struct sockaddr *addr; { struct utmp ut; struct stat buf; + char host[UT_HOSTSIZE]; - if (strlen(host) > UT_HOSTSIZE) { - struct addrinfo hints, *res; - int error; - static char hostbuf[BUFSIZ]; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - error = getaddrinfo(host, NULL, &hints, &res); - if (error) - host = "invalid hostname"; - else { - getnameinfo(res->ai_addr, res->ai_addrlen, - hostbuf, sizeof(hostbuf), NULL, 0, - NI_NUMERICHOST); - host = hostbuf; - if (strlen(host) > UT_HOSTSIZE) - host[UT_HOSTSIZE] = '\0'; - } - } + if (addr == NULL) + host[0] = '\0'; + else + realhostname_sa(host, sizeof(host), addr, addr->sa_len); if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) return; -- cgit v1.1