From cd8d72036779073e9a559040e5b29558621cdc99 Mon Sep 17 00:00:00 2001 From: des Date: Thu, 15 Mar 2001 20:46:04 +0000 Subject: Add a -W flag that tells netstat not to truncate addresses even if they are too long for the column they're printed in. Move variable definitions out of netstat.h and into main.c. Clean up some warnings. --- usr.bin/netstat/inet.c | 20 +++++++++++++------- usr.bin/netstat/main.c | 32 +++++++++++++++++++++++++++++--- usr.bin/netstat/netstat.1 | 5 ++++- usr.bin/netstat/netstat.h | 43 ++++++++++++++++++++++--------------------- 4 files changed, 68 insertions(+), 32 deletions(-) (limited to 'usr.bin/netstat') diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index b2e3c3e..185506c 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -220,7 +220,7 @@ protopr(proto, name, af) printf("%-14.14s %-22.22s\n", "Listen", "Local Address"); else - printf(Aflag ? + printf((Aflag && !Wflag) ? "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" : "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n", "Proto", "Recv-Q", "Send-Q", @@ -244,7 +244,7 @@ protopr(proto, name, af) } else continue; else { - const u_char *vchar; + const char *vchar; #ifdef INET6 if ((inp->inp_vflag & INP_IPV6) != 0) @@ -695,16 +695,22 @@ inetprint(in, port, proto,numeric) char line[80], *cp; int width; - sprintf(line, "%.*s.", (Aflag && !numeric) ? 12 : 16, inetname(in)); + if (Wflag) + sprintf(line, "%s.", inetname(in)); + else + sprintf(line, "%.*s.", (Aflag && !numeric) ? 12 : 16, inetname(in)); cp = index(line, '\0'); if (!numeric && port) sp = getservbyport((int)port, proto); if (sp || port == 0) - sprintf(cp, "%.15s", sp ? sp->s_name : "*"); + sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); + else + sprintf(cp, "%d ", ntohs((u_short)port)); + width = (Aflag && !Wflag) ? 18 : 22; + if (Wflag) + printf("%-*s ", width, line); else - sprintf(cp, "%d", ntohs((u_short)port)); - width = Aflag ? 18 : 22; - printf("%-*.*s ", width, width, line); + printf("%-*.*s ", width, width, line); } /* diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 5c23f3c..7a11793 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -290,7 +290,30 @@ static struct protox *name2protox __P((char *)); static struct protox *knownname __P((char *)); static kvm_t *kvmd; -char *nlistf = NULL, *memf = NULL; +static char *nlistf = NULL, *memf = NULL; + +int Aflag; /* show addresses of protocol control block */ +int aflag; /* show all sockets (including servers) */ +int bflag; /* show i/f total bytes in/out */ +int dflag; /* show i/f dropped packets */ +int gflag; /* show group (multicast) routing or stats */ +int iflag; /* show interfaces */ +int lflag; /* show routing table with use and ref */ +int Lflag; /* show size of listen queues */ +int mflag; /* show memory stats */ +int nflag; /* show addresses numerically */ +int pflag; /* show given protocol */ +int rflag; /* show routing tables (or routing stats) */ +int sflag; /* show protocol statistics */ +int tflag; /* show i/f watchdog timers */ +int Wflag; /* wide display */ + +int interval; /* repeat interval for i/f stats */ + +char *interface; /* desired i/f for stats, or NULL for all i/fs */ +int unit; /* unit number for above */ + +int af; /* address family */ int main(argc, argv) @@ -302,7 +325,7 @@ main(argc, argv) af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "Aabdf:ghI:lLiM:mN:np:rstuw:")) != -1) + while ((ch = getopt(argc, argv, "Aabdf:ghI:lLiM:mN:np:rstuWw:")) != -1) switch(ch) { case 'A': Aflag = 1; @@ -402,6 +425,9 @@ main(argc, argv) case 'u': af = AF_UNIX; break; + case 'W': + Wflag = 1; + break; case 'w': interval = atoi(optarg); iflag = 1; @@ -696,7 +722,7 @@ static void usage() { (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", -"usage: netstat [-AaLln] [-f address_family] [-M core] [-N system]", +"usage: netstat [-AaLlnW] [-f address_family] [-M core] [-N system]", " netstat [-abdghilmnrs] [-f address_family] [-M core] [-N system]", " netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]", " netstat [-M core] [-N system] [-p protocol]"); diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index 2568227..f81c055 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -40,7 +40,7 @@ .Nd show network status .Sh SYNOPSIS .Nm -.Op Fl AaLln +.Op Fl AaLlnW .Op Fl f Ar address_family .Op Fl M Ar core .Op Fl N Ar system @@ -256,6 +256,9 @@ When is also present, .Nm assumes more columns are there. +.It Fl W +In certain displays, avoid truncating addresses even if this causes +some fields to overflow. .It Fl w Ar wait Show network interface statistics at intervals of .Ar wait diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 6886549..ef297d5 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -36,27 +36,28 @@ #include -int Aflag; /* show addresses of protocol control block */ -int aflag; /* show all sockets (including servers) */ -int bflag; /* show i/f total bytes in/out */ -int dflag; /* show i/f dropped packets */ -int gflag; /* show group (multicast) routing or stats */ -int iflag; /* show interfaces */ -int lflag; /* show routing table with use and ref */ -int Lflag; /* show size of listen queues */ -int mflag; /* show memory stats */ -int nflag; /* show addresses numerically */ -int pflag; /* show given protocol */ -int rflag; /* show routing tables (or routing stats) */ -int sflag; /* show protocol statistics */ -int tflag; /* show i/f watchdog timers */ - -int interval; /* repeat interval for i/f stats */ - -char *interface; /* desired i/f for stats, or NULL for all i/fs */ -int unit; /* unit number for above */ - -int af; /* address family */ +extern int Aflag; /* show addresses of protocol control block */ +extern int aflag; /* show all sockets (including servers) */ +extern int bflag; /* show i/f total bytes in/out */ +extern int dflag; /* show i/f dropped packets */ +extern int gflag; /* show group (multicast) routing or stats */ +extern int iflag; /* show interfaces */ +extern int lflag; /* show routing table with use and ref */ +extern int Lflag; /* show size of listen queues */ +extern int mflag; /* show memory stats */ +extern int nflag; /* show addresses numerically */ +extern int pflag; /* show given protocol */ +extern int rflag; /* show routing tables (or routing stats) */ +extern int sflag; /* show protocol statistics */ +extern int tflag; /* show i/f watchdog timers */ +extern int Wflag; /* wide display */ + +extern int interval; /* repeat interval for i/f stats */ + +extern char *interface; /* desired i/f for stats, or NULL for all i/fs */ +extern int unit; /* unit number for above */ + +extern int af; /* address family */ int kread __P((u_long addr, char *buf, int size)); char *plural __P((int)); -- cgit v1.1