From b52bf20b5bfa797405ebab3dac9abbb1804889c7 Mon Sep 17 00:00:00 2001 From: ume Date: Thu, 5 Feb 2004 11:59:37 +0000 Subject: - %d is 12 chars, not 10. use NI_MAX* where appropriate. - goodbye RC5. - use %llu directly. - KNF. Obtained from: KAME --- usr.bin/netstat/ipsec.c | 119 +++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 67 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/netstat/ipsec.c b/usr.bin/netstat/ipsec.c index e0316aa..2b1a56a 100644 --- a/usr.bin/netstat/ipsec.c +++ b/usr.bin/netstat/ipsec.c @@ -65,11 +65,12 @@ #include #ifndef lint -/* -static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; -*/ +#if 0 +static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; +#else static const char rcsid[] = "$FreeBSD$"; +#endif #endif /* not lint */ #include @@ -88,17 +89,6 @@ static const char rcsid[] = #include #include "netstat.h" -/* - * portability issues: - * - bsdi[34] uses PLURAL(), not plural(). - * - freebsd2 can't print "unsigned long long" properly. - */ -/* - * XXX see PORTABILITY for the twist - */ -#define LLU "%llu" -#define CAST unsigned long long - #ifdef IPSEC struct val2str { int val; @@ -129,9 +119,6 @@ static struct val2str ipsec_espnames[] = { { 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 @@ -167,9 +154,7 @@ static void ipsec_hist (const u_quad_t *, size_t, const struct val2str *, * Dump IPSEC statistics structure. */ static void -ipsec_hist(const u_quad_t *hist, - size_t histmax, - const struct val2str *name, +ipsec_hist(const u_quad_t *hist, size_t histmax, const struct val2str *name, const char *title) { int first; @@ -189,10 +174,10 @@ ipsec_hist(const u_quad_t *hist, 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]); } } } @@ -201,32 +186,32 @@ static void print_ipsecstats(void) { #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 hist(f, n, t) \ ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), (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"); @@ -250,7 +235,7 @@ pfkey_msgtype_names(int x) { const int max = sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]); - static char buf[10]; + static char buf[20]; if (x < max && pfkey_msgtypenames[x]) return pfkey_msgtypenames[x]; @@ -270,11 +255,11 @@ pfkey_stats(u_long off __unused, const char *name, int af1 __unused) 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)) - /* kernel -> userland */ - p(out_total, "\t" LLU " request%s sent to userland\n"); - p(out_bytes, "\t" LLU " byte%s sent to userland\n"); + /* userland -> kernel */ + 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++) { @@ -284,22 +269,22 @@ pfkey_stats(u_long off __unused, const char *name, int af1 __unused) 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"); - /* userland -> kernel */ - p(in_total, "\t" LLU " request%s sent from userland\n"); - p(in_bytes, "\t" LLU " byte%s sent from userland\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"); for (first = 1, type = 0; type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]); type++) { @@ -309,16 +294,16 @@ pfkey_stats(u_long off __unused, const char *name, int af1 __unused) 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*/ -- cgit v1.1