diff options
author | amurai <amurai@FreeBSD.org> | 1998-06-01 08:47:04 +0000 |
---|---|---|
committer | amurai <amurai@FreeBSD.org> | 1998-06-01 08:47:04 +0000 |
commit | daec9421536dea043301b78b1811faf425e5595c (patch) | |
tree | ce5847dfeeeb2a864c0cb5ca1cb3306538092ee8 /lib/libutil/logwtmp.c | |
parent | 0f778d7313fc2777a689ebb3f9e162f198928194 (diff) | |
download | FreeBSD-src-daec9421536dea043301b78b1811faf425e5595c.zip FreeBSD-src-daec9421536dea043301b78b1811faf425e5595c.tar.gz |
Trim a domain part for wtmp as same as showed by "netstat -r".
Here is a some example for avoiding a confusion.
It asssumes a logged host domain is "spec.co.jp". All
example is longer than UT_HOSTNAMELEN value.
1) turbo.tama.spec.co.jp: 192.19.0.2 -> trubo.tama
2) turbo.tama.foo.co.jp : 192.19.0.2 -> 192.19.0.2
3) specgw.spec.co.jp : 202.32.13.1 -> specgw
Submitted by: Atsushi Murai <amurai@spec.co.jp>
Diffstat (limited to 'lib/libutil/logwtmp.c')
-rw-r--r-- | lib/libutil/logwtmp.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index de3c5d6..531b715 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -36,10 +36,11 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; #else static const char rcsid[] = - "$Id: logwtmp.c,v 1.4 1997/08/13 20:42:18 steve Exp $"; + "$Id: logwtmp.c,v 1.5 1997/09/04 22:38:59 pst Exp $"; #endif #endif /* LIBC_SCCS and not lint */ +#include <sys/param.h> #include <sys/types.h> #include <sys/file.h> #include <sys/stat.h> @@ -54,6 +55,37 @@ static const char rcsid[] = #include <utmp.h> void +trimdomain( char * fullhost, int hostsize ) +{ + static char domain[MAXHOSTNAMELEN + 1]; + static int first = 1; + char *s; + + if (first) { + first = 0; + if (gethostname(domain, MAXHOSTNAMELEN) == 0 && + (s = strchr(domain, '.'))) + (void) strcpy(domain, s + 1); + else + domain[0] = 0; + } + + if (domain[0]) { + s = fullhost; + while ((fullhost = strchr(fullhost, '.'))) { + if (!strcasecmp(fullhost + 1, domain)) { + if ( fullhost - s < hostsize ) { + *fullhost = '\0'; /* hit it and acceptable size*/ + } + break; + } else { + fullhost++; + } + } + } +} + +void logwtmp(line, name, host) const char *line; const char *name; @@ -61,7 +93,14 @@ logwtmp(line, name, host) { struct utmp ut; struct stat buf; + char fullhost[MAXHOSTNAMELEN + 1]; + char *whost = fullhost; int fd; + + strncpy( whost, host, MAXHOSTNAMELEN ); +fullhost[MAXHOSTNAMELEN] = '\0'; + trimdomain( whost, UT_HOSTSIZE ); + host = whost; if (strlen(host) > UT_HOSTSIZE) { struct hostent *hp = gethostbyname(host); |