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.
This commit is contained in:
parent
9b860e1c34
commit
080b7f4967
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=74311
@ -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 ? 18 : 22;
|
||||
printf("%-*.*s ", width, width, line);
|
||||
sprintf(cp, "%d ", ntohs((u_short)port));
|
||||
width = (Aflag && !Wflag) ? 18 : 22;
|
||||
if (Wflag)
|
||||
printf("%-*s ", width, line);
|
||||
else
|
||||
printf("%-*.*s ", width, width, line);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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]");
|
||||
|
@ -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
|
||||
|
@ -36,27 +36,28 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
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 */
|
||||
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 */
|
||||
|
||||
int interval; /* repeat interval for i/f stats */
|
||||
extern 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 */
|
||||
extern char *interface; /* desired i/f for stats, or NULL for all i/fs */
|
||||
extern int unit; /* unit number for above */
|
||||
|
||||
int af; /* address family */
|
||||
extern int af; /* address family */
|
||||
|
||||
int kread __P((u_long addr, char *buf, int size));
|
||||
char *plural __P((int));
|
||||
|
Loading…
Reference in New Issue
Block a user