mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-01 08:27:59 +00:00
add the option -S for printing port numbers symbolically but addresses
numerically. clean up the CFLAGS in Makefile.
This commit is contained in:
parent
953d6e00e9
commit
65ea0024ba
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78238
@ -6,6 +6,7 @@ SRCS= if.c inet.c inet6.c main.c mbuf.c mroute.c ipx.c route.c \
|
||||
unix.c atalk.c netgraph.c mroute6.c ipsec.c # iso.c ns.c tp_astring.c
|
||||
CFLAGS+=-Wall
|
||||
CFLAGS+=-DIPSEC
|
||||
CFLAGS+=-DINET6
|
||||
|
||||
#CFLAGS+=-g
|
||||
#.PATH: ${.CURDIR}/../../sys/netiso
|
||||
@ -13,6 +14,5 @@ BINGRP= kmem
|
||||
BINMODE=2555
|
||||
DPADD= ${LIBKVM} ${LIBIPX} ${LIBNETGRAPH} ${LIBUTIL}
|
||||
LDADD= -lkvm -lipx -lnetgraph -lutil
|
||||
CFLAGS+=-DINET6 -DIPSEC
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -259,7 +259,7 @@ protopr(proto, name, af)
|
||||
so->so_rcv.sb_cc,
|
||||
so->so_snd.sb_cc);
|
||||
}
|
||||
if (nflag) {
|
||||
if (numeric_port) {
|
||||
if (inp->inp_vflag & INP_IPV4) {
|
||||
inetprint(&inp->inp_laddr, (int)inp->inp_lport,
|
||||
name, 1);
|
||||
@ -686,11 +686,11 @@ igmp_stats(off, name)
|
||||
* Pretty print an Internet address (net address + port).
|
||||
*/
|
||||
void
|
||||
inetprint(in, port, proto,numeric)
|
||||
inetprint(in, port, proto, numeric_port)
|
||||
register struct in_addr *in;
|
||||
int port;
|
||||
char *proto;
|
||||
int numeric;
|
||||
int numeric_port;
|
||||
{
|
||||
struct servent *sp = 0;
|
||||
char line[80], *cp;
|
||||
@ -699,9 +699,9 @@ inetprint(in, port, proto,numeric)
|
||||
if (Wflag)
|
||||
sprintf(line, "%s.", inetname(in));
|
||||
else
|
||||
sprintf(line, "%.*s.", (Aflag && !numeric) ? 12 : 16, inetname(in));
|
||||
sprintf(line, "%.*s.", (Aflag && !numeric_port) ? 12 : 16, inetname(in));
|
||||
cp = index(line, '\0');
|
||||
if (!numeric && port)
|
||||
if (!numeric_port && port)
|
||||
sp = getservbyport((int)port, proto);
|
||||
if (sp || port == 0)
|
||||
sprintf(cp, "%.15s ", sp ? sp->s_name : "*");
|
||||
@ -716,7 +716,7 @@ inetprint(in, port, proto,numeric)
|
||||
|
||||
/*
|
||||
* Construct an Internet address representation.
|
||||
* If the nflag has been supplied, give
|
||||
* If numeric_addr has been supplied, give
|
||||
* numeric value, otherwise try for symbolic name.
|
||||
*/
|
||||
char *
|
||||
@ -729,7 +729,7 @@ inetname(inp)
|
||||
struct netent *np;
|
||||
|
||||
cp = 0;
|
||||
if (!nflag && inp->s_addr != INADDR_ANY) {
|
||||
if (!numeric_addr && inp->s_addr != INADDR_ANY) {
|
||||
int net = inet_netof(*inp);
|
||||
int lna = inet_lnaof(*inp);
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ rip6_stats(off, name)
|
||||
|
||||
/*
|
||||
* Pretty print an Internet address (net address + port).
|
||||
* If the nflag was specified, use numbers instead of names.
|
||||
* Take numeric_addr and numeric_port into consideration.
|
||||
*/
|
||||
#define GETSERVBYPORT6(port, proto, ret)\
|
||||
{\
|
||||
@ -1060,7 +1060,7 @@ inet6print(in6, port, proto, numeric)
|
||||
|
||||
/*
|
||||
* Construct an Internet address representation.
|
||||
* If the nflag has been supplied, give
|
||||
* If the numeric_addr has been supplied, give
|
||||
* numeric value, otherwise try for symbolic name.
|
||||
*/
|
||||
|
||||
@ -1074,7 +1074,7 @@ inet6name(in6p)
|
||||
static char domain[MAXHOSTNAMELEN];
|
||||
static int first = 1;
|
||||
|
||||
if (first && !nflag) {
|
||||
if (first && !numeric_addr) {
|
||||
first = 0;
|
||||
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
|
||||
(cp = index(domain, '.')))
|
||||
@ -1083,7 +1083,7 @@ inet6name(in6p)
|
||||
domain[0] = 0;
|
||||
}
|
||||
cp = 0;
|
||||
if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
|
||||
if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
|
||||
hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
|
||||
if (hp) {
|
||||
if ((cp = index(hp->h_name, '.')) &&
|
||||
|
@ -366,7 +366,8 @@ tp_inproto(pcb)
|
||||
|
||||
/*
|
||||
* Pretty print an iso address (net address + port).
|
||||
* If the nflag was specified, use numbers instead of names.
|
||||
* If the numeric_addr or numeric_port were specified,
|
||||
* use numbers instead of names.
|
||||
*/
|
||||
|
||||
#ifdef notdef
|
||||
@ -387,7 +388,7 @@ isonetname(iso)
|
||||
sa.siso_addr = *iso;
|
||||
sa.siso_tsuffix = 0;
|
||||
|
||||
if (!nflag )
|
||||
if ( !numeric_addr )
|
||||
ihe = iso_gethostentrybyaddr( &sa, 0, 0 );
|
||||
if( ihe ) {
|
||||
Ihe = *ihe;
|
||||
@ -426,7 +427,7 @@ isonetprint(iso, sufx, sufxlen, islocal)
|
||||
if(Aflag)
|
||||
islocal += 10 ;
|
||||
|
||||
if(!nflag) {
|
||||
if(!numeric_addr) {
|
||||
if( (cp -line)>10 ) {
|
||||
cp = line+10;
|
||||
bzero(cp, sizeof(line)-10);
|
||||
@ -435,7 +436,7 @@ isonetprint(iso, sufx, sufxlen, islocal)
|
||||
|
||||
*cp++ = '.';
|
||||
if(sufxlen) {
|
||||
if( !Aflag && !nflag && (ihe=iso_getserventrybytsel(sufx, sufxlen))) {
|
||||
if( !Aflag && !numeric_port && (ihe=iso_getserventrybytsel(sufx, sufxlen))) {
|
||||
Ihe = *ihe;
|
||||
ihe = &Ihe;
|
||||
}
|
||||
|
@ -311,7 +311,8 @@ 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 numeric_addr; /* show addresses numerically */
|
||||
int numeric_port; /* show ports numerically */
|
||||
int pflag; /* show given protocol */
|
||||
int rflag; /* show routing tables (or routing stats) */
|
||||
int sflag; /* show protocol statistics */
|
||||
@ -335,7 +336,7 @@ main(argc, argv)
|
||||
|
||||
af = AF_UNSPEC;
|
||||
|
||||
while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rstuWw:")) != -1)
|
||||
while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rsStuWw:")) != -1)
|
||||
switch(ch) {
|
||||
case 'A':
|
||||
Aflag = 1;
|
||||
@ -413,7 +414,7 @@ main(argc, argv)
|
||||
nlistf = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
numeric_addr = numeric_port = 1;
|
||||
break;
|
||||
case 'p':
|
||||
if ((tp = name2protox(optarg)) == NULL) {
|
||||
@ -429,6 +430,9 @@ main(argc, argv)
|
||||
case 's':
|
||||
++sflag;
|
||||
break;
|
||||
case 'S':
|
||||
numeric_addr = 1;
|
||||
break;
|
||||
case 't':
|
||||
tflag = 1;
|
||||
break;
|
||||
@ -740,7 +744,7 @@ usage()
|
||||
{
|
||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
|
||||
"usage: netstat [-AaLlnW] [-f address_family] [-M core] [-N system]",
|
||||
" netstat [-abdgilnrs] [-f address_family] [-M core] [-N system]",
|
||||
" netstat [-abdgilnrsS] [-f address_family] [-M core] [-N system]",
|
||||
" netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]",
|
||||
" netstat -m [-M core] [-N system]",
|
||||
" netstat [-M core] [-N system] [-p protocol]");
|
||||
|
@ -77,7 +77,7 @@ mroutepr(mfcaddr, vifaddr)
|
||||
register vifi_t vifi;
|
||||
register int i;
|
||||
register int banner_printed;
|
||||
register int saved_nflag;
|
||||
register int saved_numeric_addr;
|
||||
vifi_t maxvif = 0;
|
||||
|
||||
if (mfcaddr == 0 || vifaddr == 0) {
|
||||
@ -85,8 +85,8 @@ mroutepr(mfcaddr, vifaddr)
|
||||
return;
|
||||
}
|
||||
|
||||
saved_nflag = nflag;
|
||||
nflag = 1;
|
||||
saved_numeric_addr = numeric_addr;
|
||||
numeric_addr = 1;
|
||||
|
||||
kread(vifaddr, (char *)&viftable, sizeof(viftable));
|
||||
banner_printed = 0;
|
||||
@ -145,7 +145,7 @@ mroutepr(mfcaddr, vifaddr)
|
||||
printf("\nMulticast Routing Table is empty\n");
|
||||
|
||||
printf("\n");
|
||||
nflag = saved_nflag;
|
||||
numeric_addr = saved_numeric_addr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,8 +88,8 @@
|
||||
|
||||
#include "netstat.h"
|
||||
|
||||
#define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */
|
||||
#define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
|
||||
#define WID_ORG (lflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */
|
||||
#define WID_GRP (lflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */
|
||||
|
||||
extern char *routename6 __P((struct sockaddr_in6 *));
|
||||
|
||||
@ -105,7 +105,7 @@ mroute6pr(mfcaddr, mifaddr)
|
||||
register mifi_t mifi;
|
||||
register int i;
|
||||
register int banner_printed;
|
||||
register int saved_nflag;
|
||||
register int saved_numeric_addr;
|
||||
mifi_t maxmif = 0;
|
||||
long int waitings;
|
||||
|
||||
@ -115,8 +115,8 @@ mroute6pr(mfcaddr, mifaddr)
|
||||
return;
|
||||
}
|
||||
|
||||
saved_nflag = nflag;
|
||||
nflag = 1;
|
||||
saved_numeric_addr = numeric_addr;
|
||||
numeric_addr = 1;
|
||||
|
||||
kread(mifaddr, (char *)&mif6table, sizeof(mif6table));
|
||||
banner_printed = 0;
|
||||
@ -192,7 +192,7 @@ mroute6pr(mfcaddr, mifaddr)
|
||||
printf("\nIPv6 Multicast Routing Table is empty\n");
|
||||
|
||||
printf("\n");
|
||||
nflag = saved_nflag;
|
||||
numeric_addr = saved_numeric_addr;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -34,7 +34,7 @@
|
||||
.\"
|
||||
.Dd April 18, 1994
|
||||
.Dt NETSTAT 1
|
||||
.Os BSD 4.2
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm netstat
|
||||
.Nd show network status
|
||||
@ -45,7 +45,7 @@
|
||||
.Op Fl M Ar core
|
||||
.Op Fl N Ar system
|
||||
.Nm
|
||||
.Op Fl bdgilnrs
|
||||
.Op Fl bdgilnrsS
|
||||
.Op Fl f Ar address_family
|
||||
.Op Fl M Ar core
|
||||
.Op Fl N Ar system
|
||||
@ -172,7 +172,7 @@ option) or the
|
||||
.Fl p Ar protocol
|
||||
option is present, show per-interface statistics on the
|
||||
.Ar interface
|
||||
for the specfied
|
||||
for the specified
|
||||
.Ar address_family
|
||||
or
|
||||
.Ar protocol ,
|
||||
@ -194,7 +194,7 @@ option (with the
|
||||
option) or the
|
||||
.Fl p Ar protocol
|
||||
option is present, show per-interface statistics on all interfaces
|
||||
for the specfied
|
||||
for the specified
|
||||
.Ar address_family
|
||||
or
|
||||
.Ar protocol ,
|
||||
@ -218,11 +218,15 @@ Show statistics recorded by the memory management routines
|
||||
Extract the name list from the specified system instead of the default
|
||||
.Pa /kernel .
|
||||
.It Fl n
|
||||
Show network addresses as numbers (normally
|
||||
Show network addresses and ports as numbers (normally
|
||||
.Nm
|
||||
interprets addresses and attempts to display them
|
||||
interprets addresses and ports and attempts to display them
|
||||
symbolically).
|
||||
This option may be used with any of the display formats.
|
||||
.It Fl S
|
||||
Show network addresses as numbers (as with
|
||||
.Fl n )
|
||||
but show ports symbolically).
|
||||
.It Fl p Ar protocol
|
||||
Show statistics about
|
||||
.Ar protocol ,
|
||||
|
@ -45,7 +45,8 @@ 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 numeric_addr; /* show addresses numerically */
|
||||
extern int numeric_port; /* show ports numerically */
|
||||
extern int pflag; /* show given protocol */
|
||||
extern int rflag; /* show routing tables (or routing stats) */
|
||||
extern int sflag; /* show protocol statistics */
|
||||
|
@ -235,9 +235,9 @@ pr_family(af)
|
||||
#define WID_IF(af) 6 /* width of netif column */
|
||||
#else
|
||||
#define WID_DST(af) \
|
||||
((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 33: 18)) : 18)
|
||||
((af) == AF_INET6 ? (lflag ? 39 : (numeric_addr ? 33: 18)) : 18)
|
||||
#define WID_GW(af) \
|
||||
((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 29 : 18)) : 18)
|
||||
((af) == AF_INET6 ? (lflag ? 31 : (numeric_addr ? 29 : 18)) : 18)
|
||||
#define WID_IF(af) ((af) == AF_INET6 ? 8 : 6)
|
||||
#endif /*INET6*/
|
||||
|
||||
@ -564,7 +564,7 @@ p_sockaddr(sa, mask, flags, width)
|
||||
if (width < 0 )
|
||||
printf("%s ", cp);
|
||||
else {
|
||||
if (nflag)
|
||||
if (numeric_addr)
|
||||
printf("%-*s ", width, cp);
|
||||
else
|
||||
printf("%-*.*s ", width, width, cp);
|
||||
@ -662,7 +662,7 @@ routename(in)
|
||||
struct hostent *hp;
|
||||
|
||||
cp = 0;
|
||||
if (!nflag) {
|
||||
if (!numeric_addr) {
|
||||
hp = gethostbyaddr((char *)&in, sizeof (struct in_addr),
|
||||
AF_INET);
|
||||
if (hp) {
|
||||
@ -744,7 +744,7 @@ netname(in, mask)
|
||||
i = ntohl(in);
|
||||
dmask = forgemask(i);
|
||||
omask = mask;
|
||||
if (!nflag && i) {
|
||||
if (!numeric_addr && i) {
|
||||
net = i & dmask;
|
||||
if (!(np = getnetbyaddr(i, AF_INET)) && net != i)
|
||||
np = getnetbyaddr(net, AF_INET);
|
||||
@ -841,12 +841,12 @@ netname6(sa6, mask)
|
||||
if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
|
||||
return("default");
|
||||
|
||||
if (nflag)
|
||||
if (numeric_addr)
|
||||
flag |= NI_NUMERICHOST;
|
||||
getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line),
|
||||
NULL, 0, flag);
|
||||
|
||||
if (nflag)
|
||||
if (numeric_addr)
|
||||
sprintf(&line[strlen(line)], "/%d", masklen);
|
||||
|
||||
return line;
|
||||
@ -864,7 +864,7 @@ routename6(sa6)
|
||||
sa6_local.sin6_addr = sa6->sin6_addr;
|
||||
sa6_local.sin6_scope_id = sa6->sin6_scope_id;
|
||||
|
||||
if (nflag)
|
||||
if (numeric_addr)
|
||||
flag |= NI_NUMERICHOST;
|
||||
|
||||
getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len,
|
||||
|
Loading…
Reference in New Issue
Block a user