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
This commit is contained in:
brian 2001-03-14 20:51:26 +00:00
parent a01fd47f80
commit fc26c36488
6 changed files with 13 additions and 42 deletions

View File

@ -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>

View File

@ -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));
}
}
}

View File

@ -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) {

View File

@ -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++;
}
}
}
}

View File

@ -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 *));

View File

@ -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),};