fb91e0d1f3d32916c283f5f8bed145f9c6adea89
* Copyright (c) 1983, 1988 Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.29 (Berkeley) %G%";
/* BBN Internet protocol implementation */
u_char pr_index
; /* index into nlist of cb head */
u_char pr_sindex
; /* index into nlist of stat block */
u_char pr_wanted
; /* 1 if wanted, 0 otherwise */
void (*pr_cblocks
)(); /* control blocks printing routine */
void (*pr_stats
)(); /* statistics printing routine */
char *pr_name
; /* well-known name */
struct protox berkprotox
[] = {
{ N_TCB
, N_TCPSTAT
, 1, protopr
,
{ N_UDB
, N_UDPSTAT
, 1, protopr
,
struct protox bbnprotox
[] = {
{ N_TCP
, N_TCPSTAT
, 1, bbnprotopr
,
{ N_UDP
, N_UDPSTAT
, 1, bbnprotopr
,
{ N_RDP
, N_RDPSTAT
, 1, bbnprotopr
,
{ N_RAWCB
, 0, 1, bbnprotopr
,
struct protox nsprotox
[] = {
{ N_IDP
, N_IDPSTAT
, 1, nsprotopr
,
{ N_IDP
, N_SPPSTAT
, 1, nsprotopr
,
struct protox isoprotox
[] = {
{ ISO_TP
, N_TPSTAT
, 1, iso_protopr
,
{ N_CLTP
, N_CLTPSTAT
, 1, iso_protopr
,
struct protox
*protoprotox
[] = { protox
, nsprotox
, isoprotox
, NULL
};
static void printproto
__P((struct protox
*, char *));
static void usage
__P(());
static struct protox
*name2protox
__P((char *));
static struct protox
*knownname
__P((char *));
register struct protoent
*p
;
register struct protox
*tp
; /* for printing cblocks & stats */
char *nlistf
= NULL
, *memf
= NULL
;
char buf
[_POSIX2_LINE_MAX
];
if (cp
= rindex(argv
[0], '/'))
while ((ch
= getopt(argc
, argv
, "AaBdf:hI:iM:mN:np:rstuw")) != EOF
)
if (strcmp(optarg
, "ns") == 0)
else if (strcmp(optarg
, "inet") == 0)
else if (strcmp(optarg
, "unix") == 0)
else if (strcmp(optarg
, "iso") == 0)
"%s: %s: unknown address family\n",
for (cp
= interface
= optarg
; isalpha(*cp
); cp
++)
if ((tp
= name2protox(optarg
)) == NULL
) {
"%s: %s: unknown or uninstrumented protocol\n",
#define BACKWARD_COMPATIBILITY
#ifdef BACKWARD_COMPATIBILITY
* Discard setgid privileges if not the running kernel so that bad
* guys can't print interesting stuff from kernel memory.
if (nlistf
!= NULL
|| memf
!= NULL
)
if ((kvmd
= kvm_open(nlistf
, memf
, NULL
, O_RDONLY
, prog
)) == NULL
) {
fprintf(stderr
, "%s: kvm_open: %s\n", prog
, buf
);
if (kvm_nlist(kvmd
, nl
) < 0 || nl
[0].n_type
== 0) {
fprintf(stderr
, "%s: %s: no namelist\n", prog
, nlistf
);
fprintf(stderr
, "%s: no namelist\n", prog
);
mbpr((off_t
)nl
[N_MBSTAT
].n_value
);
(*tp
->pr_stats
)(nl
[tp
->pr_sindex
].n_value
,
printf("%s: no stats routine\n", tp
->pr_name
);
hostpr(nl
[N_IMP
].n_value
, nl
[N_NIMP
].n_value
);
* Keep file descriptors open to avoid overhead
* of open/close on each call to get* routines.
intpr(interval
, nl
[N_IFNET
].n_value
);
rt_stats((off_t
)nl
[N_RTSTAT
].n_value
);
routepr((off_t
)nl
[N_RTREE
].n_value
);
mrt_stats((off_t
)nl
[N_MRTPROTO
].n_value
,
(off_t
)nl
[N_MRTSTAT
].n_value
);
mroutepr((off_t
)nl
[N_MRTPROTO
].n_value
,
(off_t
)nl
[N_MRTTABLE
].n_value
,
(off_t
)nl
[N_VIFTABLE
].n_value
);
(*tp
->pr_stats
)(nl
[tp
->pr_sindex
].n_value
, tp
->pr_name
);
} else if (tp
->pr_cblocks
)
(*tp
->pr_cblocks
)(nl
[tp
->pr_index
].n_value
, tp
->pr_name
);
if (pr
!= NULL
&& (off
|| af
!= AF_UNSPEC
))
* Read kernel memory, return 0 on success.
if (kvm_read(kvmd
, addr
, buf
, size
) != size
) {
/* XXX this duplicates kvm_read's error printout */
(void)fprintf(stderr
, "%s: kvm_read %s\n", prog
,
return (n
!= 1 ? "s" : "");
return (n
!= 1 ? "es" : "");
* Find the protox for the given "well-known" name.
struct protox
**tpp
, *tp
;
for (tpp
= protoprotox
; *tpp
; tpp
++)
for (tp
= *tpp
; tp
->pr_name
; tp
++)
if (strcmp(tp
->pr_name
, name
) == 0)
* Find the protox corresponding to name.
char **alias
; /* alias from p->aliases */
* Try to find the name in the list of "well-known" names. If that
* fails, check if name is an alias for an Internet protocol.
if (tp
= knownname(name
))
setprotoent(1); /* make protocol lookup cheaper */
while (p
= getprotoent()) {
/* assert: name not same as p->name */
for (alias
= p
->p_aliases
; *alias
; alias
++)
if (strcmp(name
, *alias
) == 0) {
return (knownname(p
->p_name
));
"usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", prog
);
" [-himnrs] [-f address_family] [-M core] [-N system]\n");
" [-n] [-I interface] [-M core] [-N system] [-w wait]\n");
" [-M core] [-N system] [-p protocol]\n");