diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 31be4cb5a54..8f1fd959095 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -466,17 +466,7 @@ inetname(inp) static char line[50]; struct hostent *hp; struct netent *np; - static char domain[MAXHOSTNAMELEN + 1]; - static int first = 1; - if (first && !nflag) { - first = 0; - if (gethostname(domain, MAXHOSTNAMELEN) == 0 && - (cp = index(domain, '.'))) - (void) strcpy(domain, cp + 1); - else - domain[0] = 0; - } cp = 0; if (!nflag && inp->s_addr != INADDR_ANY) { int net = inet_netof(*inp); @@ -490,10 +480,8 @@ inetname(inp) if (cp == 0) { hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); if (hp) { - if ((cp = index(hp->h_name, '.')) && - !strcmp(cp + 1, domain)) - *cp = 0; cp = hp->h_name; + trimdomain(cp); } } } diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index d51489affbf..3ff395a4f65 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++; + } + } + } +} + diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index ce3bd383893..c37b90b1d59 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -61,6 +61,7 @@ char *prog; /* program name */ int kread __P((u_long addr, char *buf, int size)); char *plural __P((int)); char *plurales __P((int)); +void trimdomain __P((char *)); void protopr __P((u_long, char *)); void tcp_stats __P((u_long, char *)); @@ -70,7 +71,7 @@ void icmp_stats __P((u_long, char *)); void igmp_stats __P((u_long, char *)); void protopr __P((u_long, char *)); -void mbpr(u_long); +void mbpr __P((u_long)); void hostpr __P((u_long, u_long)); void impstats __P((u_long, u_long)); @@ -116,3 +117,4 @@ void tp_stats __P((caddr_t, caddr_t)); void mroutepr __P((u_long, u_long, u_long)); void mrt_stats __P((u_long, u_long)); + diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 0f9d1a5f3ae..b0ca63294f4 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -36,7 +36,7 @@ static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95"; #endif static const char rcsid[] = - "$Id: route.c,v 1.9 1996/01/14 23:33:13 peter Exp $"; + "$Id: route.c,v 1.10 1996/01/14 23:42:19 peter Exp $"; #endif /* not lint */ #include @@ -540,26 +540,14 @@ routename(in) register char *cp; static char line[MAXHOSTNAMELEN + 1]; struct hostent *hp; - static char domain[MAXHOSTNAMELEN + 1]; - static int first = 1; - if (first) { - first = 0; - if (gethostname(domain, MAXHOSTNAMELEN) == 0 && - (cp = index(domain, '.'))) - (void) strcpy(domain, cp + 1); - else - domain[0] = 0; - } cp = 0; if (!nflag) { hp = gethostbyaddr((char *)&in, sizeof (struct in_addr), AF_INET); if (hp) { - if ((cp = index(hp->h_name, '.')) && - !strcmp(cp + 1, domain)) - *cp = 0; cp = hp->h_name; + trimdomain(cp); } } if (cp) @@ -664,8 +652,10 @@ netname(in, mask) mask >>= 1, net >>= 1; if (!(np = getnetbyaddr(i, AF_INET))) np = getnetbyaddr(net, AF_INET); - if (np) + if (np) { cp = np->n_name; + trimdomain(cp); + } } if (cp) strncpy(line, cp, sizeof(line) - 1);