Init
This commit is contained in:
19
ucb/netstat/Makefile
Normal file
19
ucb/netstat/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Copyright (c) 1983 Regents of the University of California.
|
||||
# All rights reserved. The Berkeley software License Agreement
|
||||
# specifies the terms and conditions for redistribution.
|
||||
#
|
||||
# @(#)Makefile 1.1 94/10/31 SMI; from UCB 5.5 1/18/86
|
||||
#
|
||||
OBJS= inet.o if.o main.o mbuf.o route.o unix.o ns.o ipintrq.o
|
||||
CFLAGS=-O
|
||||
DESTDIR=
|
||||
|
||||
netstat: ${OBJS}
|
||||
${CC} ${OBJS} -o netstat -lkvm
|
||||
|
||||
install: netstat
|
||||
install -s -m 2755 -g kmem netstat ${DESTDIR}/usr/ucb/netstat
|
||||
|
||||
clean:
|
||||
rm -f *.o core a.out errs netstat
|
||||
73
ucb/netstat/host.c
Normal file
73
ucb/netstat/host.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)host.c 1.1 94/10/31 SMI"; /* from UCB 5.2 9/27/85 */
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netimp/if_imp.h>
|
||||
#include <netimp/if_imphost.h>
|
||||
|
||||
extern int kread();
|
||||
extern int nflag;
|
||||
extern char *inetname();
|
||||
|
||||
/*
|
||||
* Print the host tables associated with the ARPANET IMP.
|
||||
* Symbolic addresses are shown unless the nflag is given.
|
||||
*/
|
||||
hostpr(hostsaddr)
|
||||
off_t hostsaddr;
|
||||
{
|
||||
struct mbuf *hosts, mb;
|
||||
register struct mbuf *m;
|
||||
register struct hmbuf *mh;
|
||||
register struct host *hp;
|
||||
char flagbuf[10], *flags;
|
||||
int first = 1;
|
||||
|
||||
if (hostsaddr == 0) {
|
||||
printf("hosts: symbol not in namelist\n");
|
||||
return;
|
||||
}
|
||||
kread(hostsaddr, &hosts, sizeof (hosts));
|
||||
m = hosts;
|
||||
printf("IMP Host Table\n");
|
||||
printf("%-5.5s %-15.15s %-4.4s %-9.9s %-4.4s %s\n",
|
||||
"Flags", "Host", "Qcnt", "Q Address", "RFNM", "Timer");
|
||||
while (m) {
|
||||
kread(m, &mb, sizeof (mb));
|
||||
m = &mb;
|
||||
mh = mtod(m, struct hmbuf *);
|
||||
if (mh->hm_count == 0) {
|
||||
m = m->m_next;
|
||||
continue;
|
||||
}
|
||||
for (hp = mh->hm_hosts; hp < mh->hm_hosts + HPMBUF; hp++) {
|
||||
if ((hp->h_flags&HF_INUSE) == 0 && hp->h_timer == 0)
|
||||
continue;
|
||||
flags = flagbuf;
|
||||
*flags++ = hp->h_flags&HF_INUSE ? 'A' : 'F';
|
||||
if (hp->h_flags&HF_DEAD)
|
||||
*flags++ = 'D';
|
||||
if (hp->h_flags&HF_UNREACH)
|
||||
*flags++ = 'U';
|
||||
*flags = '\0';
|
||||
printf("%-5.5s %-15.15s %-4d %-9x %-4d %d\n",
|
||||
flagbuf,
|
||||
inetname(hp->h_addr),
|
||||
hp->h_qcnt,
|
||||
hp->h_q,
|
||||
hp->h_rfnm,
|
||||
hp->h_timer);
|
||||
}
|
||||
m = m->m_next;
|
||||
}
|
||||
}
|
||||
345
ucb/netstat/if.c
Normal file
345
ucb/netstat/if.c
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)if.c 1.1 94/10/31 SMI"; /* from UCB 5.3 4/23/86 */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
#ifdef ENABLE_XNS
|
||||
#include <netns/ns.h>
|
||||
#endif ENABLE_XNS
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int aflag;
|
||||
extern int tflag;
|
||||
extern int nflag;
|
||||
extern char *interface;
|
||||
extern int unit;
|
||||
extern int kread();
|
||||
extern char *routename(), *netname();
|
||||
|
||||
/*
|
||||
* Print a description of the network interfaces.
|
||||
*/
|
||||
intpr(interval, ifnetaddr)
|
||||
int interval;
|
||||
off_t ifnetaddr;
|
||||
{
|
||||
struct ifnet ifnet;
|
||||
union {
|
||||
struct ifaddr ifa;
|
||||
struct in_ifaddr in;
|
||||
} ifaddr;
|
||||
off_t ifaddraddr;
|
||||
char name[16];
|
||||
|
||||
if (ifnetaddr == 0) {
|
||||
printf("ifnet: symbol not defined\n");
|
||||
return;
|
||||
}
|
||||
if (interval) {
|
||||
sidewaysintpr(interval, ifnetaddr);
|
||||
return;
|
||||
}
|
||||
kread(ifnetaddr, &ifnetaddr, sizeof ifnetaddr);
|
||||
printf("%-5.5s %-5.5s%-13.13s %-14.14s %-6.6s %-5.5s %-6.6s %-5.5s",
|
||||
"Name", "Mtu", "Net/Dest", "Address", "Ipkts", "Ierrs",
|
||||
"Opkts", "Oerrs");
|
||||
printf(" %-6.6s", "Collis");
|
||||
if (tflag)
|
||||
printf(" %-6.6s", "Timer");
|
||||
else
|
||||
printf(" %-6.6s", "Queue");
|
||||
putchar('\n');
|
||||
ifaddraddr = 0;
|
||||
while (ifnetaddr || ifaddraddr) {
|
||||
struct sockaddr_in *sin;
|
||||
register char *cp;
|
||||
int n, pad;
|
||||
char *index();
|
||||
struct in_addr in, inet_makeaddr();
|
||||
char buf[80];
|
||||
|
||||
if (ifaddraddr == 0) {
|
||||
/*
|
||||
* No address list for the current interface:
|
||||
* find the first address.
|
||||
*/
|
||||
if (kread(ifnetaddr, &ifnet, sizeof ifnet) < 0)
|
||||
break;
|
||||
if (kread((off_t)ifnet.if_name, name, 16) < 0)
|
||||
break;
|
||||
name[15] = '\0';
|
||||
ifnetaddr = (off_t) ifnet.if_next;
|
||||
/*
|
||||
* If a particular interface has been singled
|
||||
* out, skip over all others.
|
||||
*/
|
||||
if (interface) {
|
||||
if (strcmp(name, interface) != 0 ||
|
||||
unit != ifnet.if_unit)
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* Extend device name with unit number.
|
||||
*/
|
||||
cp = index(name, '\0');
|
||||
*cp++ = ifnet.if_unit + '0';
|
||||
|
||||
if ((ifnet.if_flags&IFF_UP) == 0) {
|
||||
/*
|
||||
* The interface is down: don't report on it
|
||||
* unless it's been singled out or we're
|
||||
* reporting everything.
|
||||
*/
|
||||
if (!interface && !aflag)
|
||||
continue;
|
||||
*cp++ = '*';
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
ifaddraddr = (off_t)ifnet.if_addrlist;
|
||||
}
|
||||
if (ifaddraddr == 0) {
|
||||
/*
|
||||
* There's no address associated with the current
|
||||
* interface.
|
||||
*/
|
||||
if (!aflag)
|
||||
continue;
|
||||
printf("%-5s %-5d", name, ifnet.if_mtu);
|
||||
printf("%-13.13s ", "none");
|
||||
printf("%-14.14s ", "none");
|
||||
} else {
|
||||
printf("%-5s %-5d", name, ifnet.if_mtu);
|
||||
kread(ifaddraddr, &ifaddr, sizeof ifaddr);
|
||||
ifaddraddr = (off_t)ifaddr.ifa.ifa_next;
|
||||
switch (ifaddr.ifa.ifa_addr.sa_family) {
|
||||
case AF_UNSPEC:
|
||||
printf("%-13.13s ", "none");
|
||||
printf("%-14.14s ", "none");
|
||||
break;
|
||||
case AF_INET:
|
||||
if (ifnet.if_flags & IFF_POINTOPOINT) {
|
||||
sin = (struct sockaddr_in *)
|
||||
&ifaddr.in.ia_dstaddr;
|
||||
printf("%-13s ",
|
||||
routename(sin->sin_addr));
|
||||
} else {
|
||||
printf("%-13s ",
|
||||
netname(htonl(ifaddr.in.ia_subnet),
|
||||
ifaddr.in.ia_subnetmask));
|
||||
}
|
||||
sin = (struct sockaddr_in *)&ifaddr.in.ia_addr;
|
||||
printf("%-14s ", routename(sin->sin_addr));
|
||||
break;
|
||||
#ifdef ENABLE_XNS
|
||||
case AF_NS: {
|
||||
struct sockaddr_ns *sns =
|
||||
(struct sockaddr_ns *)&ifaddr.in.ia_addr;
|
||||
long net;
|
||||
char host[8];
|
||||
|
||||
*(union ns_net *) &net = sns->sns_addr.x_net;
|
||||
sprintf(host, "%lxH", ntohl(net));
|
||||
upHex(host);
|
||||
printf("ns:%-8s ", host);
|
||||
|
||||
printf("%-12s ",ns_phost(sns));
|
||||
break;
|
||||
}
|
||||
#endif ENABLE_XNS
|
||||
default:
|
||||
pad = 29; /* chars in this field */
|
||||
/*
|
||||
* We use this roundabout sprintf into a
|
||||
* buffer technique here so that we
|
||||
* can count the number of characters we
|
||||
* print. System V printf doesn't return
|
||||
* the number of bytes written.
|
||||
*/
|
||||
sprintf(buf, "af%2d: ",
|
||||
ifaddr.ifa.ifa_addr.sa_family);
|
||||
pad -= strlen(buf);
|
||||
printf("%s", buf);
|
||||
|
||||
/*
|
||||
* Shave off trailing zero bytes in the
|
||||
* address for printing, but always print
|
||||
* at least one byte.
|
||||
*/
|
||||
for (cp = (char *)&ifaddr.ifa.ifa_addr +
|
||||
sizeof(struct sockaddr) - 1;
|
||||
cp > ifaddr.ifa.ifa_addr.sa_data; --cp)
|
||||
if (*cp != 0)
|
||||
break;
|
||||
n = cp - (char *)ifaddr.ifa.ifa_addr.sa_data
|
||||
+ 1;
|
||||
cp = (char *)ifaddr.ifa.ifa_addr.sa_data;
|
||||
if (n <= 6)
|
||||
while (--n) {
|
||||
sprintf(buf, "%02d.",
|
||||
*cp++ & 0xff);
|
||||
pad -= strlen(buf);
|
||||
printf("%s", buf);
|
||||
}
|
||||
else
|
||||
while (--n) {
|
||||
sprintf(buf, "%02d",
|
||||
*cp++ & 0xff);
|
||||
pad -= strlen(buf);
|
||||
printf("%s", buf);
|
||||
}
|
||||
sprintf(buf, "%02d ", *cp & 0xff);
|
||||
pad -= strlen(buf);
|
||||
printf("%s", buf);
|
||||
if (pad > 0)
|
||||
while (pad--)
|
||||
printf(" ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("%-7d %-4d %-7d %-4d %-6d",
|
||||
ifnet.if_ipackets, ifnet.if_ierrors,
|
||||
ifnet.if_opackets, ifnet.if_oerrors,
|
||||
ifnet.if_collisions);
|
||||
if (tflag)
|
||||
printf(" %-6d", ifnet.if_timer);
|
||||
else
|
||||
printf(" %-6d", ifnet.if_snd.ifq_len);
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
#define MAXIF 20
|
||||
struct iftot {
|
||||
char ift_name[16]; /* interface name */
|
||||
int ift_ip; /* input packets */
|
||||
int ift_ie; /* input errors */
|
||||
int ift_op; /* output packets */
|
||||
int ift_oe; /* output errors */
|
||||
int ift_co; /* collisions */
|
||||
} iftot[MAXIF];
|
||||
|
||||
/*
|
||||
* Print a running summary of interface statistics.
|
||||
* Repeat display every interval seconds, showing
|
||||
* statistics collected over that interval. First
|
||||
* line printed at top of screen is always cumulative.
|
||||
*/
|
||||
sidewaysintpr(interval, off)
|
||||
int interval;
|
||||
off_t off;
|
||||
{
|
||||
struct ifnet ifnet;
|
||||
off_t firstifnet;
|
||||
static char sobuf[BUFSIZ];
|
||||
register struct iftot *ip, *total;
|
||||
register int line;
|
||||
struct iftot *lastif, *sum, *interesting;
|
||||
int maxtraffic, traffic;
|
||||
|
||||
setbuf(stdout, sobuf);
|
||||
kread(off, &firstifnet, sizeof (off_t));
|
||||
lastif = iftot;
|
||||
sum = iftot + MAXIF - 1;
|
||||
total = sum - 1;
|
||||
maxtraffic = 0, interesting = iftot;
|
||||
for (off = firstifnet, ip = iftot; off;) {
|
||||
char *cp;
|
||||
|
||||
kread(off, &ifnet, sizeof ifnet);
|
||||
traffic = ifnet.if_ipackets + ifnet.if_opackets;
|
||||
if (traffic > maxtraffic)
|
||||
maxtraffic = traffic, interesting = ip;
|
||||
ip->ift_name[0] = '(';
|
||||
kread((int)ifnet.if_name, ip->ift_name + 1, 15);
|
||||
if (interface && strcmp(ip->ift_name + 1, interface) == 0 &&
|
||||
unit == ifnet.if_unit) {
|
||||
interesting = ip;
|
||||
maxtraffic = 0x7FFFFFFF;
|
||||
}
|
||||
ip->ift_name[15] = '\0';
|
||||
cp = index(ip->ift_name, '\0');
|
||||
sprintf(cp, "%d)", ifnet.if_unit);
|
||||
ip++;
|
||||
if (ip >= iftot + MAXIF - 2)
|
||||
break;
|
||||
off = (off_t) ifnet.if_next;
|
||||
}
|
||||
lastif = ip;
|
||||
banner:
|
||||
printf(" input %-6.6s output ", interesting->ift_name);
|
||||
if (lastif - iftot > 0)
|
||||
printf(" input (Total) output ");
|
||||
for (ip = iftot; ip < iftot + MAXIF; ip++) {
|
||||
ip->ift_ip = 0;
|
||||
ip->ift_ie = 0;
|
||||
ip->ift_op = 0;
|
||||
ip->ift_oe = 0;
|
||||
ip->ift_co = 0;
|
||||
}
|
||||
putchar('\n');
|
||||
printf("%-7.7s %-5.5s %-7.7s %-5.5s %-6.6s ",
|
||||
"packets", "errs", "packets", "errs", "colls");
|
||||
if (lastif - iftot > 0)
|
||||
printf("%-7.7s %-5.5s %-7.7s %-5.5s %-6.6s ",
|
||||
"packets", "errs", "packets", "errs", "colls");
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
line = 0;
|
||||
loop:
|
||||
sum->ift_ip = 0;
|
||||
sum->ift_ie = 0;
|
||||
sum->ift_op = 0;
|
||||
sum->ift_oe = 0;
|
||||
sum->ift_co = 0;
|
||||
for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
|
||||
kread(off, &ifnet, sizeof ifnet);
|
||||
if (ip == interesting)
|
||||
printf("%-7d %-5d %-7d %-5d %-6d ",
|
||||
ifnet.if_ipackets - ip->ift_ip,
|
||||
ifnet.if_ierrors - ip->ift_ie,
|
||||
ifnet.if_opackets - ip->ift_op,
|
||||
ifnet.if_oerrors - ip->ift_oe,
|
||||
ifnet.if_collisions - ip->ift_co);
|
||||
ip->ift_ip = ifnet.if_ipackets;
|
||||
ip->ift_ie = ifnet.if_ierrors;
|
||||
ip->ift_op = ifnet.if_opackets;
|
||||
ip->ift_oe = ifnet.if_oerrors;
|
||||
ip->ift_co = ifnet.if_collisions;
|
||||
sum->ift_ip += ip->ift_ip;
|
||||
sum->ift_ie += ip->ift_ie;
|
||||
sum->ift_op += ip->ift_op;
|
||||
sum->ift_oe += ip->ift_oe;
|
||||
sum->ift_co += ip->ift_co;
|
||||
off = (off_t) ifnet.if_next;
|
||||
}
|
||||
if (lastif - iftot > 0)
|
||||
printf("%-7d %-5d %-7d %-5d %-6d\n",
|
||||
sum->ift_ip - total->ift_ip,
|
||||
sum->ift_ie - total->ift_ie,
|
||||
sum->ift_op - total->ift_op,
|
||||
sum->ift_oe - total->ift_oe,
|
||||
sum->ift_co - total->ift_co);
|
||||
*total = *sum;
|
||||
fflush(stdout);
|
||||
line++;
|
||||
if (interval)
|
||||
sleep(interval);
|
||||
if (line == 21)
|
||||
goto banner;
|
||||
goto loop;
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
481
ucb/netstat/inet.c
Normal file
481
ucb/netstat/inet.c
Normal file
@@ -0,0 +1,481 @@
|
||||
/*
|
||||
* Copyright (c) 1983, 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)inet.c 1.1 94/10/31 SMI"; /* from UCB 5.11 6/29/88 */
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in_pcb.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/icmp_var.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
#include <netinet/tcp_seq.h>
|
||||
#define TCPSTATES
|
||||
#include <netinet/tcp_fsm.h>
|
||||
#include <netinet/tcp_timer.h>
|
||||
#include <netinet/tcp_var.h>
|
||||
#include <netinet/tcp_debug.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
struct inpcb inpcb;
|
||||
struct tcpcb tcpcb;
|
||||
struct socket sockb;
|
||||
|
||||
extern int kread();
|
||||
extern int Aflag;
|
||||
extern int aflag;
|
||||
extern int nflag;
|
||||
extern char *plural();
|
||||
|
||||
char *inetname();
|
||||
|
||||
/*
|
||||
* Print a summary of connections related to an Internet
|
||||
* protocol. For TCP, also give state of connection.
|
||||
* Listening processes (aflag) are suppressed unless the
|
||||
* -a (all) flag is specified.
|
||||
*/
|
||||
protopr(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct inpcb cb;
|
||||
register struct inpcb *prev, *next;
|
||||
int istcp;
|
||||
static int first = 1;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
istcp = strcmp(name, "tcp") == 0;
|
||||
kread(off, &cb, sizeof (struct inpcb));
|
||||
inpcb = cb;
|
||||
prev = (struct inpcb *)off;
|
||||
if (inpcb.inp_next == (struct inpcb *)off)
|
||||
return;
|
||||
while (inpcb.inp_next != (struct inpcb *)off) {
|
||||
next = inpcb.inp_next;
|
||||
kread((off_t)next, &inpcb, sizeof (inpcb));
|
||||
if (inpcb.inp_prev != prev) {
|
||||
printf("???\n");
|
||||
break;
|
||||
}
|
||||
if (!aflag &&
|
||||
inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) {
|
||||
prev = next;
|
||||
continue;
|
||||
}
|
||||
kread((off_t)inpcb.inp_socket, &sockb, sizeof (sockb));
|
||||
if (istcp) {
|
||||
kread((off_t)inpcb.inp_ppcb, &tcpcb, sizeof (tcpcb));
|
||||
}
|
||||
if (first) {
|
||||
printf("Active Internet connections");
|
||||
if (aflag)
|
||||
printf(" (including servers)");
|
||||
putchar('\n');
|
||||
if (Aflag)
|
||||
printf("%-8.8s ", "PCB");
|
||||
printf(Aflag ?
|
||||
"%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n" :
|
||||
"%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
|
||||
"Proto", "Recv-Q", "Send-Q",
|
||||
"Local Address", "Foreign Address", "(state)");
|
||||
first = 0;
|
||||
}
|
||||
if (Aflag)
|
||||
if (istcp)
|
||||
printf("%8x ", inpcb.inp_ppcb);
|
||||
else
|
||||
printf("%8x ", next);
|
||||
printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
|
||||
sockb.so_snd.sb_cc);
|
||||
inetprint(&inpcb.inp_laddr, inpcb.inp_lport, name);
|
||||
inetprint(&inpcb.inp_faddr, inpcb.inp_fport, name);
|
||||
if (istcp) {
|
||||
if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
|
||||
printf(" %d", tcpcb.t_state);
|
||||
else
|
||||
printf(" %s", tcpstates[tcpcb.t_state]);
|
||||
}
|
||||
putchar('\n');
|
||||
prev = next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump TCP statistics structure.
|
||||
*/
|
||||
tcp_stats(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct tcpstat tcpstat;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
printf ("%s:\n", name);
|
||||
kread(off, (char *)&tcpstat, sizeof (tcpstat));
|
||||
|
||||
#define p(f, m) printf(m, tcpstat.f, plural(tcpstat.f))
|
||||
#define p2(f1, f2, m) printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2))
|
||||
|
||||
p(tcps_sndtotal, "\t%d packet%s sent\n");
|
||||
p2(tcps_sndpack,tcps_sndbyte,
|
||||
"\t\t%d data packet%s (%d byte%s)\n");
|
||||
p2(tcps_sndrexmitpack, tcps_sndrexmitbyte,
|
||||
"\t\t%d data packet%s (%d byte%s) retransmitted\n");
|
||||
p2(tcps_sndacks, tcps_delack,
|
||||
"\t\t%d ack-only packet%s (%d delayed)\n");
|
||||
p(tcps_sndurg, "\t\t%d URG only packet%s\n");
|
||||
p(tcps_sndprobe, "\t\t%d window probe packet%s\n");
|
||||
p(tcps_sndwinup, "\t\t%d window update packet%s\n");
|
||||
p(tcps_sndctrl, "\t\t%d control packet%s\n");
|
||||
p(tcps_rcvtotal, "\t%d packet%s received\n");
|
||||
p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t%d ack%s (for %d byte%s)\n");
|
||||
p(tcps_rcvdupack, "\t\t%d duplicate ack%s\n");
|
||||
p(tcps_rcvacktoomuch, "\t\t%d ack%s for unsent data\n");
|
||||
p2(tcps_rcvpack, tcps_rcvbyte,
|
||||
"\t\t%d packet%s (%d byte%s) received in-sequence\n");
|
||||
p2(tcps_rcvduppack, tcps_rcvdupbyte,
|
||||
"\t\t%d completely duplicate packet%s (%d byte%s)\n");
|
||||
p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte,
|
||||
"\t\t%d packet%s with some dup. data (%d byte%s duped)\n");
|
||||
p2(tcps_rcvoopack, tcps_rcvoobyte,
|
||||
"\t\t%d out-of-order packet%s (%d byte%s)\n");
|
||||
p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin,
|
||||
"\t\t%d packet%s (%d byte%s) of data after window\n");
|
||||
p(tcps_rcvwinprobe, "\t\t%d window probe%s\n");
|
||||
p(tcps_rcvwinupd, "\t\t%d window update packet%s\n");
|
||||
p(tcps_rcvafterclose, "\t\t%d packet%s received after close\n");
|
||||
p(tcps_rcvbadsum, "\t\t%d discarded for bad checksum%s\n");
|
||||
p(tcps_rcvbadoff, "\t\t%d discarded for bad header offset field%s\n");
|
||||
p(tcps_rcvshort, "\t\t%d discarded because packet too short\n");
|
||||
p(tcps_connattempt, "\t%d connection request%s\n");
|
||||
p(tcps_accepts, "\t%d connection accept%s\n");
|
||||
p(tcps_connects, "\t%d connection%s established (including accepts)\n");
|
||||
p2(tcps_closed, tcps_drops,
|
||||
"\t%d connection%s closed (including %d drop%s)\n");
|
||||
p(tcps_conndrops, "\t%d embryonic connection%s dropped\n");
|
||||
p2(tcps_rttupdated, tcps_segstimed,
|
||||
"\t%d segment%s updated rtt (of %d attempt%s)\n");
|
||||
p(tcps_rexmttimeo, "\t%d retransmit timeout%s\n");
|
||||
p(tcps_timeoutdrop, "\t\t%d connection%s dropped by rexmit timeout\n");
|
||||
p(tcps_persisttimeo, "\t%d persist timeout%s\n");
|
||||
p(tcps_keeptimeo, "\t%d keepalive timeout%s\n");
|
||||
p(tcps_keepprobe, "\t\t%d keepalive probe%s sent\n");
|
||||
p(tcps_keepdrops, "\t\t%d connection%s dropped by keepalive\n");
|
||||
#undef p
|
||||
#undef p2
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump UDP statistics structure.
|
||||
*/
|
||||
udp_stats(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct udpstat udpstat;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
kread(off, (char *)&udpstat, sizeof (udpstat));
|
||||
printf("%s:\n\t%u incomplete header%s\n", name,
|
||||
udpstat.udps_hdrops, plural(udpstat.udps_hdrops));
|
||||
printf("\t%u bad data length field%s\n",
|
||||
udpstat.udps_badlen, plural(udpstat.udps_badlen));
|
||||
printf("\t%u bad checksum%s\n",
|
||||
udpstat.udps_badsum, plural(udpstat.udps_badsum));
|
||||
printf("\t%u socket overflow%s\n",
|
||||
udpstat.udps_fullsock, plural(udpstat.udps_fullsock));
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump IP statistics structure.
|
||||
*/
|
||||
ip_stats(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct ipstat ipstat;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
kread(off, (char *)&ipstat, sizeof (ipstat));
|
||||
printf("%s:\n\t%u total packets received\n", name,
|
||||
ipstat.ips_total);
|
||||
printf("\t%u bad header checksum%s\n",
|
||||
ipstat.ips_badsum, plural(ipstat.ips_badsum));
|
||||
printf("\t%u with size smaller than minimum\n", ipstat.ips_toosmall);
|
||||
printf("\t%u with data size < data length\n", ipstat.ips_tooshort);
|
||||
printf("\t%u with header length < data size\n", ipstat.ips_badhlen);
|
||||
printf("\t%u with data length < header length\n", ipstat.ips_badlen);
|
||||
printf("\t%u fragment%s received\n",
|
||||
ipstat.ips_fragments, plural(ipstat.ips_fragments));
|
||||
printf("\t%u fragment%s dropped (dup or out of space)\n",
|
||||
ipstat.ips_fragdropped, plural(ipstat.ips_fragdropped));
|
||||
printf("\t%u fragment%s dropped after timeout\n",
|
||||
ipstat.ips_fragtimeout, plural(ipstat.ips_fragtimeout));
|
||||
printf("\t%u packet%s forwarded\n",
|
||||
ipstat.ips_forward, plural(ipstat.ips_forward));
|
||||
printf("\t%u packet%s not forwardable\n",
|
||||
ipstat.ips_cantforward, plural(ipstat.ips_cantforward));
|
||||
printf("\t%u redirect%s sent\n",
|
||||
ipstat.ips_redirectsent, plural(ipstat.ips_redirectsent));
|
||||
ipintrq_stats();
|
||||
}
|
||||
|
||||
static char *icmpnames[] = {
|
||||
"echo reply",
|
||||
"#1",
|
||||
"#2",
|
||||
"destination unreachable",
|
||||
"source quench",
|
||||
"routing redirect",
|
||||
"#6",
|
||||
"#7",
|
||||
"echo",
|
||||
"#9",
|
||||
"#10",
|
||||
"time exceeded",
|
||||
"parameter problem",
|
||||
"time stamp",
|
||||
"time stamp reply",
|
||||
"information request",
|
||||
"information request reply",
|
||||
"address mask request",
|
||||
"address mask reply"
|
||||
};
|
||||
|
||||
/*
|
||||
* Dump ICMP statistics.
|
||||
*/
|
||||
icmp_stats(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct icmpstat icmpstat;
|
||||
register int i, first;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
kread(off, (char *)&icmpstat, sizeof (icmpstat));
|
||||
printf("%s:\n\t%u call%s to icmp_error\n", name,
|
||||
icmpstat.icps_error, plural(icmpstat.icps_error));
|
||||
printf("\t%u error%s not generated 'cuz old message too short\n",
|
||||
icmpstat.icps_oldshort, plural(icmpstat.icps_oldshort));
|
||||
printf("\t%u error%s not generated 'cuz old message was icmp\n",
|
||||
icmpstat.icps_oldicmp, plural(icmpstat.icps_oldicmp));
|
||||
for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
|
||||
if (icmpstat.icps_outhist[i] != 0) {
|
||||
if (first) {
|
||||
printf("\tOutput histogram:\n");
|
||||
first = 0;
|
||||
}
|
||||
printf("\t\t%s: %u\n", icmpnames[i],
|
||||
icmpstat.icps_outhist[i]);
|
||||
}
|
||||
printf("\t%u message%s with bad code fields\n",
|
||||
icmpstat.icps_badcode, plural(icmpstat.icps_badcode));
|
||||
printf("\t%u message%s < minimum length\n",
|
||||
icmpstat.icps_tooshort, plural(icmpstat.icps_tooshort));
|
||||
printf("\t%u bad checksum%s\n",
|
||||
icmpstat.icps_checksum, plural(icmpstat.icps_checksum));
|
||||
printf("\t%u message%s with bad length\n",
|
||||
icmpstat.icps_badlen, plural(icmpstat.icps_badlen));
|
||||
for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
|
||||
if (icmpstat.icps_inhist[i] != 0) {
|
||||
if (first) {
|
||||
printf("\tInput histogram:\n");
|
||||
first = 0;
|
||||
}
|
||||
printf("\t\t%s: %u\n", icmpnames[i],
|
||||
icmpstat.icps_inhist[i]);
|
||||
}
|
||||
printf("\t%u message response%s generated\n",
|
||||
icmpstat.icps_reflect, plural(icmpstat.icps_reflect));
|
||||
}
|
||||
|
||||
/*
|
||||
* Pretty print an Internet address (net address + port).
|
||||
* If the nflag was specified, use numbers instead of names.
|
||||
*/
|
||||
inetprint(in, port, proto)
|
||||
register struct in_addr *in;
|
||||
u_short port;
|
||||
char *proto;
|
||||
{
|
||||
char *sp = 0;
|
||||
char line[80], *cp, *index();
|
||||
int width;
|
||||
char *getservname();
|
||||
|
||||
sprintf(line, "%.16s.", inetname(*in));
|
||||
cp = index(line, '\0');
|
||||
if (!nflag && port)
|
||||
sp = getservname(port, proto);
|
||||
if (sp || port == 0)
|
||||
sprintf(cp, "%.8s", sp ? sp : "*");
|
||||
else
|
||||
sprintf(cp, "%d", ntohs((u_short)port));
|
||||
width = 22;
|
||||
printf(" %-*.*s", width, width, line);
|
||||
}
|
||||
|
||||
static jmp_buf NameTimeout;
|
||||
int WaitTime = 15; /* seconds to wait for name server */
|
||||
|
||||
timeoutfunc() {longjmp(NameTimeout, 1);}
|
||||
|
||||
/*
|
||||
* Construct an Internet address representation.
|
||||
* If the nflag has been supplied, give
|
||||
* numeric value, otherwise try for symbolic name.
|
||||
*/
|
||||
char *
|
||||
inetname(in)
|
||||
struct in_addr in;
|
||||
{
|
||||
register char *cp;
|
||||
static char line[50];
|
||||
static char domain[MAXHOSTNAMELEN + 1];
|
||||
static int first = 1;
|
||||
|
||||
if (first && !nflag) {
|
||||
/*
|
||||
* Record domain name for future reference. Check
|
||||
* first for the 4.3bsd convention of keeping it as
|
||||
* part of the hostname. Failing that, try extracting
|
||||
* it using the domainname system call.
|
||||
*
|
||||
* XXX: Need to reconcile these two conventions.
|
||||
*/
|
||||
first = 0;
|
||||
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
|
||||
(cp = index(domain, '.')))
|
||||
(void) strcpy(domain, cp + 1);
|
||||
else if (getdomainname(domain, MAXHOSTNAMELEN) < 0)
|
||||
domain[0] = 0;
|
||||
}
|
||||
|
||||
if (in.s_addr == INADDR_ANY) {
|
||||
strcpy(line, "*");
|
||||
return (line);
|
||||
}
|
||||
cp = 0;
|
||||
if (!nflag) {
|
||||
if (inet_lnaof(in) == INADDR_ANY) {
|
||||
struct netent *np;
|
||||
|
||||
np = getnetbyaddr(inet_netof(in), AF_INET);
|
||||
if (np)
|
||||
cp = np->n_name;
|
||||
}
|
||||
if (cp == 0) {
|
||||
struct hostent *hp = NULL;
|
||||
|
||||
signal(SIGALRM, timeoutfunc);
|
||||
alarm(WaitTime);
|
||||
if (setjmp(NameTimeout) == 0)
|
||||
hp = gethostbyaddr(&in, sizeof (struct in_addr),
|
||||
AF_INET);
|
||||
if (hp) {
|
||||
/*
|
||||
* If the hostname contains a domain part,
|
||||
* and it's the same as the local domain,
|
||||
* elide it.
|
||||
*/
|
||||
if ((cp = index(hp->h_name, '.')) &&
|
||||
!strcmp(cp + 1, domain))
|
||||
*cp = 0;
|
||||
cp = hp->h_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cp)
|
||||
strcpy(line, cp);
|
||||
else {
|
||||
sprintf(line, "%s", inet_ntoa(in));
|
||||
}
|
||||
return (line);
|
||||
}
|
||||
|
||||
#define TCP 0
|
||||
#define UDP 1
|
||||
#define NPROTOCOLS 2
|
||||
#define MAXPORT 1024
|
||||
char *names[NPROTOCOLS][MAXPORT];
|
||||
|
||||
char *
|
||||
getservname(port, proto)
|
||||
char *proto;
|
||||
{
|
||||
static int first= 1;
|
||||
int protonum;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
initarray();
|
||||
}
|
||||
if (strcmp(proto, "tcp") == 0)
|
||||
protonum = TCP;
|
||||
else if (strcmp(proto, "udp") == 0)
|
||||
protonum = UDP;
|
||||
else
|
||||
return NULL;
|
||||
if (ntohs((u_short)port) < MAXPORT &&
|
||||
names[protonum][ntohs((u_short)port)])
|
||||
return (names[protonum][ntohs((u_short)port)]);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
initarray()
|
||||
{
|
||||
struct servent *sv;
|
||||
int proto;
|
||||
|
||||
while(sv = getservent()) {
|
||||
if (strcmp(sv->s_proto, "tcp") == 0)
|
||||
proto = TCP;
|
||||
else if (strcmp(sv->s_proto, "udp") == 0)
|
||||
proto = UDP;
|
||||
else
|
||||
continue;
|
||||
if (ntohs((u_short)sv->s_port) >= MAXPORT)
|
||||
continue;
|
||||
names[proto][ntohs((u_short)sv->s_port)] =
|
||||
(char *)malloc(strlen(sv->s_name) + 1);
|
||||
strcpy(names[proto][ntohs((u_short)sv->s_port)], sv->s_name);
|
||||
}
|
||||
endservent();
|
||||
}
|
||||
31
ucb/netstat/ipintrq.c
Normal file
31
ucb/netstat/ipintrq.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Print the IP Interupt queue overflows
|
||||
*
|
||||
* @(#)ipintrq.c 1.1 94/10/31
|
||||
*/
|
||||
|
||||
#include <kvm.h>
|
||||
#include <nlist.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct nlist ip_nl[] = { {"_ipintrq"}, {""} };
|
||||
extern kvm_t *kd;
|
||||
|
||||
static struct ifqueue {
|
||||
int ifq_head; /* struct mbuf *ifq_head; */
|
||||
int ifq_tail; /* struct mbuf *ifq_tail; */
|
||||
int ifq_len;
|
||||
int ifq_maxlen;
|
||||
int ifq_drops;
|
||||
} buf;
|
||||
|
||||
ipintrq_stats()
|
||||
{
|
||||
if (kvm_nlist(kd, ip_nl) < 0) {
|
||||
fprintf(stderr, "netstat: bad namelist\n");
|
||||
exit(1);
|
||||
}
|
||||
kread(ip_nl[0].n_value, &buf, sizeof(buf) );
|
||||
printf("\t%d ip input queue drops\n", buf.ifq_drops);
|
||||
|
||||
}
|
||||
340
ucb/netstat/main.c
Normal file
340
ucb/netstat/main.c
Normal file
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
#endif not lint
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)main.c 1.1 94/10/31 SMI"; /* from UCB 5.7 5/22/86 */
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/vmmac.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include <kvm.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <nlist.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct nlist nl[] = {
|
||||
#define N_MBSTAT 0
|
||||
{ "_mbstat" },
|
||||
#define N_IPSTAT 1
|
||||
{ "_ipstat" },
|
||||
#define N_TCB 2
|
||||
{ "_tcb" },
|
||||
#define N_TCPSTAT 3
|
||||
{ "_tcpstat" },
|
||||
#define N_UDB 4
|
||||
{ "_udb" },
|
||||
#define N_UDPSTAT 5
|
||||
{ "_udpstat" },
|
||||
#define N_IFNET 6
|
||||
{ "_ifnet" },
|
||||
#define N_HOSTS 7
|
||||
{ "_hosts" },
|
||||
#define N_RTHOST 8
|
||||
{ "_rthost" },
|
||||
#define N_RTNET 9
|
||||
{ "_rtnet" },
|
||||
#define N_ICMPSTAT 10
|
||||
{ "_icmpstat" },
|
||||
#define N_RTSTAT 11
|
||||
{ "_rtstat" },
|
||||
#define N_NFILE 12
|
||||
{ "_nfile" },
|
||||
#define N_FILE 13
|
||||
{ "_file" },
|
||||
#define N_UNIXSW 14
|
||||
{ "_unixsw" },
|
||||
#define N_RTHASHSIZE 15
|
||||
{ "_rthashsize" },
|
||||
#define N_IDP 16
|
||||
{ "_nspcb"},
|
||||
#define N_IDPSTAT 17
|
||||
{ "_idpstat"},
|
||||
#define N_SPPSTAT 18
|
||||
{ "_spp_istat"},
|
||||
#define N_NSERR 19
|
||||
{ "_ns_errstat"},
|
||||
#define N_STRST 20
|
||||
{ "_strst" },
|
||||
#define N_NSTRBUFSZ 21
|
||||
{ "_nstrbufsz" },
|
||||
#define N_STRBUFSIZES 22
|
||||
{ "_strbufsizes" },
|
||||
#define N_STRBUFSTAT 23
|
||||
{ "_strbufstat" },
|
||||
"",
|
||||
};
|
||||
|
||||
/* internet protocols */
|
||||
extern int protopr();
|
||||
extern int tcp_stats(), udp_stats(), ip_stats(), icmp_stats();
|
||||
#ifdef ENABLE_XNS
|
||||
extern int nsprotopr();
|
||||
extern int spp_stats(), idp_stats(), nserr_stats();
|
||||
#endif ENABLE_XNS
|
||||
|
||||
struct protox {
|
||||
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 */
|
||||
int (*pr_cblocks)(); /* control blocks printing routine */
|
||||
int (*pr_stats)(); /* statistics printing routine */
|
||||
char *pr_name; /* well-known name */
|
||||
} protox[] = {
|
||||
{ N_TCB, N_TCPSTAT, 1, protopr,
|
||||
tcp_stats, "tcp" },
|
||||
{ N_UDB, N_UDPSTAT, 1, protopr,
|
||||
udp_stats, "udp" },
|
||||
{ -1, N_IPSTAT, 1, 0,
|
||||
ip_stats, "ip" },
|
||||
{ -1, N_ICMPSTAT, 1, 0,
|
||||
icmp_stats, "icmp" },
|
||||
{ -1, -1, 0, 0,
|
||||
0, 0 }
|
||||
};
|
||||
|
||||
#ifdef ENABLE_XNS
|
||||
struct protox nsprotox[] = {
|
||||
{ N_IDP, N_IDPSTAT, 1, nsprotopr,
|
||||
idp_stats, "idp" },
|
||||
{ N_IDP, N_SPPSTAT, 1, nsprotopr,
|
||||
spp_stats, "spp" },
|
||||
{ -1, N_NSERR, 1, 0,
|
||||
nserr_stats, "ns_err" },
|
||||
{ -1, -1, 0, 0,
|
||||
0, 0 }
|
||||
};
|
||||
#endif ENABLE_XNS
|
||||
|
||||
char *system = NULL;
|
||||
char *kmemf = NULL;
|
||||
kvm_t *kd;
|
||||
int Aflag;
|
||||
int aflag;
|
||||
int iflag;
|
||||
int mflag;
|
||||
int nflag;
|
||||
int rflag;
|
||||
int sflag;
|
||||
int tflag;
|
||||
int interval;
|
||||
char *interface;
|
||||
int unit;
|
||||
char usage[] = "[ -Aaimnrst ] [-f address_family] [-I interface] [ interval ] [ system ] [ core ]";
|
||||
|
||||
int af = AF_UNSPEC;
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *cp, *name;
|
||||
register struct protoent *p;
|
||||
register struct protox *tp;
|
||||
|
||||
name = argv[0];
|
||||
argc--, argv++;
|
||||
while (argc > 0 && **argv == '-') {
|
||||
for (cp = &argv[0][1]; *cp; cp++)
|
||||
switch(*cp) {
|
||||
|
||||
case 'A':
|
||||
Aflag++;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
aflag++;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
iflag++;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
mflag++;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
nflag++;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
rflag++;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
sflag++;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
tflag++;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
af = AF_UNIX;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
argv++;
|
||||
argc--;
|
||||
if (argc < 1) {
|
||||
fprintf(stderr, "address family not specified\n");
|
||||
exit(10);
|
||||
}
|
||||
if (strcmp(*argv, "inet") == 0)
|
||||
af = AF_INET;
|
||||
#ifdef ENABLE_XNS
|
||||
else if (strcmp(*argv, "ns") == 0)
|
||||
af = AF_NS;
|
||||
#endif ENABLE_XNS
|
||||
else if (strcmp(*argv, "unix") == 0)
|
||||
af = AF_UNIX;
|
||||
else {
|
||||
fprintf(stderr, "%s: unknown address family\n",
|
||||
*argv);
|
||||
exit(10);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
iflag++;
|
||||
if (*(interface = cp + 1) == 0) {
|
||||
if ((interface = argv[1]) == 0)
|
||||
break;
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
for (cp = interface; isalpha(*cp); cp++)
|
||||
;
|
||||
unit = atoi(cp);
|
||||
*cp-- = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
use:
|
||||
printf("usage: %s %s\n", name, usage);
|
||||
exit(1);
|
||||
}
|
||||
argv++, argc--;
|
||||
}
|
||||
if (argc > 0 && isdigit(argv[0][0])) {
|
||||
interval = atoi(argv[0]);
|
||||
if (interval <= 0)
|
||||
goto use;
|
||||
argv++, argc--;
|
||||
iflag++;
|
||||
}
|
||||
if (argc > 0) {
|
||||
system = *argv;
|
||||
argv++, argc--;
|
||||
}
|
||||
if (argc > 0)
|
||||
kmemf = *argv;
|
||||
|
||||
if ((kd = kvm_open(system, kmemf, NULL, O_RDONLY, argv[0])) == NULL) {
|
||||
if (system == NULL)
|
||||
fprintf(stderr, "Unable to read kernel VM\n");
|
||||
else
|
||||
fprintf(stderr, "Unable to read kernel VM for %s\n",
|
||||
system);
|
||||
exit(1);
|
||||
}
|
||||
if (kvm_nlist(kd, nl) < 0) {
|
||||
fprintf(stderr, "netstat: bad namelist\n");
|
||||
exit(1);
|
||||
}
|
||||
if (mflag) {
|
||||
mbpr(nl[N_MBSTAT].n_value);
|
||||
printf("\n");
|
||||
strstpr(nl[N_STRST].n_value, nl[N_NSTRBUFSZ].n_value,
|
||||
nl[N_STRBUFSIZES].n_value, nl[N_STRBUFSTAT].n_value);
|
||||
exit(0);
|
||||
}
|
||||
/*
|
||||
* Keep file descriptors open to avoid overhead
|
||||
* of open/close on each call to get* routines.
|
||||
*/
|
||||
sethostent(1);
|
||||
setnetent(1);
|
||||
if (iflag) {
|
||||
intpr(interval, nl[N_IFNET].n_value);
|
||||
exit(0);
|
||||
}
|
||||
if (rflag) {
|
||||
if (sflag)
|
||||
rt_stats(nl[N_RTSTAT].n_value);
|
||||
else
|
||||
routepr(nl[N_RTHOST].n_value, nl[N_RTNET].n_value,
|
||||
nl[N_RTHASHSIZE].n_value);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (af == AF_INET || af == AF_UNSPEC) {
|
||||
setprotoent(1);
|
||||
setservent(1);
|
||||
while (p = getprotoent()) {
|
||||
|
||||
for (tp = protox; tp->pr_name; tp++)
|
||||
if (strcmp(tp->pr_name, p->p_name) == 0)
|
||||
break;
|
||||
if (tp->pr_name == 0 || tp->pr_wanted == 0)
|
||||
continue;
|
||||
if (sflag) {
|
||||
if (tp->pr_stats)
|
||||
(*tp->pr_stats)(nl[tp->pr_sindex].n_value,
|
||||
p->p_name);
|
||||
} else
|
||||
if (tp->pr_cblocks)
|
||||
(*tp->pr_cblocks)(nl[tp->pr_index].n_value,
|
||||
p->p_name);
|
||||
}
|
||||
endprotoent();
|
||||
}
|
||||
#ifdef ENABLE_XNS
|
||||
if (af == AF_NS || af == AF_UNSPEC) {
|
||||
for (tp = nsprotox; tp->pr_name; tp++) {
|
||||
if (sflag) {
|
||||
if (tp->pr_stats)
|
||||
(*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);
|
||||
}
|
||||
}
|
||||
#endif ENABLE_XNS
|
||||
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
|
||||
unixpr(nl[N_NFILE].n_value, nl[N_FILE].n_value,
|
||||
nl[N_UNIXSW].n_value);
|
||||
exit(0);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
kread(addr, buf, nbytes)
|
||||
unsigned long addr;
|
||||
char *buf;
|
||||
unsigned nbytes;
|
||||
{
|
||||
return kvm_read(kd, addr, buf, nbytes);
|
||||
}
|
||||
|
||||
char *
|
||||
plural(n)
|
||||
int n;
|
||||
{
|
||||
|
||||
return (n != 1 ? "s" : "");
|
||||
}
|
||||
266
ucb/netstat/mbuf.c
Normal file
266
ucb/netstat/mbuf.c
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (c) 1983, 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)mbuf.c 1.1 94/10/31 SMI"; /* from UCB 5.6 6/29/88 */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/stream.h>
|
||||
#include <sys/strstat.h>
|
||||
#define YES 1
|
||||
typedef int bool;
|
||||
|
||||
struct mbstat mbstat;
|
||||
extern int kread();
|
||||
|
||||
static struct mbtypes {
|
||||
int mt_type;
|
||||
char *mt_name;
|
||||
} mbtypes[] = {
|
||||
{ MT_DATA, "data" },
|
||||
{ MT_HEADER, "packet headers" },
|
||||
{ MT_SOCKET, "socket structures" },
|
||||
{ MT_PCB, "protocol control blocks" },
|
||||
{ MT_RTABLE, "routing table entries" },
|
||||
{ MT_HTABLE, "IMP host table entries" },
|
||||
{ MT_ATABLE, "address resolution tables" },
|
||||
{ MT_FTABLE, "fragment reassembly queue headers" },
|
||||
{ MT_SONAME, "socket names and addresses" },
|
||||
{ MT_ZOMBIE, "zombie process information" },
|
||||
{ MT_SOOPTS, "socket options" },
|
||||
{ MT_RIGHTS, "access rights" },
|
||||
{ MT_IFADDR, "interface addresses" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short);
|
||||
bool seen[256]; /* "have we seen this type yet?" */
|
||||
|
||||
/*
|
||||
* Print mbuf statistics.
|
||||
*/
|
||||
mbpr(mbaddr)
|
||||
off_t mbaddr;
|
||||
{
|
||||
register int totmem, totfree, totmbufs;
|
||||
register int i;
|
||||
register struct mbtypes *mp;
|
||||
|
||||
if (nmbtypes != 256) {
|
||||
fprintf(stderr, "unexpected change to mbstat; check source\n");
|
||||
return;
|
||||
}
|
||||
if (mbaddr == 0) {
|
||||
printf("mbstat: symbol not in namelist\n");
|
||||
return;
|
||||
}
|
||||
kread(mbaddr, &mbstat, sizeof (mbstat));
|
||||
printf("%d/%d mbufs in use:\n",
|
||||
mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs);
|
||||
totmbufs = 0;
|
||||
/*
|
||||
* Tally up totals for known mbuf types.
|
||||
*/
|
||||
for (mp = mbtypes; mp->mt_name; mp++)
|
||||
if (mbstat.m_mtypes[mp->mt_type]) {
|
||||
seen[mp->mt_type] = YES;
|
||||
printf("\t%d mbufs allocated to %s\n",
|
||||
mbstat.m_mtypes[mp->mt_type], mp->mt_name);
|
||||
totmbufs += mbstat.m_mtypes[mp->mt_type];
|
||||
}
|
||||
seen[MT_FREE] = YES;
|
||||
/*
|
||||
* Tally up totals for unknown mbuf types
|
||||
* (ones that don't appear in the mbtypes table).
|
||||
*/
|
||||
for (i = 0; i < nmbtypes; i++)
|
||||
if (!seen[i] && mbstat.m_mtypes[i]) {
|
||||
printf("\t%d mbufs allocated to <mbuf type %d>\n",
|
||||
mbstat.m_mtypes[i], i);
|
||||
totmbufs += mbstat.m_mtypes[i];
|
||||
}
|
||||
if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE])
|
||||
printf("*** %d mbufs missing ***\n",
|
||||
(mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs);
|
||||
printf("%d/%d cluster buffers in use\n",
|
||||
mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters);
|
||||
/*
|
||||
* XXX: Should account for MCL_LOANED mbufs here, too, but that
|
||||
* requires examining all the mbuf headers.
|
||||
*/
|
||||
totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * MCLBYTES;
|
||||
totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * MCLBYTES;
|
||||
printf("%d Kbytes allocated to network (%d%% in use)\n",
|
||||
totmem / 1024, (totmem - totfree) * 100 / totmem);
|
||||
printf("%d requests for memory denied\n", mbstat.m_drops);
|
||||
printf("%u requests for memory delayed\n", mbstat.m_wait);
|
||||
printf("%u calls to protocol drain routines\n", mbstat.m_drain);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Streams allocation statistics code.
|
||||
*/
|
||||
|
||||
struct strstat strst;
|
||||
u_int nstrbufsz;
|
||||
alcdat *strbufstat;
|
||||
|
||||
/*
|
||||
* Print statistics for streams allocation.
|
||||
*/
|
||||
strstpr(straddr, nstrbufszaddr, strbufsizesaddr, strbufstataddr)
|
||||
off_t straddr;
|
||||
off_t nstrbufszaddr;
|
||||
off_t strbufsizesaddr;
|
||||
off_t strbufstataddr;
|
||||
{
|
||||
register int i;
|
||||
register u_int size;
|
||||
register struct strstat *s = &strst;
|
||||
register u_int *strbufsizes;
|
||||
register alcdat *sbs;
|
||||
char buf[50];
|
||||
|
||||
/*
|
||||
* Maximize the probability of getting an internally consistent
|
||||
* snapshot by gathering all data before printing anything.
|
||||
*/
|
||||
|
||||
if (straddr == 0 || nstrbufszaddr == 0 || strbufsizesaddr == 0 ||
|
||||
strbufstataddr == 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Grab the strst structure (which contains overall STREAMS
|
||||
* statistics).
|
||||
*/
|
||||
if (kread(straddr, (char *)&strst, sizeof strst) != sizeof strst) {
|
||||
printf("prstrst: bad read\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get number of buckets for actual buffer allocations.
|
||||
*/
|
||||
if (kread(nstrbufszaddr, (char *)&nstrbufsz, sizeof nstrbufsz) !=
|
||||
sizeof nstrbufsz) {
|
||||
(void) fprintf(stderr, "strstpr: bad read of nstrbufsz\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate space for the strbufsizes array and pull it in.
|
||||
*/
|
||||
size = sizeof *strbufsizes * nstrbufsz;
|
||||
strbufsizes = (u_int *) malloc(size);
|
||||
if (strbufsizes == NULL) {
|
||||
(void) fprintf(stderr, "strstpr: bad malloc of strbufsizes\n");
|
||||
return;
|
||||
}
|
||||
if (kread(strbufsizesaddr, (char *)strbufsizes, size) != size) {
|
||||
(void) fprintf(stderr, "strstpr: bad read of strbufsizes\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate space for the strbufstat array and pull it in. Note that
|
||||
* it contains two extra entries at the beginning for external buffers
|
||||
* and buffers embedded in dblks. Also, since the kernel itself
|
||||
* dynamically allocates space for this array, we have to go through
|
||||
* an extra level of indirection here.
|
||||
*/
|
||||
if (kread(strbufstataddr, (char *)&strbufstat, sizeof strbufstat) !=
|
||||
sizeof strbufstat) {
|
||||
(void) fprintf(stderr, "strstpr: bad read of strbufstat\n");
|
||||
return;
|
||||
}
|
||||
size = sizeof *sbs * (2 + nstrbufsz);
|
||||
sbs = (alcdat *) malloc(size);
|
||||
if (strbufstat == NULL) {
|
||||
(void) fprintf(stderr,
|
||||
"strstpr: bad malloc of strbufstat array\n");
|
||||
return;
|
||||
}
|
||||
if (kread((off_t)strbufstat, (char *)sbs, size) != size) {
|
||||
(void) fprintf(stderr,
|
||||
"strstpr: bad read of strbufstat array\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Display overall STREAMS data.
|
||||
*/
|
||||
printf("streams allocation:\n");
|
||||
printf("%*s%s\n", 41, "", "cumulative allocation");
|
||||
printf("%*s%s\n", 22, "", "current maximum total failures");
|
||||
pf_strstat("streams", &s->stream);
|
||||
pf_strstat("queues", &s->queue);
|
||||
pf_strstat("mblks", &s->mblock);
|
||||
pf_strstat("dblks", &s->dblock);
|
||||
|
||||
/*
|
||||
* Display buffer-related data.
|
||||
*/
|
||||
printf("streams buffers:\n");
|
||||
pf_strstat("external", &sbs[0]);
|
||||
pf_strstat("within-dblk", &sbs[1]);
|
||||
for (i = 0; i < nstrbufsz - 1; i++) {
|
||||
(void) sprintf(buf, "size <= %5d", strbufsizes[i]);
|
||||
pf_strstat(buf, &sbs[i + 2]);
|
||||
}
|
||||
(void) sprintf(buf, "size > %5d", strbufsizes[nstrbufsz - 2]);
|
||||
pf_strstat(buf, &sbs[nstrbufsz + 1]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print a line of streams allocation information, as recorded
|
||||
* in the (alcdat *) given as argument.
|
||||
*/
|
||||
pf_strstat(label, alp)
|
||||
char *label;
|
||||
alcdat *alp;
|
||||
{
|
||||
printf("%s%*s%6d %6d %7d %6d\n",
|
||||
label,
|
||||
23 - strlen(label), "", /* Move to column 24 */
|
||||
alp->use,
|
||||
alp->max,
|
||||
alp->total,
|
||||
alp->fail);
|
||||
}
|
||||
|
||||
#ifdef notdef
|
||||
/*
|
||||
* Streams display layout follows.
|
||||
*/
|
||||
streams allocation:
|
||||
cumulative allocation
|
||||
current maximum total failures
|
||||
streams 000000 000000 0000000 000000
|
||||
queues 000000 000000 0000000 000000
|
||||
mblks 000000 000000 0000000 000000
|
||||
dblks 000000 000000 0000000 000000
|
||||
streams buffers:
|
||||
external 000000 000000 0000000 000000
|
||||
within-dblk 000000 000000 0000000 000000
|
||||
size <= ll 000000 000000 0000000 000000
|
||||
size <= mmm 000000 000000 0000000 000000
|
||||
size <= nnnn 000000 000000 0000000 000000
|
||||
size > nnnn 000000 000000 0000000 000000
|
||||
#endif notdef
|
||||
236
ucb/netstat/ns.c
Normal file
236
ucb/netstat/ns.c
Normal file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ns.c 1.1 94/10/31 SMI"; /* from UCB 5.3 9/12/85 */
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_XNS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <nlist.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
|
||||
#include <net/route.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/tcp_fsm.h>
|
||||
#include <netinet/tcp_timer.h>
|
||||
|
||||
#include <netns/ns.h>
|
||||
#include <netns/ns_pcb.h>
|
||||
#include <netns/idp.h>
|
||||
#include <netns/idp_var.h>
|
||||
#include <netns/ns_error.h>
|
||||
#include <netns/sp.h>
|
||||
#include <netns/spidp.h>
|
||||
#include <netns/spp_var.h>
|
||||
#define SANAMES
|
||||
#include <netns/spp_debug.h>
|
||||
|
||||
|
||||
struct nspcb nspcb;
|
||||
struct sppcb sppcb;
|
||||
struct socket sockb;
|
||||
struct protosw proto;
|
||||
extern int kread();
|
||||
extern int Aflag;
|
||||
extern int aflag;
|
||||
extern int nflag;
|
||||
char *ns_prpr();
|
||||
|
||||
static int first = 1;
|
||||
|
||||
/*
|
||||
* Print a summary of connections related to a Network Systems
|
||||
* protocol. For SPP, also give state of connection.
|
||||
* Listening processes (aflag) are suppressed unless the
|
||||
* -a (all) flag is specified.
|
||||
*/
|
||||
|
||||
nsprotopr(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct nspcb cb;
|
||||
register struct nspcb *prev, *next;
|
||||
int isspp;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
isspp = strcmp(name, "spp") == 0;
|
||||
kread(off, &cb, sizeof (struct nspcb));
|
||||
nspcb = cb;
|
||||
prev = (struct nspcb *)off;
|
||||
if (nspcb.nsp_next == (struct nspcb *)off)
|
||||
return;
|
||||
for (;nspcb.nsp_next != (struct nspcb *)off; prev = next) {
|
||||
char *cp;
|
||||
off_t ppcb;
|
||||
|
||||
next = nspcb.nsp_next;
|
||||
kread((off_t)next, &nspcb, sizeof (nspcb));
|
||||
if (nspcb.nsp_prev != prev) {
|
||||
printf("???\n");
|
||||
break;
|
||||
}
|
||||
if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) {
|
||||
continue;
|
||||
}
|
||||
kread((off_t)nspcb.nsp_socket, &sockb, sizeof (sockb));
|
||||
ppcb = (off_t) nspcb.nsp_pcb;
|
||||
if (ppcb) {
|
||||
if (isspp) {
|
||||
kread(ppcb, &sppcb, sizeof (sppcb));
|
||||
} else continue;
|
||||
} else
|
||||
if (isspp) continue;
|
||||
if (first) {
|
||||
printf("Active NS connections");
|
||||
if (aflag)
|
||||
printf(" (including servers)");
|
||||
putchar('\n');
|
||||
if (Aflag)
|
||||
printf("%-8.8s ", "PCB");
|
||||
printf(Aflag ?
|
||||
"%-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",
|
||||
"Local Address", "Foreign Address", "(state)");
|
||||
first = 0;
|
||||
}
|
||||
if (Aflag)
|
||||
printf("%8x ", ppcb);
|
||||
printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
|
||||
sockb.so_snd.sb_cc);
|
||||
printf(" %-22.22s", ns_prpr(&nspcb.nsp_laddr));
|
||||
printf(" %-22.22s", ns_prpr(&nspcb.nsp_faddr));
|
||||
if (isspp) {
|
||||
extern char *tcpstates[];
|
||||
if (sppcb.s_state < 0 || sppcb.s_state >= TCP_NSTATES)
|
||||
printf(" %d", sppcb.s_state);
|
||||
else
|
||||
printf(" %s", tcpstates[sppcb.s_state]);
|
||||
}
|
||||
putchar('\n');
|
||||
prev = next;
|
||||
}
|
||||
}
|
||||
#define ANY(x,y,z) ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0)
|
||||
|
||||
/*
|
||||
* Dump SPP statistics structure.
|
||||
*/
|
||||
spp_stats(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct spp_istat spp_istat;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
kread(off, (char *)&spp_istat, sizeof (spp_istat));
|
||||
printf("%s:\n", name);
|
||||
ANY(spp_istat.nonucn, "connection", " dropped due to no new sockets ");
|
||||
ANY(spp_istat.gonawy, "connection", " terminated due to our end dying");
|
||||
ANY(spp_istat.nonucn, "connection", " dropped due to inability to connect");
|
||||
ANY(spp_istat.noconn, "connection", " dropped due to inability to connect");
|
||||
ANY(spp_istat.notme, "connection", " incompleted due to mismatched id's");
|
||||
ANY(spp_istat.wrncon, "connection", " dropped due to mismatched id's");
|
||||
ANY(spp_istat.bdreas, "packet", " dropped out of sequence");
|
||||
ANY(spp_istat.lstdup, "packet", " duplicating the highest packet");
|
||||
ANY(spp_istat.notyet, "packet", " refused as exceeding allocation");
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump IDP statistics structure.
|
||||
*/
|
||||
idp_stats(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct idpstat idpstat;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
kread(off, (char *)&idpstat, sizeof (idpstat));
|
||||
ANY(idpstat.idps_toosmall, "packet", " smaller than a header");
|
||||
ANY(idpstat.idps_tooshort, "packet", " smaller than advertised");
|
||||
ANY(idpstat.idps_badsum, "packet", " with bad checksums");
|
||||
}
|
||||
|
||||
static char *((ns_errnames[])[2]) = {
|
||||
{"Unspecified Error", " at Destination"},
|
||||
{"Bad Checksum", " at Destination"},
|
||||
{"No Listener", " at Socket"},
|
||||
{"Packet", " Refused due to lack of space at Destination"},
|
||||
{"Unspecified Error", " while gatewayed"},
|
||||
{"Bad Checksum", " while gatewayed"},
|
||||
{"Packet", " forwarded too many times"},
|
||||
{"Packet", " too large to be forwarded"},
|
||||
};
|
||||
|
||||
/*
|
||||
* Dump NS Error statistics structure.
|
||||
*/
|
||||
nserr_stats(off, name)
|
||||
off_t off;
|
||||
char *name;
|
||||
{
|
||||
struct ns_errstat ns_errstat;
|
||||
register int j;
|
||||
register int histoprint = 1;
|
||||
int z;
|
||||
|
||||
if (off == 0)
|
||||
return;
|
||||
kread(off, (char *)&ns_errstat, sizeof (ns_errstat));
|
||||
printf("NS error statistics:\n");
|
||||
ANY(ns_errstat.ns_es_error, "call", " to ns_error");
|
||||
ANY(ns_errstat.ns_es_oldshort, "error",
|
||||
" ignored due to insufficient addressing");
|
||||
ANY(ns_errstat.ns_es_oldns_err, "error request",
|
||||
" in response to error packets");
|
||||
ANY(ns_errstat.ns_es_tooshort, "error packet",
|
||||
" received incomplete");
|
||||
ANY(ns_errstat.ns_es_badcode, "error packet",
|
||||
" received of unknown type");
|
||||
for(j = 0; j < NS_ERR_MAX; j ++) {
|
||||
z = ns_errstat.ns_es_outhist[j];
|
||||
if (z && histoprint) {
|
||||
printf("Output Error Histogram:\n");
|
||||
histoprint = 0;
|
||||
}
|
||||
ANY(z, ns_errnames[j][0], ns_errnames[j][1]);
|
||||
}
|
||||
histoprint = 1;
|
||||
for(j = 0; j < NS_ERR_MAX; j ++) {
|
||||
z = ns_errstat.ns_es_inhist[j];
|
||||
if (z && histoprint) {
|
||||
printf("Input Error Histogram:\n");
|
||||
histoprint = 0;
|
||||
}
|
||||
ANY(z, ns_errnames[j][0], ns_errnames[j][1]);
|
||||
}
|
||||
}
|
||||
static struct sockaddr_ns ssns = {AF_NS};
|
||||
|
||||
char *ns_prpr(x)
|
||||
struct ns_addr *x;
|
||||
{
|
||||
extern char *ns_print();
|
||||
struct sockaddr_ns *sns = &ssns;
|
||||
sns->sns_addr = *x;
|
||||
return(ns_print(sns));
|
||||
}
|
||||
|
||||
#endif ENABLE_XNS
|
||||
380
ucb/netstat/route.c
Normal file
380
ucb/netstat/route.c
Normal file
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)route.c 1.1 94/10/31 SMI"; /* from UCB 5.6 86/04/23 */
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef ENABLE_XNS
|
||||
#include <netns/ns.h>
|
||||
#endif ENABLE_XNS
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
extern int kread();
|
||||
extern int nflag;
|
||||
extern char *routename(), *netname(), *inet_ntoa();
|
||||
#ifdef ENABLE_XNS
|
||||
extern char *ns_print();
|
||||
#endif ENABLE_XNS
|
||||
|
||||
/*
|
||||
* Definitions for showing gateway flags.
|
||||
*/
|
||||
struct bits {
|
||||
short b_mask;
|
||||
char b_val;
|
||||
} bits[] = {
|
||||
{ RTF_UP, 'U' },
|
||||
{ RTF_GATEWAY, 'G' },
|
||||
{ RTF_HOST, 'H' },
|
||||
{ RTF_DYNAMIC, 'D' },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Print routing tables.
|
||||
*/
|
||||
routepr(hostaddr, netaddr, hashsizeaddr)
|
||||
off_t hostaddr, netaddr, hashsizeaddr;
|
||||
{
|
||||
struct mbuf mb;
|
||||
register struct rtentry *rt;
|
||||
register struct mbuf *m;
|
||||
register struct bits *p;
|
||||
char name[16], *flags;
|
||||
struct mbuf **routehash;
|
||||
struct ifnet ifnet;
|
||||
int hashsize;
|
||||
int i, doinghost = 1;
|
||||
|
||||
if (hostaddr == 0) {
|
||||
printf("rthost: symbol not in namelist\n");
|
||||
return;
|
||||
}
|
||||
if (netaddr == 0) {
|
||||
printf("rtnet: symbol not in namelist\n");
|
||||
return;
|
||||
}
|
||||
if (hashsizeaddr == 0) {
|
||||
printf("rthashsize: symbol not in namelist\n");
|
||||
return;
|
||||
}
|
||||
kread(hashsizeaddr, &hashsize, sizeof (hashsize));
|
||||
routehash = (struct mbuf **)malloc( hashsize*sizeof (struct mbuf *) );
|
||||
kread(hostaddr, routehash, hashsize*sizeof (struct mbuf *));
|
||||
printf("Routing tables\n");
|
||||
printf("%-20.20s %-20.20s %-8.8s %-6.6s %-10.10s %s\n",
|
||||
"Destination", "Gateway",
|
||||
"Flags", "Refcnt", "Use", "Interface");
|
||||
again:
|
||||
for (i = 0; i < hashsize; i++) {
|
||||
if (routehash[i] == 0)
|
||||
continue;
|
||||
m = routehash[i];
|
||||
while (m) {
|
||||
struct sockaddr_in *sin;
|
||||
|
||||
kread(m, &mb, sizeof (mb));
|
||||
rt = mtod(&mb, struct rtentry *);
|
||||
if ((unsigned)rt < (unsigned)&mb ||
|
||||
(unsigned)rt >= (unsigned)(&mb + 1)) {
|
||||
printf("???\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch(rt->rt_dst.sa_family) {
|
||||
case AF_INET:
|
||||
sin = (struct sockaddr_in *)&rt->rt_dst;
|
||||
printf("%-20.20s ",
|
||||
(sin->sin_addr.s_addr == 0) ? "default" :
|
||||
(rt->rt_flags & RTF_HOST) ?
|
||||
routename(sin->sin_addr) :
|
||||
netname(sin->sin_addr.s_addr, 0));
|
||||
sin = (struct sockaddr_in *)&rt->rt_gateway;
|
||||
printf("%-20.20s ", routename(sin->sin_addr));
|
||||
break;
|
||||
#ifdef ENABLE_XNS
|
||||
case AF_NS:
|
||||
printf("%-20s ",
|
||||
ns_print((struct sockaddr_ns *)&rt->rt_dst));
|
||||
printf("%-20s ",
|
||||
ns_print((struct sockaddr_ns *)&rt->rt_gateway));
|
||||
break;
|
||||
#endif ENABLE_XNS
|
||||
default: {
|
||||
u_short *s = (u_short *)rt->rt_dst.sa_data;
|
||||
|
||||
printf("(%d)%x %x %x %x %x %x %x ",
|
||||
rt->rt_dst.sa_family,
|
||||
s[0], s[1], s[2], s[3], s[4], s[5], s[6]);
|
||||
s = (u_short *)rt->rt_gateway.sa_data;
|
||||
printf("(%d)%x %x %x %x %x %x %x ",
|
||||
rt->rt_gateway.sa_family,
|
||||
s[0], s[1], s[2], s[3], s[4], s[5], s[6]);
|
||||
}
|
||||
}
|
||||
for (flags = name, p = bits; p->b_mask; p++)
|
||||
if (p->b_mask & rt->rt_flags)
|
||||
*flags++ = p->b_val;
|
||||
*flags = '\0';
|
||||
printf("%-8.8s %-6d %-10d ", name,
|
||||
rt->rt_refcnt, rt->rt_use);
|
||||
if (rt->rt_ifp == 0) {
|
||||
putchar('\n');
|
||||
m = mb.m_next;
|
||||
continue;
|
||||
}
|
||||
kread(rt->rt_ifp, &ifnet, sizeof (ifnet));
|
||||
kread((int)ifnet.if_name, name, 16);
|
||||
printf("%s%d\n", name, ifnet.if_unit);
|
||||
m = mb.m_next;
|
||||
}
|
||||
}
|
||||
if (doinghost) {
|
||||
kread(netaddr, routehash, hashsize*sizeof (struct mbuf *));
|
||||
doinghost = 0;
|
||||
goto again;
|
||||
}
|
||||
free(routehash);
|
||||
}
|
||||
|
||||
char *
|
||||
routename(in)
|
||||
struct in_addr in; /* in network order */
|
||||
{
|
||||
register char *cp;
|
||||
static char line[50];
|
||||
struct hostent *hp;
|
||||
static char domain[MAXHOSTNAMELEN + 1];
|
||||
static int first = 1;
|
||||
char *index();
|
||||
|
||||
if (first) {
|
||||
/*
|
||||
* Record domain name for future reference. Check
|
||||
* first for the 4.3bsd convention of keeping it as
|
||||
* part of the hostname. Failing that, try extracting
|
||||
* it using the domainname system call.
|
||||
*/
|
||||
first = 0;
|
||||
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
|
||||
(cp = index(domain, '.')))
|
||||
(void) strcpy(domain, cp + 1);
|
||||
else if (getdomainname(domain, MAXHOSTNAMELEN) < 0)
|
||||
domain[0] = 0;
|
||||
}
|
||||
cp = 0;
|
||||
if (!nflag) {
|
||||
hp = gethostbyaddr(&in, sizeof (struct in_addr),
|
||||
AF_INET);
|
||||
if (hp) {
|
||||
/*
|
||||
* If the hostname contains a domain part,
|
||||
* and it's the same as the local domain,
|
||||
* elide it.
|
||||
*/
|
||||
if ((cp = index(hp->h_name, '.')) &&
|
||||
!strcmp(cp + 1, domain))
|
||||
*cp = 0;
|
||||
cp = hp->h_name;
|
||||
}
|
||||
}
|
||||
if (cp)
|
||||
strcpy(line, cp);
|
||||
else
|
||||
strcpy(line, inet_ntoa(in));
|
||||
return (line);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the name of the network whose address is given.
|
||||
* The address is assumed to be that of a net or subnet, not a host.
|
||||
*/
|
||||
char *
|
||||
netname(iaddr, mask)
|
||||
u_long iaddr;
|
||||
u_long mask;
|
||||
{
|
||||
char *cp = 0;
|
||||
static char line[50];
|
||||
struct in_addr in;
|
||||
|
||||
in.s_addr = ntohl(iaddr);
|
||||
if (!nflag && in.s_addr) {
|
||||
struct netent *np = 0;
|
||||
struct hostent *hp;
|
||||
u_long net;
|
||||
|
||||
if (mask == 0) {
|
||||
register u_long i = in.s_addr;
|
||||
int subnetshift;
|
||||
|
||||
if (IN_CLASSA(i)) {
|
||||
mask = IN_CLASSA_NET;
|
||||
subnetshift = 8;
|
||||
} else if (IN_CLASSB(i)) {
|
||||
mask = IN_CLASSB_NET;
|
||||
subnetshift = 8;
|
||||
} else {
|
||||
mask = IN_CLASSC_NET;
|
||||
subnetshift = 4;
|
||||
}
|
||||
/*
|
||||
* If there are more bits than the standard mask
|
||||
* would suggest, subnets must be in use.
|
||||
* Guess at the subnet mask, assuming reasonable
|
||||
* width subnet fields.
|
||||
*/
|
||||
while (in.s_addr &~ mask)
|
||||
mask = (long)mask >> subnetshift;
|
||||
}
|
||||
net = in.s_addr & mask;
|
||||
/*
|
||||
* Right-justify the network number.
|
||||
*
|
||||
* This is a throw-back to the old conventions used in the
|
||||
* kernel. We now store it left-justified in the kernel,
|
||||
* but still right-justified in the NIS maps for backward
|
||||
* compatibility.
|
||||
*/
|
||||
while ((mask & 1) == 0)
|
||||
mask >>= 1, net >>= 1;
|
||||
np = getnetbyaddr(net, AF_INET);
|
||||
if (np && np->n_net == net)
|
||||
cp = np->n_name;
|
||||
else {
|
||||
/*
|
||||
* gethostbyaddr takes network order; above
|
||||
* wanted host order.
|
||||
*/
|
||||
in.s_addr = iaddr;
|
||||
hp = gethostbyaddr(&in,sizeof(struct in_addr),AF_INET);
|
||||
if (hp)
|
||||
cp = hp->h_name;
|
||||
}
|
||||
}
|
||||
if (cp)
|
||||
strcpy(line, cp);
|
||||
else {
|
||||
in.s_addr = iaddr;
|
||||
strcpy(line, inet_ntoa(in));
|
||||
}
|
||||
return (line);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print routing statistics
|
||||
*/
|
||||
rt_stats(off)
|
||||
off_t off;
|
||||
{
|
||||
struct rtstat rtstat;
|
||||
|
||||
if (off == 0) {
|
||||
printf("rtstat: symbol not in namelist\n");
|
||||
return;
|
||||
}
|
||||
kread(off, (char *)&rtstat, sizeof (rtstat));
|
||||
printf("routing:\n");
|
||||
printf("\t%d bad routing redirect%s\n",
|
||||
rtstat.rts_badredirect, plural(rtstat.rts_badredirect));
|
||||
printf("\t%d dynamically created route%s\n",
|
||||
rtstat.rts_dynamic, plural(rtstat.rts_dynamic));
|
||||
printf("\t%d new gateway%s due to redirects\n",
|
||||
rtstat.rts_newgateway, plural(rtstat.rts_newgateway));
|
||||
printf("\t%d destination%s found unreachable\n",
|
||||
rtstat.rts_unreach, plural(rtstat.rts_unreach));
|
||||
printf("\t%d use%s of a wildcard route\n",
|
||||
rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_XNS
|
||||
|
||||
short ns_nullh[] = {0,0,0};
|
||||
short ns_bh[] = {-1,-1,-1};
|
||||
|
||||
char *
|
||||
ns_print(sns)
|
||||
struct sockaddr_ns *sns;
|
||||
{
|
||||
struct ns_addr work;
|
||||
union { union ns_net net_e; u_long long_e; } net;
|
||||
u_short port;
|
||||
static char mybuf[50], cport[10], chost[25];
|
||||
char *host = "";
|
||||
register char *p; register u_char *q; u_char *q_lim;
|
||||
|
||||
work = sns->sns_addr;
|
||||
port = ntohs(work.x_port);
|
||||
work.x_port = 0;
|
||||
net.net_e = work.x_net;
|
||||
if (ns_nullhost(work) && net.long_e == 0) {
|
||||
if (port ) {
|
||||
sprintf(mybuf, "*.%xH", port);
|
||||
upHex(mybuf);
|
||||
} else
|
||||
sprintf(mybuf, "*.*");
|
||||
return (mybuf);
|
||||
}
|
||||
|
||||
if (bcmp(ns_bh, work.x_host.c_host, 6) == 0) {
|
||||
host = "any";
|
||||
} else if (bcmp(ns_nullh, work.x_host.c_host, 6) == 0) {
|
||||
host = "*";
|
||||
} else {
|
||||
q = work.x_host.c_host;
|
||||
sprintf(chost, "%02x%02x%02x%02x%02x%02xH",
|
||||
q[0], q[1], q[2], q[3], q[4], q[5]);
|
||||
for (p = chost; *p == '0' && p < chost + 12; p++);
|
||||
host = p;
|
||||
}
|
||||
if (port)
|
||||
sprintf(cport, ".%xH", htons(port));
|
||||
else
|
||||
*cport = 0;
|
||||
|
||||
sprintf(mybuf,"%xH.%s%s", ntohl(net.long_e), host, cport);
|
||||
upHex(mybuf);
|
||||
return(mybuf);
|
||||
}
|
||||
|
||||
char *
|
||||
ns_phost(sns)
|
||||
struct sockaddr_ns *sns;
|
||||
{
|
||||
struct sockaddr_ns work;
|
||||
static union ns_net ns_zeronet;
|
||||
char *p;
|
||||
|
||||
work = *sns;
|
||||
work.sns_addr.x_port = 0;
|
||||
work.sns_addr.x_net = ns_zeronet;
|
||||
|
||||
p = ns_print(&work);
|
||||
if (strncmp("0H.", p, 3) == 0)
|
||||
p += 3;
|
||||
return(p);
|
||||
}
|
||||
upHex(p0)
|
||||
char *p0;
|
||||
{
|
||||
register char *p = p0;
|
||||
for (; *p; p++) switch (*p) {
|
||||
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
*p += ('A' - 'a');
|
||||
}
|
||||
}
|
||||
#endif ENABLE_XNS
|
||||
108
ucb/netstat/unix.c
Normal file
108
ucb/netstat/unix.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved. The Berkeley software License Agreement
|
||||
* specifies the terms and conditions for redistribution.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)unix.c 1.1 94/10/31 SMI"; /* from UCB 5.3 5/8/86 */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Display protocol blocks in the unix domain.
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/unpcb.h>
|
||||
#define KERNEL
|
||||
#include <sys/file.h>
|
||||
|
||||
int Aflag;
|
||||
int kread();
|
||||
|
||||
unixpr(nfileaddr, fileaddr, unixsw)
|
||||
off_t nfileaddr, fileaddr;
|
||||
struct protosw *unixsw;
|
||||
{
|
||||
register struct file *fp;
|
||||
struct file *filep;
|
||||
struct socket sock, *so = &sock;
|
||||
|
||||
if (nfileaddr == 0 || fileaddr == 0) {
|
||||
printf("nfile or file not in namelist.\n");
|
||||
return;
|
||||
}
|
||||
if (kread(nfileaddr, &nfile, sizeof (nfile)) != sizeof (nfile)) {
|
||||
printf("nfile: bad read.\n");
|
||||
return;
|
||||
}
|
||||
if (kread(fileaddr, &filep, sizeof (filep)) != sizeof (filep)) {
|
||||
printf("File table address, bad read.\n");
|
||||
return;
|
||||
}
|
||||
file = (struct file *)calloc(nfile, sizeof (struct file));
|
||||
if (file == (struct file *)0) {
|
||||
printf("Out of memory (file table).\n");
|
||||
return;
|
||||
}
|
||||
if (kread((off_t)filep, file, nfile * sizeof (struct file)) !=
|
||||
nfile * sizeof (struct file)) {
|
||||
printf("File table read error.\n");
|
||||
return;
|
||||
}
|
||||
fileNFILE = file + nfile;
|
||||
for (fp = file; fp < fileNFILE; fp++) {
|
||||
if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
|
||||
continue;
|
||||
if (kread(fp->f_data, so, sizeof (*so)) != sizeof (*so))
|
||||
continue;
|
||||
/* kludge */
|
||||
if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
|
||||
if (so->so_pcb)
|
||||
unixdomainpr(so, fp->f_data);
|
||||
}
|
||||
free((char *)file);
|
||||
}
|
||||
|
||||
static char *socktype[] =
|
||||
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
|
||||
|
||||
unixdomainpr(so, soaddr)
|
||||
register struct socket *so;
|
||||
caddr_t soaddr;
|
||||
{
|
||||
struct unpcb unpcb, *unp = &unpcb;
|
||||
struct mbuf mbuf, *m;
|
||||
struct sockaddr_un *sa;
|
||||
static int first = 1;
|
||||
|
||||
if (kread(so->so_pcb, unp, sizeof (*unp)) != sizeof (*unp))
|
||||
return;
|
||||
if (unp->unp_addr) {
|
||||
m = &mbuf;
|
||||
if (kread(unp->unp_addr, m, sizeof (*m)) != sizeof (*m))
|
||||
m = (struct mbuf *)0;
|
||||
sa = mtod(m, struct sockaddr_un *);
|
||||
} else
|
||||
m = (struct mbuf *)0;
|
||||
if (first) {
|
||||
printf("Active UNIX domain sockets\n");
|
||||
printf(
|
||||
"%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
|
||||
"Address", "Type", "Recv-Q", "Send-Q",
|
||||
"Vnode", "Conn", "Refs", "Nextref");
|
||||
first = 0;
|
||||
}
|
||||
printf("%8x %-6.6s %6d %6d %8x %8x %8x %8x",
|
||||
soaddr, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc,
|
||||
unp->unp_vnode, unp->unp_conn,
|
||||
unp->unp_refs, unp->unp_nextref);
|
||||
if (m)
|
||||
printf(" %.*s", m->m_len - sizeof(sa->sun_family),
|
||||
sa->sun_path);
|
||||
putchar('\n');
|
||||
}
|
||||
Reference in New Issue
Block a user