Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat KNF



details:   https://anonhg.NetBSD.org/src/rev/36783207d65a
branches:  trunk
changeset: 532206:36783207d65a
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Jun 02 15:25:42 2002 +0000

description:
KNF

diffstat:

 usr.bin/netstat/ipsec.c   |  143 ++++++++++++++++-----------------------------
 usr.bin/netstat/mroute6.c |   55 ++++++++---------
 2 files changed, 76 insertions(+), 122 deletions(-)

diffs (truncated from 345 to 300 lines):

diff -r bb0d379aa163 -r 36783207d65a usr.bin/netstat/ipsec.c
--- a/usr.bin/netstat/ipsec.c   Sun Jun 02 15:17:17 2002 +0000
+++ b/usr.bin/netstat/ipsec.c   Sun Jun 02 15:25:42 2002 +0000
@@ -1,4 +1,5 @@
-/*     $NetBSD: ipsec.c,v 1.5 2002/03/21 04:23:38 itojun Exp $ */
+/*     $NetBSD: ipsec.c,v 1.6 2002/06/02 15:30:29 itojun Exp $ */
+/*     $KAME: ipsec.c,v 1.28 2002/06/02 15:27:40 itojun Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
@@ -68,7 +69,7 @@
 static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
 #else
 #ifdef __NetBSD__
-__RCSID("$NetBSD: ipsec.c,v 1.5 2002/03/21 04:23:38 itojun Exp $");
+__RCSID("$NetBSD: ipsec.c,v 1.6 2002/06/02 15:30:29 itojun Exp $");
 #endif
 #endif
 #endif /* not lint */
@@ -89,26 +90,6 @@
 #include <unistd.h>
 #include "netstat.h"
 
-/*
- * portability issues:
- * - bsdi[34] uses PLURAL(), not plural().
- * - freebsd2 can't print "unsigned long long" properly.
- */
-#ifdef __bsdi__
-#define plural(x)      PLURAL(x)
-#define plurales(x)    PLURALES(x)
-#endif
-/*
- * XXX see PORTABILITY for the twist
- */
-#if defined(__FreeBSD__) && __FreeBSD__ < 3
-#define LLU    "%qu"
-#define CAST   u_quad_t
-#else
-#define LLU    "%llu"
-#define CAST   unsigned long long
-#endif
-
 #ifdef IPSEC 
 struct val2str {
        int val;
@@ -130,9 +111,6 @@
        { SADB_EALG_DESCBC, "des-cbc", },
        { SADB_EALG_3DESCBC, "3des-cbc", },
        { SADB_EALG_NULL, "null", },
-#ifdef SADB_X_EALG_RC5CBC
-       { SADB_X_EALG_RC5CBC, "rc5-cbc", },
-#endif
        { SADB_X_EALG_CAST128CBC, "cast128-cbc", },
        { SADB_X_EALG_BLOWFISHCBC, "blowfish-cbc", },
 #ifdef SADB_X_EALG_RIJNDAELCBC
@@ -159,14 +137,6 @@
 
 static struct ipsecstat ipsecstat;
 
-#if defined(__bsdi__) && _BSDI_VERSION >= 199802
-struct data_info ipsecstat_info = {    /* for bsdi4 only */
-       "_ipsecstat",
-       NULL, 0,
-       &ipsecstat, sizeof(struct ipsecstat)
-};
-#endif
-
 static void print_ipsecstats __P((void));
 static const char *pfkey_msgtype_names __P((int));
 static void ipsec_hist __P((const u_quad_t *, size_t, const struct val2str *,
@@ -200,10 +170,10 @@
                                break;
                }
                if (p && p->str) {
-                       printf("\t\t%s: " LLU "\n", p->str, (CAST)hist[proto]);
+                       printf("\t\t%s: %llu\n", p->str, (unsigned long long)hist[proto]);
                } else {
-                       printf("\t\t#%ld: " LLU "\n", (long)proto,
-                           (CAST)hist[proto]);
+                       printf("\t\t#%ld: %llu\n", (long)proto,
+                           (unsigned long long)hist[proto]);
                }
        }
 }
@@ -212,39 +182,39 @@
 print_ipsecstats()
 {
 #define        p(f, m) if (ipsecstat.f || sflag <= 1) \
-    printf(m, (CAST)ipsecstat.f, plural(ipsecstat.f))
+    printf(m, (unsigned long long)ipsecstat.f, plural(ipsecstat.f))
 #define        pes(f, m) if (ipsecstat.f || sflag <= 1) \
-    printf(m, (CAST)ipsecstat.f, plurales(ipsecstat.f))
+    printf(m, (unsigned long long)ipsecstat.f, plurales(ipsecstat.f))
 #define hist(f, n, t) \
     ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), sizeof(n)/sizeof(n[0]), (t));
 
-       p(in_success, "\t" LLU " inbound packet%s processed successfully\n");
-       p(in_polvio, "\t" LLU " inbound packet%s violated process security "
-               "policy\n");
-       p(in_nosa, "\t" LLU " inbound packet%s with no SA available\n");
-       p(in_inval, "\t" LLU " invalid inbound packet%s\n");
-       p(in_nomem, "\t" LLU " inbound packet%s failed due to insufficient memory\n");
-       p(in_badspi, "\t" LLU " inbound packet%s failed getting SPI\n");
-       p(in_ahreplay, "\t" LLU " inbound packet%s failed on AH replay check\n");
-       p(in_espreplay, "\t" LLU " inbound packet%s failed on ESP replay check\n");
-       p(in_ahauthsucc, "\t" LLU " inbound packet%s considered authentic\n");
-       p(in_ahauthfail, "\t" LLU " inbound packet%s failed on authentication\n");
+       p(in_success, "\t%llu inbound packet%s processed successfully\n");
+       p(in_polvio, "\t%llu inbound packet%s violated process security "
+           "policy\n");
+       p(in_nosa, "\t%llu inbound packet%s with no SA available\n");
+       p(in_inval, "\t%llu invalid inbound packet%s\n");
+       p(in_nomem, "\t%llu inbound packet%s failed due to insufficient memory\n");
+       p(in_badspi, "\t%llu inbound packet%s failed getting SPI\n");
+       p(in_ahreplay, "\t%llu inbound packet%s failed on AH replay check\n");
+       p(in_espreplay, "\t%llu inbound packet%s failed on ESP replay check\n");
+       p(in_ahauthsucc, "\t%llu inbound packet%s considered authentic\n");
+       p(in_ahauthfail, "\t%llu inbound packet%s failed on authentication\n");
        hist(ipsecstat.in_ahhist, ipsec_ahnames, "AH input");
        hist(ipsecstat.in_esphist, ipsec_espnames, "ESP input");
        hist(ipsecstat.in_comphist, ipsec_compnames, "IPComp input");
 
-       p(out_success, "\t" LLU " outbound packet%s processed successfully\n");
-       p(out_polvio, "\t" LLU " outbound packet%s violated process security "
-               "policy\n");
-       p(out_nosa, "\t" LLU " outbound packet%s with no SA available\n");
-       p(out_inval, "\t" LLU " invalid outbound packet%s\n");
-       p(out_nomem, "\t" LLU " outbound packet%s failed due to insufficient memory\n");
-       p(out_noroute, "\t" LLU " outbound packet%s with no route\n");
+       p(out_success, "\t%llu outbound packet%s processed successfully\n");
+       p(out_polvio, "\t%llu outbound packet%s violated process security "
+           "policy\n");
+       p(out_nosa, "\t%llu outbound packet%s with no SA available\n");
+       p(out_inval, "\t%llu invalid outbound packet%s\n");
+       p(out_nomem, "\t%llu outbound packet%s failed due to insufficient memory\n");
+       p(out_noroute, "\t%llu outbound packet%s with no route\n");
        hist(ipsecstat.out_ahhist, ipsec_ahnames, "AH output");
        hist(ipsecstat.out_esphist, ipsec_espnames, "ESP output");
        hist(ipsecstat.out_comphist, ipsec_compnames, "IPComp output");
-       p(spdcachelookup, "\t" LLU " SPD cache lookup%s\n");
-       pes(spdcachemiss, "\t" LLU " SPD cache miss%s\n");
+       p(spdcachelookup, "\t%llu SPD cache lookup%s\n");
+       pes(spdcachemiss, "\t%llu SPD cache miss%s\n");
 #undef p
 #undef pes
 #undef hist
@@ -263,19 +233,6 @@
        print_ipsecstats();
 }
 
-#if defined(__bsdi__) && _BSDI_VERSION >= 199802 /* bsdi4 only */
-void
-ipsec_stats0(name)
-       char *name;
-{
-       printf("%s:\n", name);
-
-       skread(name, &ipsecstat_info);
-
-       print_ipsecstats();
-}
-#endif
-
 static const char *
 pfkey_msgtype_names(x)
        int x;
@@ -304,11 +261,11 @@
        kread(off, (char *)&pfkeystat, sizeof(pfkeystat));
 
 #define        p(f, m) if (pfkeystat.f || sflag <= 1) \
-    printf(m, (CAST)pfkeystat.f, plural(pfkeystat.f))
+    printf(m, (unsigned long long)pfkeystat.f, plural(pfkeystat.f))
 
        /* userland -> kernel */
-       p(out_total, "\t" LLU " request%s sent from userland\n");
-       p(out_bytes, "\t" LLU " byte%s sent from userland\n");
+       p(out_total, "\t%llu request%s sent from userland\n");
+       p(out_bytes, "\t%llu byte%s sent from userland\n");
        for (first = 1, type = 0;
             type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]);
             type++) {
@@ -318,22 +275,22 @@
                        printf("\thistogram by message type:\n");
                        first = 0;
                }
-               printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
-                       (CAST)pfkeystat.out_msgtype[type]);
+               printf("\t\t%s: %llu\n", pfkey_msgtype_names(type),
+                   (unsigned long long)pfkeystat.out_msgtype[type]);
        }
-       p(out_invlen, "\t" LLU " message%s with invalid length field\n");
-       p(out_invver, "\t" LLU " message%s with invalid version field\n");
-       p(out_invmsgtype, "\t" LLU " message%s with invalid message type field\n");
-       p(out_tooshort, "\t" LLU " message%s too short\n");
-       p(out_nomem, "\t" LLU " message%s with memory allocation failure\n");
-       p(out_dupext, "\t" LLU " message%s with duplicate extension\n");
-       p(out_invexttype, "\t" LLU " message%s with invalid extension type\n");
-       p(out_invsatype, "\t" LLU " message%s with invalid sa type\n");
-       p(out_invaddr, "\t" LLU " message%s with invalid address extension\n");
+       p(out_invlen, "\t%llu message%s with invalid length field\n");
+       p(out_invver, "\t%llu message%s with invalid version field\n");
+       p(out_invmsgtype, "\t%llu message%s with invalid message type field\n");
+       p(out_tooshort, "\t%llu message%s too short\n");
+       p(out_nomem, "\t%llu message%s with memory allocation failure\n");
+       p(out_dupext, "\t%llu message%s with duplicate extension\n");
+       p(out_invexttype, "\t%llu message%s with invalid extension type\n");
+       p(out_invsatype, "\t%llu message%s with invalid sa type\n");
+       p(out_invaddr, "\t%llu message%s with invalid address extension\n");
 
        /* kernel -> userland */
-       p(in_total, "\t" LLU " request%s sent to userland\n");
-       p(in_bytes, "\t" LLU " byte%s sent to userland\n");
+       p(in_total, "\t%llu request%s sent to userland\n");
+       p(in_bytes, "\t%llu byte%s sent to userland\n");
        for (first = 1, type = 0;
             type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]);
             type++) {
@@ -343,16 +300,16 @@
                        printf("\thistogram by message type:\n");
                        first = 0;
                }
-               printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type),
-                       (CAST)pfkeystat.in_msgtype[type]);
+               printf("\t\t%s: %llu\n", pfkey_msgtype_names(type),
+                   (unsigned long long)pfkeystat.in_msgtype[type]);
        }
        p(in_msgtarget[KEY_SENDUP_ONE],
-           "\t" LLU " message%s toward single socket\n");
+           "\t%llu message%s toward single socket\n");
        p(in_msgtarget[KEY_SENDUP_ALL],
-           "\t" LLU " message%s toward all sockets\n");
+           "\t%llu message%s toward all sockets\n");
        p(in_msgtarget[KEY_SENDUP_REGISTERED],
-           "\t" LLU " message%s toward registered sockets\n");
-       p(in_nomem, "\t" LLU " message%s with memory allocation failure\n");
+           "\t%llu message%s toward registered sockets\n");
+       p(in_nomem, "\t%llu message%s with memory allocation failure\n");
 #undef p
 }
 #endif /*IPSEC*/
diff -r bb0d379aa163 -r 36783207d65a usr.bin/netstat/mroute6.c
--- a/usr.bin/netstat/mroute6.c Sun Jun 02 15:17:17 2002 +0000
+++ b/usr.bin/netstat/mroute6.c Sun Jun 02 15:25:42 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mroute6.c,v 1.8 2001/05/28 04:22:56 assar Exp $        */
+/*     $NetBSD: mroute6.c,v 1.9 2002/06/02 15:25:42 itojun Exp $       */
 
 /*
  * Copyright (C) 1998 WIDE Project.
@@ -114,18 +114,17 @@
 
        kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
        switch (mrtproto) {
-
-        case 0:
-                printf("no IPv6 multicast routing compiled into this system\n");
-                return;
+       case 0:
+               printf("no IPv6 multicast routing compiled into this system\n");
+               return;
 
-        case IPPROTO_PIM:
-                break;
+       case IPPROTO_PIM:
+               break;
 
-        default:
-                printf("IPv6 multicast routing protocol %u, unknown\n",
-                       mrtproto);
-                return;
+       default:
+               printf("IPv6 multicast routing protocol %u, unknown\n",
+                   mrtproto);
+               return;
        }
 
        if (mfcaddr == 0) {
@@ -153,15 +152,13 @@
                maxmif = mifi;
                if (!banner_printed) {
                        printf("\nIPv6 Multicast Interface Table\n"
-                              " Mif   Rate   PhyIF   "
-                              "Pkts-In   Pkts-Out\n");
+                           " Mif   Rate   PhyIF   Pkts-In   Pkts-Out\n");
                        banner_printed = 1;
                }
 
-               printf("  %2u   %4d",
-                      mifi, mifp->m6_rate_limit);
+               printf("  %2u   %4d", mifi, mifp->m6_rate_limit);
                printf("   %5s", (mifp->m6_flags & MIFF_REGISTER) ?
-                      "reg0" : if_indextoname(ifnet.if_index, ifname));
+                   "reg0" : if_indextoname(ifnet.if_index, ifname));
 
                printf(" %9llu  %9llu\n", (unsigned long long)mifp->m6_pkt_in,
                    (unsigned long long)mifp->m6_pkt_out);
@@ -178,16 +175,16 @@
                        if (!banner_printed) {
                                printf ("\nIPv6 Multicast Forwarding Cache\n");



Home | Main Index | Thread Index | Old Index