Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/route Clean up some minor nits:
details: https://anonhg.NetBSD.org/src/rev/2cbbdc95627b
branches: trunk
changeset: 583935:2cbbdc95627b
user: ginsbach <ginsbach%NetBSD.org@localhost>
date: Tue Aug 30 19:01:25 2005 +0000
description:
Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).
diffstat:
sbin/route/route.c | 59 +++++++++++++++++++++++++++++------------------------
sbin/route/show.c | 21 ++++++++++--------
2 files changed, 44 insertions(+), 36 deletions(-)
diffs (223 lines):
diff -r c85dbd677c49 -r 2cbbdc95627b sbin/route/route.c
--- a/sbin/route/route.c Tue Aug 30 18:47:19 2005 +0000
+++ b/sbin/route/route.c Tue Aug 30 19:01:25 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.91 2005/08/15 19:28:08 ginsbach Exp $ */
+/* $NetBSD: route.c,v 1.92 2005/08/30 19:01:25 ginsbach Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: route.c,v 1.91 2005/08/15 19:28:08 ginsbach Exp $");
+__RCSID("$NetBSD: route.c,v 1.92 2005/08/30 19:01:25 ginsbach Exp $");
#endif
#endif /* not lint */
@@ -296,18 +296,21 @@
mib[5] = 0; /* no flags */
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
- if (needed == 0)
- return 0;
- if ((buf = malloc(needed)) == NULL)
- err(1, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
- err(1, "actual retrieval of routing table");
- lim = buf + needed;
+ buf = lim = NULL;
+ if (needed) {
+ if ((buf = malloc(needed)) == NULL)
+ err(1, "malloc");
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ err(1, "actual retrieval of routing table");
+ lim = buf + needed;
+ }
if (verbose) {
(void)printf("Examining routing table from sysctl\n");
if (af)
printf("(address family %s)\n", (*argv + 1));
}
+ if (needed == 0)
+ return 0;
seqno = 0; /* ??? */
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
@@ -350,6 +353,7 @@
(void)printf("done\n");
}
}
+ free(buf);
return 0;
}
@@ -381,7 +385,6 @@
return obuf;
}
-
int
netmask_length(struct sockaddr *nm, int family)
{
@@ -481,7 +484,6 @@
return smask;
}
-
const char *
routename(struct sockaddr *sa, struct sockaddr *nm, int flags)
{
@@ -533,7 +535,7 @@
char *ccp;
if ((ccp = strchr(hp->h_name, '.')) &&
!strcmp(ccp + 1, domain))
- *ccp = 0;
+ *ccp = '\0';
cp = hp->h_name;
}
}
@@ -587,7 +589,7 @@
char *ccp;
if (!nflag && (ccp = strchr(nihost, '.')) &&
strcmp(ccp + 1, domain) == 0)
- *ccp = 0;
+ *ccp = '\0';
strlcpy(line, nihost, sizeof(line));
}
break;
@@ -740,7 +742,6 @@
/* noncontiguous never happens in ipv6 */
snprintf(line, sizeof(line), "::/%d", nml);
}
-
else if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
line, sizeof(line), NULL, 0, niflags) != 0)
strlcpy(line, "invalid", sizeof(line));
@@ -990,7 +991,7 @@
"assuming route to if");
}
} else
- usage((char *)NULL);
+ usage(NULL);
iflag = 1;
continue;
} else if (ret > 0 && ret < 10) {
@@ -1220,14 +1221,14 @@
slash = 0;
}
if (getaddrinfo(s, "0", &hints, &res) != 0)
- errx(1, "bad value: %s", s);
+ errx(1, "%s: bad value", s);
}
if (slash)
*slash = '/';
if (sizeof(su->sin6) != res->ai_addrlen)
errx(1, "%s: bad value", s);
if (res->ai_next)
- errx(1, "address resolved to multiple values: %s", s);
+ errx(1, "%s: address resolved to multiple values", s);
memcpy(&su->sin6, res->ai_addr, sizeof(su->sin6));
freeaddrinfo(res);
#ifdef __KAME__
@@ -1353,7 +1354,7 @@
memmove(&su->sin.sin_addr, hp->h_addr, hp->h_length);
return (1);
}
- errx(1, "bad value: %s", s);
+ errx(1, "%s: bad value", s);
/*NOTREACHED*/
}
@@ -1374,11 +1375,12 @@
#endif
default:
errx(1, "prefixlen is not supported with af %d", af);
+ /*NOTREACHED*/
}
rtm_addrs |= RTA_NETMASK;
if (len < -1 || len > max)
- errx(1, "bad value: %s", s);
+ errx(1, "%s: bad value", s);
q = len >> 3;
r = len & 7;
@@ -1483,14 +1485,17 @@
mib[5] = 0; /* no flags */
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
- if ((buf = malloc(needed)) == NULL)
- err(1, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
- err(1, "actual retrieval of interface table");
- lim = buf + needed;
- for (next = buf; next < lim; next += rtm->rtm_msglen) {
- rtm = (struct rt_msghdr *)next;
- print_rtmsg(rtm, rtm->rtm_msglen);
+ if (needed) {
+ if ((buf = malloc(needed)) == NULL)
+ err(1, "malloc");
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ err(1, "actual retrieval of interface table");
+ lim = buf + needed;
+ for (next = buf; next < lim; next += rtm->rtm_msglen) {
+ rtm = (struct rt_msghdr *)next;
+ print_rtmsg(rtm, rtm->rtm_msglen);
+ }
+ free(buf);
}
}
diff -r c85dbd677c49 -r 2cbbdc95627b sbin/route/show.c
--- a/sbin/route/show.c Tue Aug 30 18:47:19 2005 +0000
+++ b/sbin/route/show.c Tue Aug 30 19:01:25 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.26 2005/08/09 21:25:42 ginsbach Exp $ */
+/* $NetBSD: show.c,v 1.27 2005/08/30 19:01:25 ginsbach Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-__RCSID("$NetBSD: show.c,v 1.26 2005/08/09 21:25:42 ginsbach Exp $");
+__RCSID("$NetBSD: show.c,v 1.27 2005/08/30 19:01:25 ginsbach Exp $");
#endif
#endif /* not lint */
@@ -159,22 +159,25 @@
mib[5] = 0;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
- if ((buf = malloc(needed)) == 0)
- err(1, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
- err(1, "sysctl of routing table");
- lim = buf + needed;
+ buf = lim = NULL;
+ if (needed) {
+ if ((buf = malloc(needed)) == 0)
+ err(1, "malloc");
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ err(1, "sysctl of routing table");
+ lim = buf + needed;
+ }
printf("Routing table%s\n", (af == AF_UNSPEC)? "s" : "");
- /* for (i = 0; i <= AF_MAX; i++) ??? */
- {
+ if (needed) {
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
sa = (struct sockaddr *)(rtm + 1);
if (af == AF_UNSPEC || af == sa->sa_family)
p_rtentry(rtm);
}
+ free(buf);
}
}
Home |
Main Index |
Thread Index |
Old Index