Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/netstat - avoid pointer gymnastics
details: https://anonhg.NetBSD.org/src/rev/baac20d083ef
branches: trunk
changeset: 790637:baac20d083ef
user: christos <christos%NetBSD.org@localhost>
date: Fri Oct 18 20:26:45 2013 +0000
description:
- avoid pointer gymnastics
- remove unused variables
diffstat:
usr.bin/netstat/atalk.c | 13 ++++++-------
usr.bin/netstat/if.c | 19 +++++++++++--------
usr.bin/netstat/inet6.c | 10 ++++++----
usr.bin/netstat/mroute6.c | 4 +---
usr.bin/netstat/show.c | 17 +++++++++++------
usr.bin/netstat/vtw.c | 13 ++++---------
6 files changed, 39 insertions(+), 37 deletions(-)
diffs (247 lines):
diff -r ab51b2141edc -r baac20d083ef usr.bin/netstat/atalk.c
--- a/usr.bin/netstat/atalk.c Fri Oct 18 20:19:36 2013 +0000
+++ b/usr.bin/netstat/atalk.c Fri Oct 18 20:26:45 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atalk.c,v 1.14 2009/04/12 16:08:37 lukem Exp $ */
+/* $NetBSD: atalk.c,v 1.15 2013/10/18 20:26:45 christos Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from @(#)atalk.c 1.1 (Whistle) 6/6/96";
#else
-__RCSID("$NetBSD: atalk.c,v 1.14 2009/04/12 16:08:37 lukem Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.15 2013/10/18 20:26:45 christos Exp $");
#endif
#endif /* not lint */
@@ -229,17 +229,16 @@
void
atalkprotopr(u_long off, const char *name)
{
- struct ddpcb cb;
- struct ddpcb *prev, *next;
- struct ddpcb *initial;
+ struct ddpcb cb;
+ struct ddpcb *next;
+ struct ddpcb *initial;
int width = 22;
if (off == 0)
return;
if (kread(off, (char *)&initial, sizeof(struct ddpcb *)) < 0)
return;
ddpcb = cb;
- prev = (struct ddpcb *)off;
- for (next = initial; next != NULL; prev = next) {
+ for (next = initial; next != NULL;) {
u_long ppcb = (u_long)next;
if (kread((u_long)next, (char *)&ddpcb, sizeof(ddpcb)) < 0)
diff -r ab51b2141edc -r baac20d083ef usr.bin/netstat/if.c
--- a/usr.bin/netstat/if.c Fri Oct 18 20:19:36 2013 +0000
+++ b/usr.bin/netstat/if.c Fri Oct 18 20:26:45 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.76 2013/03/01 18:26:11 joerg Exp $ */
+/* $NetBSD: if.c,v 1.77 2013/10/18 20:26:45 christos Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
#else
-__RCSID("$NetBSD: if.c,v 1.76 2013/03/01 18:26:11 joerg Exp $");
+__RCSID("$NetBSD: if.c,v 1.77 2013/10/18 20:26:45 christos Exp $");
#endif
#endif /* not lint */
@@ -401,9 +401,10 @@
sin6 = (struct sockaddr_in6 *)sa;
#ifdef __KAME__
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
- sin6->sin6_scope_id =
- ntohs(*(u_int16_t *)
- &sin6->sin6_addr.s6_addr[2]);
+ uint16_t scope;
+ memcpy(&scope, &sin6->sin6_addr.s6_addr[2],
+ sizeof(scope));
+ sin6->sin6_scope_id = ntohs(scope);
/* too little width */
if (!vflag)
sin6->sin6_scope_id = 0;
@@ -455,9 +456,11 @@
as6.sin6_addr = inm.in6m_addr;
#ifdef __KAME__
if (IN6_IS_ADDR_MC_LINKLOCAL(&as6.sin6_addr)) {
- as6.sin6_scope_id =
- ntohs(*(u_int16_t *)
- &as6.sin6_addr.s6_addr[2]);
+ uint16_t scope;
+ memcpy(&scope,
+ &sin6->sin6_addr.s6_addr[2],
+ sizeof(scope));
+ as6.sin6_scope_id = ntohs(scope);
as6.sin6_addr.s6_addr[2] = 0;
as6.sin6_addr.s6_addr[3] = 0;
}
diff -r ab51b2141edc -r baac20d083ef usr.bin/netstat/inet6.c
--- a/usr.bin/netstat/inet6.c Fri Oct 18 20:19:36 2013 +0000
+++ b/usr.bin/netstat/inet6.c Fri Oct 18 20:26:45 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inet6.c,v 1.62 2013/06/20 10:43:18 martin Exp $ */
+/* $NetBSD: inet6.c,v 1.63 2013/10/18 20:26:45 christos Exp $ */
/* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
/*
@@ -64,7 +64,7 @@
#if 0
static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-__RCSID("$NetBSD: inet6.c,v 1.62 2013/06/20 10:43:18 martin Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.63 2013/10/18 20:26:45 christos Exp $");
#endif
#endif /* not lint */
@@ -1423,8 +1423,10 @@
#ifdef __KAME__
if (IN6_IS_ADDR_LINKLOCAL(in6p) ||
IN6_IS_ADDR_MC_LINKLOCAL(in6p)) {
- sin6.sin6_scope_id =
- ntohs(*(const u_int16_t *)&in6p->s6_addr[2]);
+ uint16_t scope;
+ memcpy(&scope, &sin6.sin6_addr.s6_addr[2],
+ sizeof(scope));
+ sin6.sin6_scope_id = ntohs(scope);
sin6.sin6_addr.s6_addr[2] = 0;
sin6.sin6_addr.s6_addr[3] = 0;
}
diff -r ab51b2141edc -r baac20d083ef usr.bin/netstat/mroute6.c
--- a/usr.bin/netstat/mroute6.c Fri Oct 18 20:19:36 2013 +0000
+++ b/usr.bin/netstat/mroute6.c Fri Oct 18 20:26:45 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mroute6.c,v 1.13 2012/03/20 20:34:58 matt Exp $ */
+/* $NetBSD: mroute6.c,v 1.14 2013/10/18 20:26:45 christos Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@@ -136,7 +136,6 @@
register int i;
register int banner_printed;
register int saved_numeric_addr;
- mifi_t maxmif = 0;
int waitings;
if (mrpaddr == 0) {
@@ -181,7 +180,6 @@
continue;
kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
- maxmif = mifi;
if (!banner_printed) {
printf("\nIPv6 Multicast Interface Table\n"
" Mif Rate PhyIF Pkts-In Pkts-Out\n");
diff -r ab51b2141edc -r baac20d083ef usr.bin/netstat/show.c
--- a/usr.bin/netstat/show.c Fri Oct 18 20:19:36 2013 +0000
+++ b/usr.bin/netstat/show.c Fri Oct 18 20:26:45 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.15 2011/11/11 15:09:33 gdt Exp $ */
+/* $NetBSD: show.c,v 1.16 2013/10/18 20:26:45 christos Exp $ */
/* $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $ */
/*
@@ -339,9 +339,12 @@
if (IN6_IS_ADDR_LINKLOCAL(in6) ||
IN6_IS_ADDR_MC_LINKLOCAL(in6)) {
/* XXX: override is ok? */
- sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)
- &in6->s6_addr[2]);
- *(u_short *)&in6->s6_addr[2] = 0;
+ uint16_t scope;
+ memcpy(&scope, &sa6->sin6_addr.s6_addr[2],
+ sizeof(scope));
+ sa6->sin6_scope_id = ntohs(scope);
+ in6->s6_addr[2] = 0;
+ in6->s6_addr[3] = 0;
}
if (flags & RTF_HOST)
cp = routename((struct sockaddr *)sa6);
@@ -436,8 +439,10 @@
(IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||
IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr)) &&
sin6.sin6_scope_id == 0) {
- sin6.sin6_scope_id =
- ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]);
+ uint16_t scope;
+ memcpy(&scope, &sin6.sin6_addr.s6_addr[2],
+ sizeof(scope));
+ sin6.sin6_scope_id = ntohs(scope);
sin6.sin6_addr.s6_addr[2] = 0;
sin6.sin6_addr.s6_addr[3] = 0;
}
diff -r ab51b2141edc -r baac20d083ef usr.bin/netstat/vtw.c
--- a/usr.bin/netstat/vtw.c Fri Oct 18 20:19:36 2013 +0000
+++ b/usr.bin/netstat/vtw.c Fri Oct 18 20:26:45 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vtw.c,v 1.6 2011/05/11 15:08:59 drochner Exp $ */
+/* $NetBSD: vtw.c,v 1.7 2013/10/18 20:26:45 christos Exp $ */
/*
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#if 0
static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-__RCSID("$NetBSD: vtw.c,v 1.6 2011/05/11 15:08:59 drochner Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.7 2013/10/18 20:26:45 christos Exp $");
#endif
#endif /* not lint */
@@ -263,7 +263,7 @@
/* snarf/adjust vtw_ctl */
for (i = 0; i < VTW_NCLASS; ++i) {
vtw_v4_t *kbase, *klim;
- vtw_v4_t *ubase, *ulim;
+ vtw_v4_t *ubase;
ptrdiff_t delta;
kbase = vtw_tcpv4[i].base.v4;
@@ -277,14 +277,11 @@
if (!i) {
if ((ubase = malloc(n * sizeof(*kbase))) == NULL)
err(EXIT_FAILURE, NULL);
- ulim = ubase + n - 1;
-
snarf(kbase, ubase, n * sizeof(*ubase));
mem += n * sizeof(*ubase);
} else {
ubase = vtw_tcpv4[0].base.v4;
- ulim = vtw_tcpv4[0].lim.v4;
}
delta = ubase - kbase;
@@ -366,7 +363,7 @@
for (i = 0; i < VTW_NCLASS; ++i) {
vtw_v6_t *kbase, *klim;
- vtw_v6_t *ubase, *ulim;
+ vtw_v6_t *ubase;
ptrdiff_t delta;
kbase = vtw_tcpv6[i].base.v6;
@@ -380,14 +377,12 @@
if (!i) {
if ((ubase = malloc(n * sizeof(*kbase))) == NULL)
err(EXIT_FAILURE, NULL);
- ulim = ubase + n - 1;
snarf(kbase, ubase, n * sizeof(*ubase));
mem += n * sizeof(*ubase);
} else {
ubase = vtw_tcpv6[0].base.v6;
- ulim = vtw_tcpv6[0].lim.v6;
}
delta = ubase - kbase;
Home |
Main Index |
Thread Index |
Old Index