If hostname > UT_HOSTSIZE, use its numerical address instead to keep

valid utmp and wtmp entries
This commit is contained in:
ache 1996-06-17 14:59:07 +00:00
parent aba2bff439
commit 87e1afbd93

View File

@ -37,10 +37,13 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <time.h>
#include <netdb.h>
#include <utmp.h>
#include <unistd.h>
#include <stdio.h>
@ -61,6 +64,18 @@ logwtmp(line, name, host)
struct utmp ut;
struct stat buf;
if (strlen(host) > UT_HOSTSIZE) {
struct hostent *hp = gethostbyname(host);
if (hp != NULL) {
struct in_addr in;
memmove(&in, hp->h_addr, sizeof(in));
host = inet_ntoa(in);
} else
host = "invalid hostname";
}
if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
return;
if (fstat(fd, &buf) == 0) {