summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2013-10-18 20:26:45 +0000
committerchristos <christos@NetBSD.org>2013-10-18 20:26:45 +0000
commit6e20d4e45679dc080dd2ec8c233b4fbc3fd13ab6 (patch)
tree2a65c8617cda5dfbd65ed1ad911b1402de143e90
parent8eef60812a86ff72e11986e3aeee1b7719d37ab2 (diff)
- avoid pointer gymnastics
- remove unused variables
-rw-r--r--usr.bin/netstat/atalk.c13
-rw-r--r--usr.bin/netstat/if.c19
-rw-r--r--usr.bin/netstat/inet6.c10
-rw-r--r--usr.bin/netstat/mroute6.c4
-rw-r--r--usr.bin/netstat/show.c17
-rw-r--r--usr.bin/netstat/vtw.c13
6 files changed, 39 insertions, 37 deletions
diff --git a/usr.bin/netstat/atalk.c b/usr.bin/netstat/atalk.c
index 9f990f9eea7..b24ca5c0f9a 100644
--- a/usr.bin/netstat/atalk.c
+++ b/usr.bin/netstat/atalk.c
@@ -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 @@ atalk_print2(const struct sockaddr *sa, const struct sockaddr *mask, int what)
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 --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index fb26091702e..fe214bd6bb0 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -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 @@ print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd,
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 @@ print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd,
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 --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c
index 1b67d274f60..647de3d6d02 100644
--- a/usr.bin/netstat/inet6.c
+++ b/usr.bin/netstat/inet6.c
@@ -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 @@ inet6name(const struct in6_addr *in6p)
#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 --git a/usr.bin/netstat/mroute6.c b/usr.bin/netstat/mroute6.c
index 4a90e0ec70e..a08d773754a 100644
--- a/usr.bin/netstat/mroute6.c
+++ b/usr.bin/netstat/mroute6.c
@@ -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 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr)
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 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr)
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 --git a/usr.bin/netstat/show.c b/usr.bin/netstat/show.c
index bfc054915ef..817e401dbb1 100644
--- a/usr.bin/netstat/show.c
+++ b/usr.bin/netstat/show.c
@@ -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 @@ p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width)
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 @@ routename(struct sockaddr *sa)
(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 --git a/usr.bin/netstat/vtw.c b/usr.bin/netstat/vtw.c
index c093890aed0..031e9b3c8d4 100644
--- a/usr.bin/netstat/vtw.c
+++ b/usr.bin/netstat/vtw.c
@@ -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 @@ show_vtw_v4(void (*print)(const vtw_t *))
/* 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 @@ show_vtw_v4(void (*print)(const vtw_t *))
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 @@ show_vtw_v6(void (*print)(const vtw_t *))
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 @@ show_vtw_v6(void (*print)(const vtw_t *))
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;