From aba2bff439b6d99def06b8e2338b3e0060281808 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 17 Jun 1996 14:49:02 +0000 Subject: If hostname > UT_HOSTSIZE, use its numeric address instead to keep valid entries into utmp and wtmp --- lib/libutil/logwtmp.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/libutil/logwtmp.c') diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index f4a6408..a19e651 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -37,12 +37,16 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; #include #include -#include #include +#include +#include +#include +#include +#include +#include #include #include -#include void logwtmp(line, name, host) @@ -51,8 +55,18 @@ logwtmp(line, name, host) struct utmp ut; struct stat buf; int fd; - time_t time(); - char *strncpy(); + + 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 = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) return; -- cgit v1.1