diff options
author | peter <peter@FreeBSD.org> | 1996-01-15 02:18:35 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-01-15 02:18:35 +0000 |
commit | 297db4d6f76e22d93e587a48e8ba9cc319d61a24 (patch) | |
tree | f8d390e27b66f7711ca7e142e0e03b710fab7429 /usr.bin/netstat/main.c | |
parent | f9c7af3d08d6ea07bcd3818f4371531323c551da (diff) | |
download | FreeBSD-src-297db4d6f76e22d93e587a48e8ba9cc319d61a24.zip FreeBSD-src-297db4d6f76e22d93e587a48e8ba9cc319d61a24.tar.gz |
tidy up the domain name trimming code, and move it to a single place
rather than having the same bit of code duplicated in three places,
each with their own static copy of the host's local name.
Diffstat (limited to 'usr.bin/netstat/main.c')
-rw-r--r-- | usr.bin/netstat/main.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index d51489a..3ff395a 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -542,3 +542,33 @@ usage() " %s [-M core] [-N system] [-p protocol]\n", prog); exit(1); } + +void +trimdomain(cp) + char *cp; +{ + 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]) { + while ((cp = strchr(cp, '.'))) { + if (!strcasecmp(cp + 1, domain)) { + *cp = 0; /* hit it */ + break; + } else { + cp++; + } + } + } +} + |