diff options
author | brian <brian@FreeBSD.org> | 2001-03-14 20:51:26 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2001-03-14 20:51:26 +0000 |
commit | dd004da290c46c50b50ee5c919ad6eab35694921 (patch) | |
tree | 5e787a2429ce382c01d683306212b6100c2c4928 | |
parent | 8a3521bf30812a63d06554a1d7f88325346ba791 (diff) | |
download | FreeBSD-src-dd004da290c46c50b50ee5c919ad6eab35694921.zip FreeBSD-src-dd004da290c46c50b50ee5c919ad6eab35694921.tar.gz |
MAXHOSTNAMELEN includes space for a NUL.
Don't roll our own version of trimdomain(), use the one in libutil.
Not objected to by: freebsd-audit
-rw-r--r-- | usr.bin/netstat/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/netstat/inet.c | 5 | ||||
-rw-r--r-- | usr.bin/netstat/inet6.c | 2 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 30 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 1 | ||||
-rw-r--r-- | usr.bin/netstat/route.c | 13 |
6 files changed, 13 insertions, 42 deletions
diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile index 7f88c3b..c0a19a7 100644 --- a/usr.bin/netstat/Makefile +++ b/usr.bin/netstat/Makefile @@ -11,8 +11,8 @@ CFLAGS+=-DIPSEC #.PATH: ${.CURDIR}/../../sys/netiso BINGRP= kmem BINMODE=2555 -DPADD= ${LIBKVM} ${LIBIPX} ${LIBNETGRAPH} -LDADD= -lkvm -lipx -lnetgraph +DPADD= ${LIBKVM} ${LIBIPX} ${LIBNETGRAPH} ${LIBUTIL} +LDADD= -lkvm -lipx -lnetgraph -lutil CFLAGS+=-DINET6 -DIPSEC .include <bsd.prog.mk> diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index a2c2259..b2e3c3e 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -72,6 +72,7 @@ static const char rcsid[] = #include <arpa/inet.h> #include <err.h> #include <errno.h> +#include <libutil.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> @@ -716,7 +717,7 @@ inetname(inp) struct in_addr *inp; { register char *cp; - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; struct hostent *hp; struct netent *np; @@ -734,7 +735,7 @@ inetname(inp) hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); if (hp) { cp = hp->h_name; - trimdomain(cp); + trimdomain(cp, strlen(cp)); } } } diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c index 6fbb39a..0dd9e4e 100644 --- a/usr.bin/netstat/inet6.c +++ b/usr.bin/netstat/inet6.c @@ -1015,7 +1015,7 @@ inet6name(in6p) register char *cp; static char line[50]; struct hostent *hp; - static char domain[MAXHOSTNAMELEN + 1]; + static char domain[MAXHOSTNAMELEN]; static int first = 1; if (first && !nflag) { diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 9c128aa..5c23f3c 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -702,33 +702,3 @@ usage() " netstat [-M core] [-N system] [-p protocol]"); 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 70bfbf0..6886549 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -61,7 +61,6 @@ int af; /* address family */ 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 *, int)); void tcp_stats __P((u_long, char *)); diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 0a52e56..e10d07a 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -62,6 +62,7 @@ static const char rcsid[] = #include <sys/sysctl.h> #include <arpa/inet.h> +#include <libutil.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> @@ -637,7 +638,7 @@ routename(in) u_long in; { register char *cp; - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; struct hostent *hp; cp = 0; @@ -646,7 +647,7 @@ routename(in) AF_INET); if (hp) { cp = hp->h_name; - trimdomain(cp); + trimdomain(cp, strlen(cp)); } } if (cp) { @@ -715,7 +716,7 @@ netname(in, mask) u_long in, mask; { char *cp = 0; - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; struct netent *np = 0; u_long net, omask, dmask; register u_long i; @@ -729,7 +730,7 @@ netname(in, mask) np = getnetbyaddr(net, AF_INET); if (np) { cp = np->n_name; - trimdomain(cp); + trimdomain(cp, strlen(cp)); } } if (cp) @@ -753,7 +754,7 @@ netname6(sa6, mask) struct sockaddr_in6 *sa6; struct in6_addr *mask; { - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; u_char *p = (u_char *)mask; u_char *lim; int masklen, illegal = 0, flag = NI_WITHSCOPEID; @@ -816,7 +817,7 @@ char * routename6(sa6) struct sockaddr_in6 *sa6; { - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; int flag = NI_WITHSCOPEID; /* use local variable for safety */ struct sockaddr_in6 sa6_local = {AF_INET6, sizeof(sa6_local),}; |