diff options
author | brian <brian@FreeBSD.org> | 1999-04-09 01:54:10 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-04-09 01:54:10 +0000 |
commit | 040921481a09e7431faf10969c11dfce638fbeda (patch) | |
tree | c41d7b9736ccd4da3835e9e0bb68c307bd702820 /lib/libutil | |
parent | 2dbfcc3870c83de97f28288eb29f4274983dcd28 (diff) | |
download | FreeBSD-src-040921481a09e7431faf10969c11dfce638fbeda.zip FreeBSD-src-040921481a09e7431faf10969c11dfce638fbeda.tar.gz |
If given host.domain:nn[.nn], trimdomain() now reduces it to
host:nn[.nn] (if the domain is the same as the local one).
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/logwtmp.c | 42 | ||||
-rw-r--r-- | lib/libutil/trimdomain.3 | 22 |
2 files changed, 54 insertions, 10 deletions
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index a3cd87e..ad9a86e 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; #else static const char rcsid[] = - "$Id: logwtmp.c,v 1.10 1999/04/07 14:03:31 brian Exp $"; + "$Id: logwtmp.c,v 1.11 1999/04/08 08:00:06 brian Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -59,7 +59,9 @@ trimdomain(char *fullhost, int hostsize) { static char domain[MAXHOSTNAMELEN]; static int first = 1; - char *s; + static size_t dlen; + char *s, *end; + int spn, ok; if (first) { first = 0; @@ -68,17 +70,39 @@ trimdomain(char *fullhost, int hostsize) memmove(domain, s + 1, strlen(s + 1) + 1); else domain[0] = '\0'; + dlen = strlen(domain); } if (domain[0] != '\0') { s = fullhost; - while ((fullhost = strchr(fullhost, '.')) != NULL) - if (!strcasecmp(fullhost + 1, domain)) { - if (fullhost - s <= hostsize) - *fullhost = '\0'; /* hit it and acceptable size*/ - break; - } else - fullhost++; + end = s + hostsize + 1; + for (; (s = memchr(s, '.', end - s)) != NULL; s++) + if (!strncasecmp(s + 1, domain, dlen)) { + if (s[dlen + 1] == '\0') { + *s = '\0'; /* Found - lose the domain */ + break; + } else if (s[dlen + 1] == ':') { /* $DISPLAY ? */ + ok = dlen + 2; + spn = strspn(s + ok, "0123456789"); + if (spn > 0 && ok + spn - dlen <= end - s) { + ok += spn; + if (s[ok] == '\0') { + /* host.domain:nn */ + memmove(s, s + dlen + 1, ok - dlen); + break; + } else if (s[ok] == '.') { + ok++; + spn = strspn(s + ok, "0123456789"); + if (spn > 0 && s[ok + spn] == '\0' && + ok + spn - dlen <= end - s) { + /* host.domain:nn.nn */ + memmove(s, s + dlen + 1, ok + spn - dlen); + break; + } + } + } + } + } } } diff --git a/lib/libutil/trimdomain.3 b/lib/libutil/trimdomain.3 index 57e476f..263252a 100644 --- a/lib/libutil/trimdomain.3 +++ b/lib/libutil/trimdomain.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: realhostname.3,v 1.1 1999/04/06 23:02:35 brian Exp $ +.\" $Id: trimdomain.3,v 1.1 1999/04/07 14:03:31 brian Exp $ .\" .Dd April 7, 1999 .Os @@ -31,6 +31,7 @@ .Nm trimdomain .Nd "trim the current domain name from a host name" .Sh SYNOPSIS +.Fd #include <sys/types.h> .Fd #include <libutil.h> .Ft void .Fn trimdomain "char *fullhost" "int hostsize" @@ -59,6 +60,25 @@ will only trim the domain name if the passed ends with the current domain name and if the length of the resulting host name does not exceed .Ar hostsize . +.Pp +If the passed +.Ar fullname +is actually a +.Dv DISPLAY +specification of the form +.Sm off +.Ar host No . Ar domain No : Ns +.Sm on +.Ar \&nn Oo +.No . Ns Ar \&nn +.Oc +and the domain name is the same as the local domain name, +.Fn trimdomain +will remove the embedded domain name, copying the screen and display +numbers to the end of the base host name and resulting in +.Ar host No : Ns Ar \&nn Oo +.No . Ns Ar \&nn +.Oc . .Sh RETURN VALUES .Fn trimdomain does not return a value. |