Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/netstat Use sysctl based code netstat -r. Remove sup...
details: https://anonhg.NetBSD.org/src/rev/dfce65e17be8
branches: trunk
changeset: 784428:dfce65e17be8
user: joerg <joerg%NetBSD.org@localhost>
date: Mon Jan 28 13:49:08 2013 +0000
description:
Use sysctl based code netstat -r. Remove support for post-mortem
analysis.
diffstat:
usr.bin/netstat/main.c | 13 +-
usr.bin/netstat/netstat.h | 4 +-
usr.bin/netstat/route.c | 295 +---------------------------------------------
3 files changed, 10 insertions(+), 302 deletions(-)
diffs (truncated from 386 to 300 lines):
diff -r 0ffc84a2771d -r dfce65e17be8 usr.bin/netstat/main.c
--- a/usr.bin/netstat/main.c Mon Jan 28 13:46:47 2013 +0000
+++ b/usr.bin/netstat/main.c Mon Jan 28 13:49:08 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.83 2012/03/22 20:34:43 drochner Exp $ */
+/* $NetBSD: main.c,v 1.84 2013/01/28 13:49:08 joerg Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
#else
-__RCSID("$NetBSD: main.c,v 1.83 2012/03/22 20:34:43 drochner Exp $");
+__RCSID("$NetBSD: main.c,v 1.84 2013/01/28 13:49:08 joerg Exp $");
#endif
#endif /* not lint */
@@ -393,7 +393,6 @@
/* If we have -M and -N, we're not dealing with live memory. */
use_sysctl = 0;
} else if (qflag ||
- rflag ||
iflag ||
#ifndef SMALL
gflag ||
@@ -661,10 +660,10 @@
if (sflag)
rt_stats(use_sysctl ? 0 : nl[N_RTSTAT].n_value);
else {
- if (use_sysctl)
- p_rttables(af);
- else
- routepr(nl[N_RTREE].n_value);
+ if (!use_sysctl)
+ err(1, "-r is not supported "
+ "for post-mortem analysis.");
+ p_rttables(af);
}
exit(0);
}
diff -r 0ffc84a2771d -r dfce65e17be8 usr.bin/netstat/netstat.h
--- a/usr.bin/netstat/netstat.h Mon Jan 28 13:46:47 2013 +0000
+++ b/usr.bin/netstat/netstat.h Mon Jan 28 13:49:08 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netstat.h,v 1.44 2012/03/22 20:34:43 drochner Exp $ */
+/* $NetBSD: netstat.h,v 1.45 2013/01/28 13:49:08 joerg Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -118,7 +118,6 @@
void pr_family __P((int));
void rt_stats __P((u_long));
char *ns_phost __P((struct sockaddr *));
-void upHex __P((char *));
void p_rttables(int);
void p_flags(int, const char *);
@@ -139,7 +138,6 @@
const char *atalk_print2 __P((const struct sockaddr *, const struct sockaddr *,
int));
char *ns_print __P((struct sockaddr *));
-void routepr __P((u_long));
void nsprotopr __P((u_long, const char *));
void spp_stats __P((u_long, const char *));
diff -r 0ffc84a2771d -r dfce65e17be8 usr.bin/netstat/route.c
--- a/usr.bin/netstat/route.c Mon Jan 28 13:46:47 2013 +0000
+++ b/usr.bin/netstat/route.c Mon Jan 28 13:49:08 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.79 2012/03/20 20:34:58 matt Exp $ */
+/* $NetBSD: route.c,v 1.80 2013/01/28 13:49:08 joerg Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -30,287 +30,15 @@
*/
#include <sys/cdefs.h>
-#ifndef lint
-#if 0
-static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
-#else
-__RCSID("$NetBSD: route.c,v 1.79 2012/03/20 20:34:58 matt Exp $");
-#endif
-#endif /* not lint */
-#include <stdbool.h>
-#include <sys/param.h>
-#include <sys/protosw.h>
-#include <sys/socket.h>
-#include <sys/mbuf.h>
-#include <sys/un.h>
-
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/if_types.h>
-#include <net/route.h>
-#include <netinet/in.h>
-#include <netatalk/at.h>
-#include <netiso/iso.h>
-#include <netmpls/mpls.h>
+__RCSID("$NetBSD: route.c,v 1.80 2013/01/28 13:49:08 joerg Exp $");
#include <sys/sysctl.h>
-
-#include <arpa/inet.h>
-
+#include <net/route.h>
#include <err.h>
-#include <kvm.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
#include "netstat.h"
-#define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
-
-/*
- * XXX we put all of the sockaddr types in here to force the alignment
- * to be correct.
- */
-static union sockaddr_union {
- struct sockaddr u_sa;
- struct sockaddr_in u_in;
- struct sockaddr_un u_un;
- struct sockaddr_iso u_iso;
- struct sockaddr_at u_at;
- struct sockaddr_dl u_dl;
- u_short u_data[128];
- int u_dummy; /* force word-alignment */
-} pt_u;
-
-int do_rtent = 0;
-struct rtentry rtentry;
-struct radix_node rnode;
-struct radix_mask rmask;
-
-static struct sockaddr *kgetsa(const struct sockaddr *);
-static void p_tree(struct radix_node *);
-static void p_rtnode(void);
-static void p_krtentry(struct rtentry *);
-
-/*
- * Print routing tables.
- */
-void
-routepr(u_long rtree)
-{
- struct radix_node_head *rnh, head;
- struct radix_node_head *rt_nodes[AF_MAX+1];
- int i;
-
- printf("Routing tables\n");
-
- if (rtree == 0) {
- printf("rt_tables: symbol not in namelist\n");
- return;
- }
-
- kget(rtree, rt_nodes);
- for (i = 0; i <= AF_MAX; i++) {
- if ((rnh = rt_nodes[i]) == 0)
- continue;
- kget(rnh, head);
- if (i == AF_UNSPEC) {
- if (Aflag && (af == 0 || af == 0xff)) {
- printf("Netmasks:\n");
- p_tree(head.rnh_treetop);
- }
- } else if (af == AF_UNSPEC || af == i) {
- pr_family(i);
- do_rtent = 1;
- pr_rthdr(i, Aflag);
- p_tree(head.rnh_treetop);
- }
- }
-}
-
-static struct sockaddr *
-kgetsa(const struct sockaddr *dst)
-{
-
- kget(dst, pt_u.u_sa);
- if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
- kread((u_long)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len);
- return (&pt_u.u_sa);
-}
-
-static void
-p_tree(struct radix_node *rn)
-{
-
-again:
- kget(rn, rnode);
- if (rnode.rn_b < 0) {
- if (Aflag)
- printf("%-8.8lx ", (u_long) rn);
- if (rnode.rn_flags & RNF_ROOT) {
- if (Aflag)
- printf("(root node)%s",
- rnode.rn_dupedkey ? " =>\n" : "\n");
- } else if (do_rtent) {
- kget(rn, rtentry);
- p_krtentry(&rtentry);
- if (Aflag)
- p_rtnode();
- } else {
- p_sockaddr(kgetsa((const struct sockaddr *)rnode.rn_key),
- NULL, 0, 44);
- putchar('\n');
- }
- if ((rn = rnode.rn_dupedkey) != NULL)
- goto again;
- } else {
- if (Aflag && do_rtent) {
- printf("%-8.8lx ", (u_long) rn);
- p_rtnode();
- }
- rn = rnode.rn_r;
- p_tree(rnode.rn_l);
- p_tree(rn);
- }
-}
-
-static void
-p_rtnode(void)
-{
- struct radix_mask *rm = rnode.rn_mklist;
- char nbuf[20];
-
- if (rnode.rn_b < 0) {
- if (rnode.rn_mask) {
- printf("\t mask ");
- p_sockaddr(kgetsa((const struct sockaddr *)rnode.rn_mask),
- NULL, 0, -1);
- } else if (rm == 0)
- return;
- } else {
- (void)snprintf(nbuf, sizeof nbuf, "(%d)", rnode.rn_b);
- printf("%6.6s %8.8lx : %8.8lx", nbuf, (u_long) rnode.rn_l,
- (u_long) rnode.rn_r);
- }
- while (rm) {
- kget(rm, rmask);
- (void)snprintf(nbuf, sizeof nbuf, " %d refs, ", rmask.rm_refs);
- printf(" mk = %8.8lx {(%d),%s", (u_long) rm,
- -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " ");
- if (rmask.rm_flags & RNF_NORMAL) {
- struct radix_node rnode_aux;
- printf(" <normal>, ");
- kget(rmask.rm_leaf, rnode_aux);
- p_sockaddr(kgetsa((const struct sockaddr *)rnode_aux.rn_mask),
- NULL, 0, -1);
- } else
- p_sockaddr(kgetsa((const struct sockaddr *)rmask.rm_mask),
- NULL, 0, -1);
- putchar('}');
- if ((rm = rmask.rm_mklist) != NULL)
- printf(" ->");
- }
- putchar('\n');
-}
-
-static struct sockaddr *sockcopy(struct sockaddr *, union sockaddr_union *);
-
-/*
- * copy a sockaddr into an allocated region, allocate at least sockaddr
- * bytes and zero unused
- */
-static struct sockaddr *
-sockcopy(struct sockaddr *sp, union sockaddr_union *dp)
-{
- int len;
-
- if (sp == 0 || sp->sa_len == 0)
- (void)memset(dp, 0, sizeof (*sp));
- else {
- len = (sp->sa_len >= sizeof (*sp)) ? sp->sa_len : sizeof (*sp);
- (void)memcpy(dp, sp, len);
- }
- return ((struct sockaddr *)dp);
-}
-
-static void
-p_krtentry(struct rtentry *rt)
-{
- static struct ifnet ifnet, *lastif;
- union sockaddr_union addr_un, mask_un;
- struct sockaddr *addr, *mask;
-
- if (Lflag && (rt->rt_flags & RTF_LLINFO))
- return;
-
- memset(&addr_un, 0, sizeof(addr_un));
- memset(&mask_un, 0, sizeof(mask_un));
- addr = sockcopy(kgetsa(rt_getkey(rt)), &addr_un);
Home |
Main Index |
Thread Index |
Old Index