Clean up import.

This commit is contained in:
mycroft 1994-05-13 08:08:09 +00:00
parent 6ca69ffc0e
commit d3877f2073
12 changed files with 1102 additions and 1255 deletions

View File

@ -1,19 +1,12 @@
# from: @(#)Makefile 5.14 (Berkeley) 6/18/90 # from: @(#)Makefile 8.1 (Berkeley) 6/12/93
# $Id: Makefile,v 1.6 1994/01/28 00:48:33 cgd Exp $ # $Id: Makefile,v 1.7 1994/05/13 08:08:09 mycroft Exp $
CFLAGS+=-I${DESTDIR}/sys
PROG= netstat PROG= netstat
SRCS= inet.c if.c main.c mbuf.c mroute.c route.c unix.c SRCS= if.c inet.c iso.c main.c mbuf.c mroute.c ns.c route.c \
# unix.c
#SRCS+= host.c #SRCS+= tp_astring.c # XXXX
#CFLAGS+= -DIMP CFLAGS+=-I/sys
.PATH: ${.CURDIR}/../../sys/netiso
SRCS+= ns.c
CFLAGS+= -DNS
SRCS+= iso.c
CFLAGS+= -DISO
BINGRP= kmem BINGRP= kmem
BINMODE=2555 BINMODE=2555
LDADD= -lkvm LDADD= -lkvm

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 1983, 1988 Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,62 +32,51 @@
*/ */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)if.c 5.15 (Berkeley) 3/1/91";*/ /*static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";*/
static char rcsid[] = "$Id: if.c,v 1.7 1994/04/01 09:18:09 cgd Exp $"; static char *rcsid = "$Id: if.c,v 1.8 1994/05/13 08:08:10 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/types.h> #include <sys/types.h>
#include <sys/protosw.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/in_var.h> #include <netinet/in_var.h>
#ifdef NS
#include <netns/ns.h> #include <netns/ns.h>
#include <netns/ns_if.h> #include <netns/ns_if.h>
#endif /* NS */
#ifdef ISO
#include <netiso/iso.h> #include <netiso/iso.h>
#include <netiso/iso_var.h> #include <netiso/iso_var.h>
#endif /* ISO */ #include <arpa/inet.h>
#include <nlist.h>
#include <kvm.h>
#include <stdio.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "netstat.h"
#define YES 1 #define YES 1
#define NO 0 #define NO 0
extern int tflag; static void sidewaysintpr __P((u_int, u_long));
extern int dflag; static void catchalarm __P((int));
extern int nflag;
extern char *interface;
extern int unit;
extern char *routename(), *netname(), *ns_phost();
char *index();
/* /*
* Print a description of the network interfaces. * Print a description of the network interfaces.
*/ */
void
intpr(interval, ifnetaddr) intpr(interval, ifnetaddr)
int interval; int interval;
u_long ifnetaddr; u_long ifnetaddr;
{ {
struct ifnet ifnet; struct ifnet ifnet;
struct in_addr in;
union { union {
struct ifaddr ifa; struct ifaddr ifa;
struct in_ifaddr in; struct in_ifaddr in;
#ifdef NS
struct ns_ifaddr ns; struct ns_ifaddr ns;
#endif
#ifdef ISO
struct iso_ifaddr iso; struct iso_ifaddr iso;
#endif
} ifaddr; } ifaddr;
u_long ifaddraddr; u_long ifaddraddr;
struct sockaddr *sa; struct sockaddr *sa;
@ -101,7 +90,8 @@ intpr(interval, ifnetaddr)
sidewaysintpr((unsigned)interval, ifnetaddr); sidewaysintpr((unsigned)interval, ifnetaddr);
return; return;
} }
kvm_read((void *)(long)ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr); if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr))
return;
printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s", printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
"Opkts", "Oerrs"); "Opkts", "Oerrs");
@ -114,38 +104,36 @@ intpr(interval, ifnetaddr)
ifaddraddr = 0; ifaddraddr = 0;
while (ifnetaddr || ifaddraddr) { while (ifnetaddr || ifaddraddr) {
struct sockaddr_in *sin; struct sockaddr_in *sin;
#ifdef ISO
struct sockaddr_iso *siso;
#endif
register char *cp; register char *cp;
int n, m; int n, m;
struct in_addr inet_makeaddr();
if (ifaddraddr == 0) { if (ifaddraddr == 0) {
kvm_read((void *)(long)ifnetaddr, (char *)&ifnet, if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
sizeof ifnet); kread((u_long)ifnet.if_name, name, 16))
kvm_read(ifnet.if_name, name, 16); return;
name[15] = '\0'; name[15] = '\0';
ifnetaddr = (long)ifnet.if_next; ifnetaddr = (u_long)ifnet.if_next;
if (interface != 0 && if (interface != 0 && (strcmp(name, interface) != 0 ||
(strcmp(name, interface) != 0 || unit != ifnet.if_unit)) unit != ifnet.if_unit))
continue; continue;
cp = index(name, '\0'); cp = index(name, '\0');
cp += sprintf(cp, "%d", ifnet.if_unit); cp += sprintf(cp, "%d", ifnet.if_unit);
if ((ifnet.if_flags&IFF_UP) == 0) if ((ifnet.if_flags&IFF_UP) == 0)
*cp++ = '*'; *cp++ = '*';
*cp = '\0'; *cp = '\0';
ifaddraddr = (long)ifnet.if_addrlist; ifaddraddr = (u_long)ifnet.if_addrlist;
} }
printf("%-5.5s %-5d ", name, ifnet.if_mtu); printf("%-5.5s %-5d ", name, ifnet.if_mtu);
if (ifaddraddr == 0) { if (ifaddraddr == 0) {
printf("%-11.11s ", "none"); printf("%-11.11s ", "none");
printf("%-15.15s ", "none"); printf("%-15.15s ", "none");
} else { } else {
kvm_read((void *)(long)ifaddraddr, (char *)&ifaddr, if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
sizeof ifaddr); ifaddraddr = 0;
continue;
}
#define CP(x) ((char *)(x)) #define CP(x) ((char *)(x))
cp = (CP(ifaddr.ifa.ifa_addr) - CP((long)ifaddraddr)) + cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
CP(&ifaddr); sa = (struct sockaddr *)cp; CP(&ifaddr); sa = (struct sockaddr *)cp;
switch (sa->sa_family) { switch (sa->sa_family) {
case AF_UNSPEC: case AF_UNSPEC:
@ -160,32 +148,31 @@ intpr(interval, ifnetaddr)
*/ */
in = inet_makeaddr(ifaddr.in.ia_subnet, in = inet_makeaddr(ifaddr.in.ia_subnet,
INADDR_ANY); INADDR_ANY);
printf("%-11.11s ", netname(in)); printf("%-11.11s ", netname(in.s_addr,
ifaddr.in.ia_subnetmask));
#else #else
in.s_addr = htonl(ifaddr.in.ia_subnet);
printf("%-11.11s ", printf("%-11.11s ",
netname(in, ifaddr.in.ia_subnetmask)); netname(htonl(ifaddr.in.ia_subnet),
ifaddr.in.ia_subnetmask));
#endif #endif
printf("%-15.15s ", routename(sin->sin_addr)); printf("%-15.15s ",
routename(sin->sin_addr.s_addr));
break; break;
#ifdef NS
case AF_NS: case AF_NS:
{ {
struct sockaddr_ns *sns = struct sockaddr_ns *sns =
(struct sockaddr_ns *)sa; (struct sockaddr_ns *)sa;
u_long net; u_long net;
char netnum[8]; char netnum[8];
char *ns_phost();
*(union ns_net *) &net = sns->sns_addr.x_net; *(union ns_net *) &net = sns->sns_addr.x_net;
sprintf(netnum, "%lxH", ntohl(net)); sprintf(netnum, "%lxH", ntohl(net));
upHex(netnum); upHex(netnum);
printf("ns:%-8s ", netnum); printf("ns:%-8s ", netnum);
printf("%-15s ", ns_phost(sns)); printf("%-15s ",
ns_phost((struct sockaddr *)sns));
} }
break; break;
#endif
case AF_LINK: case AF_LINK:
{ {
struct sockaddr_dl *sdl = struct sockaddr_dl *sdl =
@ -193,24 +180,8 @@ intpr(interval, ifnetaddr)
cp = (char *)LLADDR(sdl); cp = (char *)LLADDR(sdl);
n = sdl->sdl_alen; n = sdl->sdl_alen;
} }
m = printf("%-11.11s ","<Link>"); m = printf("<Link>");
goto hexprint; goto hexprint;
#ifdef ISO
case AF_ISO:
siso = (struct sockaddr_iso *)sa;
if(nflag) {
printf("%27s ",
iso_ntoa(&siso->siso_addr));
} else {
/* This will probably truncate the */
/* NSAP prefix */
printf("%-11.11s ",
iso_ntoa(&siso->siso_addr));
printf("%-15.15s ",
iso_idtoa(&siso->siso_addr));
}
break;
#endif
default: default:
m = printf("(%d)", sa->sa_family); m = printf("(%d)", sa->sa_family);
for (cp = sa->sa_len + (char *)sa; for (cp = sa->sa_len + (char *)sa;
@ -226,7 +197,7 @@ intpr(interval, ifnetaddr)
putchar(' '); putchar(' ');
break; break;
} }
ifaddraddr = (long)ifaddr.ifa.ifa_next; ifaddraddr = (u_long)ifaddr.ifa.ifa_next;
} }
printf("%8d %5d %8d %5d %5d", printf("%8d %5d %8d %5d %5d",
ifnet.if_ipackets, ifnet.if_ierrors, ifnet.if_ipackets, ifnet.if_ierrors,
@ -259,6 +230,7 @@ u_char signalled; /* set if alarm goes off "early" */
* collected over that interval. Assumes that interval is non-zero. * collected over that interval. Assumes that interval is non-zero.
* First line printed at top of screen is always cumulative. * First line printed at top of screen is always cumulative.
*/ */
static void
sidewaysintpr(interval, off) sidewaysintpr(interval, off)
unsigned interval; unsigned interval;
u_long off; u_long off;
@ -269,9 +241,9 @@ sidewaysintpr(interval, off)
register int line; register int line;
struct iftot *lastif, *sum, *interesting; struct iftot *lastif, *sum, *interesting;
int oldmask; int oldmask;
void catchalarm();
kvm_read((void *)(long)off, (char *)&firstifnet, sizeof (u_long)); if (kread(off, (char *)&firstifnet, sizeof (u_long)))
return;
lastif = iftot; lastif = iftot;
sum = iftot + MAXIF - 1; sum = iftot + MAXIF - 1;
total = sum - 1; total = sum - 1;
@ -279,9 +251,11 @@ sidewaysintpr(interval, off)
for (off = firstifnet, ip = iftot; off;) { for (off = firstifnet, ip = iftot; off;) {
char *cp; char *cp;
kvm_read((void *)(long)off, (char *)&ifnet, sizeof ifnet); if (kread(off, (char *)&ifnet, sizeof ifnet))
break;
ip->ift_name[0] = '('; ip->ift_name[0] = '(';
kvm_read(ifnet.if_name, ip->ift_name + 1, 15); if (kread((u_long)ifnet.if_name, ip->ift_name + 1, 15))
break;
if (interface && strcmp(ip->ift_name + 1, interface) == 0 && if (interface && strcmp(ip->ift_name + 1, interface) == 0 &&
unit == ifnet.if_unit) unit == ifnet.if_unit)
interesting = ip; interesting = ip;
@ -291,7 +265,7 @@ sidewaysintpr(interval, off)
ip++; ip++;
if (ip >= iftot + MAXIF - 2) if (ip >= iftot + MAXIF - 2)
break; break;
off = (long)ifnet.if_next; off = (u_long) ifnet.if_next;
} }
lastif = ip; lastif = ip;
@ -334,7 +308,10 @@ loop:
sum->ift_co = 0; sum->ift_co = 0;
sum->ift_dr = 0; sum->ift_dr = 0;
for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) { for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
kvm_read((void *)(long)off, (char *)&ifnet, sizeof ifnet); if (kread(off, (char *)&ifnet, sizeof ifnet)) {
off = 0;
continue;
}
if (ip == interesting) { if (ip == interesting) {
printf("%8d %5d %8d %5d %5d", printf("%8d %5d %8d %5d %5d",
ifnet.if_ipackets - ip->ift_ip, ifnet.if_ipackets - ip->ift_ip,
@ -358,7 +335,7 @@ loop:
sum->ift_oe += ip->ift_oe; sum->ift_oe += ip->ift_oe;
sum->ift_co += ip->ift_co; sum->ift_co += ip->ift_co;
sum->ift_dr += ip->ift_dr; sum->ift_dr += ip->ift_dr;
off = (long)ifnet.if_next; off = (u_long) ifnet.if_next;
} }
if (lastif - iftot > 0) { if (lastif - iftot > 0) {
printf(" %8d %5d %8d %5d %5d", printf(" %8d %5d %8d %5d %5d",
@ -391,8 +368,9 @@ loop:
* Called if an interval expires before sidewaysintpr has completed a loop. * Called if an interval expires before sidewaysintpr has completed a loop.
* Sets a flag to not wait for the alarm. * Sets a flag to not wait for the alarm.
*/ */
void static void
catchalarm() catchalarm(signo)
int signo;
{ {
signalled = YES; signalled = YES;
} }

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 1983, 1988 Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,8 +32,8 @@
*/ */
#ifndef lint #ifndef lint
/* from: static char sccsid[] = "@(#)inet.c 5.15 (Berkeley) 6/18/90"; */ /*static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";*/
static char rcsid[] = "inet.c,v 1.4 1993/05/20 12:03:49 cgd Exp"; static char *rcsid = "$Id: inet.c,v 1.9 1994/05/13 08:08:11 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -62,22 +62,19 @@ static char rcsid[] = "inet.c,v 1.4 1993/05/20 12:03:49 cgd Exp";
#include <netinet/udp.h> #include <netinet/udp.h>
#include <netinet/udp_var.h> #include <netinet/udp_var.h>
#include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <nlist.h> #include <unistd.h>
#include <kvm.h> #include "netstat.h"
struct inpcb inpcb; struct inpcb inpcb;
struct tcpcb tcpcb; struct tcpcb tcpcb;
struct socket sockb; struct socket sockb;
extern int Aflag;
extern int aflag;
extern int nflag;
extern char *plural();
char *inetname(); char *inetname __P((struct in_addr *));
void inetprint __P((struct in_addr *, int, char *));
/* /*
* Print a summary of connections related to an Internet * Print a summary of connections related to an Internet
@ -85,6 +82,7 @@ char *inetname();
* Listening processes (aflag) are suppressed unless the * Listening processes (aflag) are suppressed unless the
* -a (all) flag is specified. * -a (all) flag is specified.
*/ */
void
protopr(off, name) protopr(off, name)
u_long off; u_long off;
char *name; char *name;
@ -97,15 +95,14 @@ protopr(off, name)
if (off == 0) if (off == 0)
return; return;
istcp = strcmp(name, "tcp") == 0; istcp = strcmp(name, "tcp") == 0;
kvm_read((void *)(long)off, (char *)&cb, sizeof (struct inpcb)); kread(off, (char *)&cb, sizeof (struct inpcb));
inpcb = cb; inpcb = cb;
prev = (struct inpcb *)(long)off; prev = (struct inpcb *)off;
if (inpcb.inp_next == (struct inpcb *)(long)off) if (inpcb.inp_next == (struct inpcb *)off)
return; return;
while (inpcb.inp_next != (struct inpcb *)(long)off) { while (inpcb.inp_next != (struct inpcb *)off) {
next = inpcb.inp_next; next = inpcb.inp_next;
kvm_read(next, (char *)&inpcb, sizeof (inpcb)); kread((u_long)next, (char *)&inpcb, sizeof (inpcb));
if (inpcb.inp_prev != prev) { if (inpcb.inp_prev != prev) {
printf("???\n"); printf("???\n");
break; break;
@ -115,10 +112,10 @@ protopr(off, name)
prev = next; prev = next;
continue; continue;
} }
kvm_read(inpcb.inp_socket, (char *)&sockb, sizeof (sockb)); kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof (sockb));
if (istcp) { if (istcp) {
kvm_read(inpcb.inp_ppcb, (char *)&tcpcb, kread((u_long)inpcb.inp_ppcb,
sizeof (tcpcb)); (char *)&tcpcb, sizeof (tcpcb));
} }
if (first) { if (first) {
printf("Active Internet connections"); printf("Active Internet connections");
@ -141,8 +138,8 @@ protopr(off, name)
printf("%8x ", next); printf("%8x ", next);
printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc, printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
sockb.so_snd.sb_cc); sockb.so_snd.sb_cc);
inetprint(&inpcb.inp_laddr, inpcb.inp_lport, name); inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport, name);
inetprint(&inpcb.inp_faddr, inpcb.inp_fport, name); inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport, name);
if (istcp) { if (istcp) {
if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES) if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
printf(" %d", tcpcb.t_state); printf(" %d", tcpcb.t_state);
@ -157,6 +154,7 @@ protopr(off, name)
/* /*
* Dump TCP statistics structure. * Dump TCP statistics structure.
*/ */
void
tcp_stats(off, name) tcp_stats(off, name)
u_long off; u_long off;
char *name; char *name;
@ -166,11 +164,15 @@ tcp_stats(off, name)
if (off == 0) if (off == 0)
return; return;
printf ("%s:\n", name); printf ("%s:\n", name);
kvm_read((void *)(long)off, (char *)&tcpstat, sizeof (tcpstat)); kread(off, (char *)&tcpstat, sizeof (tcpstat));
#define p(f, m) if (tcpstat.f || sflag <= 1) \
printf(m, tcpstat.f, plural(tcpstat.f))
#define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2))
#define p3(f, m) if (tcpstat.f || sflag <= 1) \
printf(m, tcpstat.f, plurales(tcpstat.f))
#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"); p(tcps_sndtotal, "\t%d packet%s sent\n");
p2(tcps_sndpack,tcps_sndbyte, p2(tcps_sndpack,tcps_sndbyte,
"\t\t%d data packet%s (%d byte%s)\n"); "\t\t%d data packet%s (%d byte%s)\n");
@ -190,6 +192,7 @@ tcp_stats(off, name)
"\t\t%d packet%s (%d byte%s) received in-sequence\n"); "\t\t%d packet%s (%d byte%s) received in-sequence\n");
p2(tcps_rcvduppack, tcps_rcvdupbyte, p2(tcps_rcvduppack, tcps_rcvdupbyte,
"\t\t%d completely duplicate packet%s (%d byte%s)\n"); "\t\t%d completely duplicate packet%s (%d byte%s)\n");
p(tcps_pawsdrop, "\t\t%d old duplicate packet%s\n");
p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte,
"\t\t%d packet%s with some dup. data (%d byte%s duped)\n"); "\t\t%d packet%s with some dup. data (%d byte%s duped)\n");
p2(tcps_rcvoopack, tcps_rcvoobyte, p2(tcps_rcvoopack, tcps_rcvoobyte,
@ -216,45 +219,55 @@ tcp_stats(off, name)
p(tcps_keeptimeo, "\t%d keepalive 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_keepprobe, "\t\t%d keepalive probe%s sent\n");
p(tcps_keepdrops, "\t\t%d connection%s dropped by keepalive\n"); p(tcps_keepdrops, "\t\t%d connection%s dropped by keepalive\n");
p(tcps_predack, "\t%d correct ACK header prediction%s\n");
p(tcps_preddat, "\t%d correct data packet header prediction%s\n");
p3(tcps_pcbcachemiss, "\t%d PCB cache miss%s\n");
#undef p #undef p
#undef p2 #undef p2
#undef p3
} }
/* /*
* Dump UDP statistics structure. * Dump UDP statistics structure.
*/ */
void
udp_stats(off, name) udp_stats(off, name)
u_long off; u_long off;
char *name; char *name;
{ {
struct udpstat udpstat; struct udpstat udpstat;
u_long delivered;
if (off == 0) if (off == 0)
return; return;
kvm_read((void *)(long)off, (char *)&udpstat, sizeof (udpstat)); kread(off, (char *)&udpstat, sizeof (udpstat));
printf("%s:\n\t%u packet%s sent\n", name, printf("%s:\n", name);
udpstat.udps_opackets, plural(udpstat.udps_opackets)); #define p(f, m) if (udpstat.f || sflag <= 1) \
printf("\t%u packet%s received\n", printf(m, udpstat.f, plural(udpstat.f))
udpstat.udps_ipackets, plural(udpstat.udps_ipackets)); p(udps_ipackets, "\t%u datagram%s received\n");
printf("\t%u incomplete header%s\n", p(udps_hdrops, "\t%u with incomplete header\n");
udpstat.udps_hdrops, plural(udpstat.udps_hdrops)); p(udps_badlen, "\t%u with bad data length field\n");
printf("\t%u bad data length field%s\n", p(udps_badsum, "\t%u with bad checksum\n");
udpstat.udps_badlen, plural(udpstat.udps_badlen)); p(udps_noport, "\t%u dropped due to no socket\n");
printf("\t%u bad checksum%s\n", p(udps_noportbcast, "\t%u broadcast/multicast datagram%s dropped due to no socket\n");
udpstat.udps_badsum, plural(udpstat.udps_badsum)); p(udps_fullsock, "\t%u dropped due to full socket buffers\n");
printf("\t%u packet%s received on unbound ports\n", delivered = udpstat.udps_ipackets -
udpstat.udps_noport, plural(udpstat.udps_noport)); udpstat.udps_hdrops -
printf("\t%u packet%s received (arrived as bcast) on unbound ports\n", udpstat.udps_badlen -
udpstat.udps_noportbcast, plural(udpstat.udps_noportbcast)); udpstat.udps_badsum -
printf("\t%u packet%s dropped, socket full\n", udpstat.udps_noport -
udpstat.udps_fullsock, plural(udpstat.udps_fullsock)); udpstat.udps_noportbcast -
printf("\t%u packet%s missed pcb cache\n", udpstat.udps_fullsock;
udpstat.udpps_pcbcachemiss, plural(udpstat.udpps_pcbcachemiss)); if (delivered || sflag <= 1)
printf("\t%u delivered\n", delivered);
p(udps_opackets, "\t%u datagram%s output\n");
#undef p
} }
/* /*
* Dump IP statistics structure. * Dump IP statistics structure.
*/ */
void
ip_stats(off, name) ip_stats(off, name)
u_long off; u_long off;
char *name; char *name;
@ -263,27 +276,37 @@ ip_stats(off, name)
if (off == 0) if (off == 0)
return; return;
kvm_read((void *)(long)off, (char *)&ipstat, sizeof (ipstat)); kread(off, (char *)&ipstat, sizeof (ipstat));
printf("%s:\n\t%u total packets received\n", name, printf("%s:\n", name);
ipstat.ips_total);
printf("\t%u bad header checksum%s\n", #define p(f, m) if (ipstat.f || sflag <= 1) \
ipstat.ips_badsum, plural(ipstat.ips_badsum)); printf(m, ipstat.f, plural(ipstat.f))
printf("\t%u with size smaller than minimum\n", ipstat.ips_tooshort);
printf("\t%u with data size < data length\n", ipstat.ips_toosmall); p(ips_total, "\t%u total packet%s received\n");
printf("\t%u with header length < data size\n", ipstat.ips_badhlen); p(ips_badsum, "\t%u bad header checksum%s\n");
printf("\t%u with data length < header length\n", ipstat.ips_badlen); p(ips_toosmall, "\t%u with size smaller than minimum\n");
printf("\t%u fragment%s received\n", p(ips_tooshort, "\t%u with data size < data length\n");
ipstat.ips_fragments, plural(ipstat.ips_fragments)); p(ips_badhlen, "\t%u with header length < data size\n");
printf("\t%u fragment%s dropped (dup or out of space)\n", p(ips_badlen, "\t%u with data length < header length\n");
ipstat.ips_fragdropped, plural(ipstat.ips_fragdropped)); p(ips_badoptions, "\t%u with bad options\n");
printf("\t%u fragment%s dropped after timeout\n", p(ips_badvers, "\t%u with incorrect version number\n");
ipstat.ips_fragtimeout, plural(ipstat.ips_fragtimeout)); p(ips_fragments, "\t%u fragment%s received\n");
printf("\t%u packet%s forwarded\n", p(ips_fragdropped, "\t%u fragment%s dropped (dup or out of space)\n");
ipstat.ips_forward, plural(ipstat.ips_forward)); p(ips_fragtimeout, "\t%u fragment%s dropped after timeout\n");
printf("\t%u packet%s not forwardable\n", p(ips_reassembled, "\t%u packet%s reassembled ok\n");
ipstat.ips_cantforward, plural(ipstat.ips_cantforward)); p(ips_delivered, "\t%u packet%s for this host\n");
printf("\t%u redirect%s sent\n", p(ips_noproto, "\t%u packet%s for unknown/unsupported protocol\n");
ipstat.ips_redirectsent, plural(ipstat.ips_redirectsent)); p(ips_forward, "\t%u packet%s forwarded\n");
p(ips_cantforward, "\t%u packet%s not forwardable\n");
p(ips_redirectsent, "\t%u redirect%s sent\n");
p(ips_localout, "\t%u packet%s sent from this host\n");
p(ips_rawout, "\t%u packet%s sent with fabricated ip header\n");
p(ips_odropped, "\t%u output packet%s dropped due to no bufs, etc.\n");
p(ips_noroute, "\t%u output packet%s discarded due to no route\n");
p(ips_fragmented, "\t%u output datagram%s fragmented\n");
p(ips_ofragments, "\t%u fragment%s created\n");
p(ips_cantfrag, "\t%u datagram%s that can't be fragmented\n");
#undef p
} }
static char *icmpnames[] = { static char *icmpnames[] = {
@ -311,6 +334,7 @@ static char *icmpnames[] = {
/* /*
* Dump ICMP statistics. * Dump ICMP statistics.
*/ */
void
icmp_stats(off, name) icmp_stats(off, name)
u_long off; u_long off;
char *name; char *name;
@ -320,11 +344,15 @@ icmp_stats(off, name)
if (off == 0) if (off == 0)
return; return;
kvm_read((void *)(long)off, (char *)&icmpstat, sizeof (icmpstat)); kread(off, (char *)&icmpstat, sizeof (icmpstat));
printf("%s:\n\t%u call%s to icmp_error\n", name, printf("%s:\n", name);
icmpstat.icps_error, plural(icmpstat.icps_error));
printf("\t%u error%s not generated 'cuz old message was icmp\n", #define p(f, m) if (icmpstat.f || sflag <= 1) \
icmpstat.icps_oldicmp, plural(icmpstat.icps_oldicmp)); printf(m, icmpstat.f, plural(icmpstat.f))
p(icps_error, "\t%u call%s to icmp_error\n");
p(icps_oldicmp,
"\t%u error%s not generated 'cuz old message was icmp\n");
for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
if (icmpstat.icps_outhist[i] != 0) { if (icmpstat.icps_outhist[i] != 0) {
if (first) { if (first) {
@ -334,14 +362,10 @@ icmp_stats(off, name)
printf("\t\t%s: %u\n", icmpnames[i], printf("\t\t%s: %u\n", icmpnames[i],
icmpstat.icps_outhist[i]); icmpstat.icps_outhist[i]);
} }
printf("\t%u message%s with bad code fields\n", p(icps_badcode, "\t%u message%s with bad code fields\n");
icmpstat.icps_badcode, plural(icmpstat.icps_badcode)); p(icps_tooshort, "\t%u message%s < minimum length\n");
printf("\t%u message%s < minimum length\n", p(icps_checksum, "\t%u bad checksum%s\n");
icmpstat.icps_tooshort, plural(icmpstat.icps_tooshort)); p(icps_badlen, "\t%u message%s with bad length\n");
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++) for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
if (icmpstat.icps_inhist[i] != 0) { if (icmpstat.icps_inhist[i] != 0) {
if (first) { if (first) {
@ -351,18 +375,12 @@ icmp_stats(off, name)
printf("\t\t%s: %u\n", icmpnames[i], printf("\t\t%s: %u\n", icmpnames[i],
icmpstat.icps_inhist[i]); icmpstat.icps_inhist[i]);
} }
printf("\t%u message response%s generated\n", p(icps_reflect, "\t%u message response%s generated\n");
icmpstat.icps_reflect, plural(icmpstat.icps_reflect)); #undef p
}
char*
pluraly(n)
{
return (n == 1? "y" : "ies");
} }
/* /*
* Dump IGMP statistics. * Dump IGMP statistics structure.
*/ */
void void
igmp_stats(off, name) igmp_stats(off, name)
@ -370,46 +388,44 @@ igmp_stats(off, name)
char *name; char *name;
{ {
struct igmpstat igmpstat; struct igmpstat igmpstat;
register int i, first;
if (off == 0) if (off == 0)
return; return;
kvm_read((void *)(long)off, (char *)&igmpstat, sizeof (igmpstat)); kread(off, (char *)&igmpstat, sizeof (igmpstat));
printf("%s:\n", name ); printf("%s:\n", name);
printf("\t%u message%s received\n",
igmpstat.igps_rcv_total, plural(igmpstat.igps_rcv_total)); #define p(f, m) if (igmpstat.f || sflag <= 1) \
printf("\t%u message%s received with too few bytes\n", printf(m, igmpstat.f, plural(igmpstat.f))
igmpstat.igps_rcv_tooshort, plural(igmpstat.igps_rcv_tooshort)); #define py(f, m) if (igmpstat.f || sflag <= 1) \
printf("\t%u message%s received with bad checksum\n", printf(m, igmpstat.f, igmpstat.f != 1 ? "ies" : "y")
igmpstat.igps_rcv_badsum, plural(igmpstat.igps_rcv_badsum)); p(igps_rcv_total, "\t%u message%s received\n");
printf("\t%u membership quer%s received\n", p(igps_rcv_tooshort, "\t%u message%s received with too few bytes\n");
igmpstat.igps_rcv_queries, pluraly(igmpstat.igps_rcv_queries)); p(igps_rcv_badsum, "\t%u message%s received with bad checksum\n");
printf("\t%u membership quer%s received with invalid field(s)\n", py(igps_rcv_queries, "\t%u membership quer%s received\n");
igmpstat.igps_rcv_badqueries, pluraly(igmpstat.igps_rcv_badqueries)); py(igps_rcv_badqueries, "\t%u membership quer%s received with invalid field(s)\n");
printf("\t%u membership report%s received\n", p(igps_rcv_reports, "\t%u membership report%s received\n");
igmpstat.igps_rcv_reports, plural(igmpstat.igps_rcv_reports)); p(igps_rcv_badreports, "\t%u membership report%s received with invalid field(s)\n");
printf("\t%u membership report%s received with invalid field(s)\n", p(igps_rcv_ourreports, "\t%u membership report%s received for groups to which we belong\n");
igmpstat.igps_rcv_badreports, plural(igmpstat.igps_rcv_badreports)); p(igps_snd_reports, "\t%u membership report%s sent\n");
printf("\t%u membership report%s received for groups to which we belong\n", #undef p
igmpstat.igps_rcv_ourreports, plural(igmpstat.igps_rcv_ourreports)); #undef py
printf("\t%u membership report%s sent\n",
igmpstat.igps_snd_reports, plural(igmpstat.igps_snd_reports));
} }
/* /*
* Pretty print an Internet address (net address + port). * Pretty print an Internet address (net address + port).
* If the nflag was specified, use numbers instead of names. * If the nflag was specified, use numbers instead of names.
*/ */
void
inetprint(in, port, proto) inetprint(in, port, proto)
register struct in_addr *in; register struct in_addr *in;
u_short port; int port;
char *proto; char *proto;
{ {
struct servent *sp = 0; struct servent *sp = 0;
char line[80], *cp, *index(); char line[80], *cp;
int width; int width;
sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inetname(*in)); sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inetname(in));
cp = index(line, '\0'); cp = index(line, '\0');
if (!nflag && port) if (!nflag && port)
sp = getservbyport((int)port, proto); sp = getservbyport((int)port, proto);
@ -423,12 +439,12 @@ inetprint(in, port, proto)
/* /*
* Construct an Internet address representation. * Construct an Internet address representation.
* If the nflag has been supplied, give * If the nflag has been supplied, give
* numeric value, otherwise try for symbolic name. * numeric value, otherwise try for symbolic name.
*/ */
char * char *
inetname(in) inetname(inp)
struct in_addr in; struct in_addr *inp;
{ {
register char *cp; register char *cp;
static char line[50]; static char line[50];
@ -446,9 +462,9 @@ inetname(in)
domain[0] = 0; domain[0] = 0;
} }
cp = 0; cp = 0;
if (!nflag && in.s_addr != INADDR_ANY) { if (!nflag && inp->s_addr != INADDR_ANY) {
int net = inet_netof(in); int net = inet_netof(*inp);
int lna = inet_lnaof(in); int lna = inet_lnaof(*inp);
if (lna == INADDR_ANY) { if (lna == INADDR_ANY) {
np = getnetbyaddr(net, AF_INET); np = getnetbyaddr(net, AF_INET);
@ -456,7 +472,7 @@ inetname(in)
cp = np->n_name; cp = np->n_name;
} }
if (cp == 0) { if (cp == 0) {
hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET); hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
if (hp) { if (hp) {
if ((cp = index(hp->h_name, '.')) && if ((cp = index(hp->h_name, '.')) &&
!strcmp(cp + 1, domain)) !strcmp(cp + 1, domain))
@ -465,15 +481,15 @@ inetname(in)
} }
} }
} }
if (in.s_addr == INADDR_ANY) if (inp->s_addr == INADDR_ANY)
strcpy(line, "*"); strcpy(line, "*");
else if (cp) else if (cp)
strcpy(line, cp); strcpy(line, cp);
else { else {
in.s_addr = ntohl(in.s_addr); inp->s_addr = ntohl(inp->s_addr);
#define C(x) ((x) & 0xff) #define C(x) ((x) & 0xff)
sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24), sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24),
C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr));
} }
return (line); return (line);
} }

View File

@ -1,6 +1,6 @@
/*- /*
* Copyright (c) 1989, 1990 The Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,8 +32,8 @@
*/ */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)iso.c 5.6 (Berkeley) 4/27/91";*/ /*static char sccsid[] = "from: @(#)iso.c 8.1 (Berkeley) 6/6/93";*/
static char rcsid[] = "$Id: iso.c,v 1.8 1994/04/01 09:18:11 cgd Exp $"; static char *rcsid = "$Id: iso.c,v 1.9 1994/05/13 08:08:13 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
/******************************************************************************* /*******************************************************************************
@ -41,13 +41,13 @@ static char rcsid[] = "$Id: iso.c,v 1.8 1994/04/01 09:18:11 cgd Exp $";
All Rights Reserved All Rights Reserved
Permission to use, copy, modify, and distribute this software and its Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission. software without specific, written prior permission.
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
@ -63,7 +63,6 @@ SOFTWARE.
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
*/ */
#include <stdio.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <sys/time.h> #include <sys/time.h>
@ -74,6 +73,11 @@ SOFTWARE.
#include <errno.h> #include <errno.h>
#include <net/if.h> #include <net/if.h>
#include <net/route.h> #include <net/route.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/in_pcb.h>
#include <netinet/ip_var.h>
#include <netiso/iso.h> #include <netiso/iso.h>
#include <netiso/iso_errno.h> #include <netiso/iso_errno.h>
#include <netiso/clnp.h> #include <netiso/clnp.h>
@ -92,63 +96,31 @@ SOFTWARE.
#undef IncStat #undef IncStat
#endif #endif
#include <netiso/cons_pcb.h> #include <netiso/cons_pcb.h>
#include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <nlist.h> #include <string.h>
#include <kvm.h> #include <stdio.h>
#include <stdlib.h>
#include "netstat.h"
char *tp_sstring[] = { static void tprintstat __P((struct tp_stat *, int));
"ST_ERROR(0x0)", static void isonetprint __P((struct sockaddr_iso *, int));
"TP_CLOSED(0x1)", static void hexprint __P((int, char *, char *));
"TP_CRSENT(0x2)", extern void inetprint __P((struct in_addr *, int, char *));
"TP_AKWAIT(0x3)",
"TP_OPEN(0x4)",
"TP_CLOSING(0x5)",
"TP_REFWAIT(0x6)",
"TP_LISTENING(0x7)",
"TP_CONFIRMING(0x8)",
};
char *tp_estring[] = {
"TM_inact(0x0)",
"TM_retrans(0x1)",
"TM_sendack(0x2)",
"TM_notused(0x3)",
"TM_reference(0x4)",
"TM_data_retrans(0x5)",
"ER_TPDU(0x6)",
"CR_TPDU(0x7)",
"DR_TPDU(0x8)",
"DC_TPDU(0x9)",
"CC_TPDU(0xa)",
"AK_TPDU(0xb)",
"DT_TPDU(0xc)",
"XPD_TPDU(0xd)",
"XAK_TPDU(0xe)",
"T_CONN_req(0xf)",
"T_DISC_req(0x10)",
"T_LISTEN_req(0x11)",
"T_DATA_req(0x12)",
"T_XPD_req(0x13)",
"T_USR_rcvd(0x14)",
"T_USR_Xrcvd(0x15)",
"T_DETACH(0x16)",
"T_NETRESET(0x17)",
"T_ACPT_req(0x18)",
};
/* /*
* Dump esis stats * Dump esis stats
*/ */
void
esis_stats(off, name) esis_stats(off, name)
u_long off; u_long off;
char *name; char *name;
{ {
struct esis_stat esis_stat; struct esis_stat esis_stat;
if (off == 0) if (off == 0 ||
kread(off, (char *)&esis_stat, sizeof (struct esis_stat)))
return; return;
kvm_read((void *)(long)off, (char *)&esis_stat,
sizeof (struct esis_stat));
printf("%s:\n", name); printf("%s:\n", name);
printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent, printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent,
esis_stat.es_eshrcvd); esis_stat.es_eshrcvd);
@ -156,10 +128,10 @@ esis_stats(off, name)
esis_stat.es_ishrcvd); esis_stat.es_ishrcvd);
printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent, printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,
esis_stat.es_rdrcvd); esis_stat.es_rdrcvd);
printf("\t%d pdus not sent due to insufficient memory\n", printf("\t%d pdus not sent due to insufficient memory\n",
esis_stat.es_nomem); esis_stat.es_nomem);
printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum); printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum);
printf("\t%d pdus received with bad version number\n", printf("\t%d pdus received with bad version number\n",
esis_stat.es_badvers); esis_stat.es_badvers);
printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype); printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype);
printf("\t%d short pdus received\n", esis_stat.es_toosmall); printf("\t%d short pdus received\n", esis_stat.es_toosmall);
@ -168,49 +140,51 @@ esis_stats(off, name)
/* /*
* Dump clnp statistics structure. * Dump clnp statistics structure.
*/ */
void
clnp_stats(off, name) clnp_stats(off, name)
u_long off; u_long off;
char *name; char *name;
{ {
struct clnp_stat clnp_stat; struct clnp_stat clnp_stat;
if (off == 0) if (off == 0 ||
kread(off, (char *)&clnp_stat, sizeof (clnp_stat)))
return; return;
kvm_read((void *)(long)off, (char *)&clnp_stat, sizeof (clnp_stat));
printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent); printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent);
printf("\t%d total fragments sent\n", clnp_stat.cns_fragments); printf("\t%d total fragments sent\n", clnp_stat.cns_fragments);
printf("\t%d total packets received\n", clnp_stat.cns_total); printf("\t%d total packets received\n", clnp_stat.cns_total);
printf("\t%d with fixed part of header too small\n", printf("\t%d with fixed part of header too small\n",
clnp_stat.cns_toosmall); clnp_stat.cns_toosmall);
printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen); printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);
printf("\t%d incorrect checksum%s\n", printf("\t%d incorrect checksum%s\n",
clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum)); clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));
printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr); printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);
printf("\t%d with forgotten segmentation information\n", printf("\t%d with forgotten segmentation information\n",
clnp_stat.cns_noseg); clnp_stat.cns_noseg);
printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto); printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto);
printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers); printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers);
printf("\t%d dropped because the ttl has expired\n", printf("\t%d dropped because the ttl has expired\n",
clnp_stat.cns_ttlexpired); clnp_stat.cns_ttlexpired);
printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss); printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);
printf("\t%d clnp congestion experience bits set\n", printf("\t%d clnp congestion experience bits set\n",
clnp_stat.cns_congest_set); clnp_stat.cns_congest_set);
printf("\t%d clnp congestion experience bits received\n", printf("\t%d clnp congestion experience bits received\n",
clnp_stat.cns_congest_rcvd); clnp_stat.cns_congest_rcvd);
} }
/* /*
* Dump CLTP statistics structure. * Dump CLTP statistics structure.
*/ */
void
cltp_stats(off, name) cltp_stats(off, name)
u_long off; u_long off;
char *name; char *name;
{ {
struct cltpstat cltpstat; struct cltpstat cltpstat;
if (off == 0) if (off == 0 ||
kread(off, (char *)&cltpstat, sizeof (cltpstat)))
return; return;
kvm_read((void *)(long)off, (char *)&cltpstat, sizeof (cltpstat));
printf("%s:\n\t%u incomplete header%s\n", name, printf("%s:\n\t%u incomplete header%s\n", name,
cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops)); cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops));
printf("\t%u bad data length field%s\n", printf("\t%u bad data length field%s\n",
@ -223,14 +197,11 @@ struct tp_pcb tpcb;
struct isopcb isopcb; struct isopcb isopcb;
struct socket sockb; struct socket sockb;
union { union {
struct sockaddr_iso siso; struct sockaddr_iso siso;
char data[128]; char data[128];
} laddr, faddr; } laddr, faddr;
#define kget(o, p) \ #define kget(o, p) \
(kvm_read((void *)(long)(o), (char *)&p, sizeof (p))) (kread((u_long)(o), (char *)&p, sizeof (p)))
extern int Aflag;
extern int aflag;
extern int nflag;
static int first = 1; static int first = 1;
@ -240,26 +211,29 @@ static int first = 1;
* Listening processes (aflag) are suppressed unless the * Listening processes (aflag) are suppressed unless the
* -a (all) flag is specified. * -a (all) flag is specified.
*/ */
void
iso_protopr(off, name) iso_protopr(off, name)
u_long off; u_long off;
char *name; char *name;
{ {
struct isopcb cb; struct isopcb cb;
register struct isopcb *prev, *next; register struct isopcb *prev, *next;
int istp = (strcmp(name, "tp") == 0);
if (off == 0) { if (off == 0) {
#ifdef DEBUG
printf("%s control block: symbol not in namelist\n", name); printf("%s control block: symbol not in namelist\n", name);
#endif
return; return;
} }
kget(off, cb); if (strcmp(name, "tp") == 0) {
isopcb = cb; tp_protopr(off, name);
prev = (struct isopcb *)(long)off;
if (isopcb.isop_next == (struct isopcb *)(long)off)
return; return;
while (isopcb.isop_next != (struct isopcb *)(long)off) { }
if (kread(off, (char *)&cb, sizeof(cb)))
return;
isopcb = cb;
prev = (struct isopcb *)off;
if (isopcb.isop_next == (struct isopcb *)off)
return;
while (isopcb.isop_next != (struct isopcb *)off) {
next = isopcb.isop_next; next = isopcb.isop_next;
kget(next, isopcb); kget(next, isopcb);
if (isopcb.isop_prev != prev) { if (isopcb.isop_prev != prev) {
@ -268,68 +242,127 @@ iso_protopr(off, name)
break; break;
} }
kget(isopcb.isop_socket, sockb); kget(isopcb.isop_socket, sockb);
if (istp) { iso_protopr1((u_long)next, 0);
kget(sockb.so_tpcb, tpcb);
if (tpcb.tp_state == ST_ERROR)
fprintf(stderr,"addr: 0x%x, prev 0x%x\n", next, prev);
if (!aflag &&
tpcb.tp_state == TP_LISTENING ||
tpcb.tp_state == TP_CLOSED ||
tpcb.tp_state == TP_REFWAIT) {
prev = next;
continue;
}
}
if (first) {
printf("Active ISO net 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 ",
(istp ? (long)sockb.so_tpcb : (long)next));
printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
sockb.so_snd.sb_cc);
if (isopcb.isop_laddr == 0)
printf("*.*\t");
else {
if ((char *)isopcb.isop_laddr == ((char *)next) +
_offsetof(struct isopcb, isop_sladdr))
laddr.siso = isopcb.isop_sladdr;
else
kget(isopcb.isop_laddr, laddr);
isonetprint(&laddr, 1);
}
if (isopcb.isop_faddr == 0)
printf("*.*\t");
else {
if ((char *)isopcb.isop_faddr == ((char *)next) +
_offsetof(struct isopcb, isop_sfaddr))
faddr.siso = isopcb.isop_sfaddr;
else
kget(isopcb.isop_faddr, faddr);
isonetprint(&faddr, 0);
}
if (istp) {
if (tpcb.tp_state >= tp_NSTATES)
printf(" %d", tpcb.tp_state);
else
printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
}
putchar('\n'); putchar('\n');
prev = next; prev = next;
} }
} }
void
iso_protopr1(kern_addr, istp)
u_long kern_addr;
int istp;
{
if (first) {
printf("Active ISO net 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 ",
(sockb.so_pcb ? (void *)sockb.so_pcb : (void *)kern_addr));
printf("%-5.5s %6d %6d ", "tp", sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
if (istp && tpcb.tp_lsuffixlen) {
hexprint(tpcb.tp_lsuffixlen, tpcb.tp_lsuffix, "()");
printf("\t");
} else if (isopcb.isop_laddr == 0)
printf("*.*\t");
else {
if ((char *)isopcb.isop_laddr == ((char *)kern_addr) +
_offsetof(struct isopcb, isop_sladdr))
laddr.siso = isopcb.isop_sladdr;
else
kget(isopcb.isop_laddr, laddr);
isonetprint((struct sockaddr_iso *)&laddr, 1);
}
if (istp && tpcb.tp_fsuffixlen) {
hexprint(tpcb.tp_fsuffixlen, tpcb.tp_fsuffix, "()");
printf("\t");
} else if (isopcb.isop_faddr == 0)
printf("*.*\t");
else {
if ((char *)isopcb.isop_faddr == ((char *)kern_addr) +
_offsetof(struct isopcb, isop_sfaddr))
faddr.siso = isopcb.isop_sfaddr;
else
kget(isopcb.isop_faddr, faddr);
isonetprint((struct sockaddr_iso *)&faddr, 0);
}
}
void
tp_protopr(off, name)
u_long off;
char *name;
{
#ifdef notyet /* XXXX */
extern char *tp_sstring[];
struct tp_ref *tpr, *tpr_base;
struct tp_refinfo tpkerninfo;
int size;
kget(off, tpkerninfo);
size = tpkerninfo.tpr_size * sizeof (*tpr);
tpr_base = (struct tp_ref *)malloc(size);
if (tpr_base == 0)
return;
kread((u_long)(tpkerninfo.tpr_base), (char *)tpr_base, size);
for (tpr = tpr_base; tpr < tpr_base + tpkerninfo.tpr_size; tpr++) {
if (tpr->tpr_pcb == 0)
continue;
kget(tpr->tpr_pcb, tpcb);
if (tpcb.tp_state == ST_ERROR)
printf("undefined tpcb state: 0x%x\n", tpr->tpr_pcb);
if (!aflag &&
(tpcb.tp_state == TP_LISTENING ||
tpcb.tp_state == TP_CLOSED ||
tpcb.tp_state == TP_REFWAIT)) {
continue;
}
kget(tpcb.tp_sock, sockb);
if (tpcb.tp_npcb) switch(tpcb.tp_netservice) {
case IN_CLNS:
tp_inproto((u_long)tpkerninfo.tpr_base);
break;
default:
kget(tpcb.tp_npcb, isopcb);
iso_protopr1((u_long)tpcb.tp_npcb, 1);
break;
}
if (tpcb.tp_state >= tp_NSTATES)
printf(" %d", tpcb.tp_state);
else
printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
putchar('\n');
}
#endif
}
void
tp_inproto(pcb)
u_long pcb;
{
struct inpcb inpcb;
kget(tpcb.tp_npcb, inpcb);
if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
return;
if (Aflag)
printf("%8x ", pcb);
printf("%-5.5s %6d %6d ", "tpip",
sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
inetprint(&inpcb.inp_laddr, inpcb.inp_lport, "tp");
inetprint(&inpcb.inp_faddr, inpcb.inp_fport, "tp");
}
/* /*
* Pretty print an iso address (net address + port). * Pretty print an iso address (net address + port).
* If the nflag was specified, use numbers instead of names. * If the nflag was specified, use numbers instead of names.
@ -346,7 +379,6 @@ isonetname(iso)
struct iso_hostent *iso_getserventrybytsel(); struct iso_hostent *iso_getserventrybytsel();
struct iso_hostent Ihe; struct iso_hostent Ihe;
static char line[80]; static char line[80];
char *index();
bzero(line, sizeof(line)); bzero(line, sizeof(line));
if( iso->isoa_afi ) { if( iso->isoa_afi ) {
@ -369,6 +401,7 @@ isonetname(iso)
return line; return line;
} }
static void
isonetprint(iso, sufx, sufxlen, islocal) isonetprint(iso, sufx, sufxlen, islocal)
register struct iso_addr *iso; register struct iso_addr *iso;
char *sufx; char *sufx;
@ -377,7 +410,7 @@ isonetprint(iso, sufx, sufxlen, islocal)
{ {
struct iso_hostent *iso_getserventrybytsel(), *ihe; struct iso_hostent *iso_getserventrybytsel(), *ihe;
struct iso_hostent Ihe; struct iso_hostent Ihe;
char *line, *cp, *index(); char *line, *cp;
int Alen = Aflag?18:22; int Alen = Aflag?18:22;
line = isonetname(iso); line = isonetname(iso);
@ -386,7 +419,7 @@ isonetprint(iso, sufx, sufxlen, islocal)
if( islocal ) if( islocal )
islocal = 20; islocal = 20;
else else
islocal = 22 + Alen; islocal = 22 + Alen;
if(Aflag) if(Aflag)
@ -426,6 +459,7 @@ isonetprint(iso, sufx, sufxlen, islocal)
#endif #endif
#ifdef notdef #ifdef notdef
static void
x25_protopr(off, name) x25_protopr(off, name)
u_long off; u_long off;
char *name; char *name;
@ -442,23 +476,21 @@ x25_protopr(off, name)
struct x25_pcb xpcb; struct x25_pcb xpcb;
if (off == 0) { if (off == 0) {
#ifdef DEBUG
printf("%s control block: symbol not in namelist\n", name); printf("%s control block: symbol not in namelist\n", name);
#endif
return; return;
} }
kvm_read(off, &xpcb, sizeof (struct x25_pcb)); kread(off, &xpcb, sizeof (struct x25_pcb));
prev = (struct isopcb *)off; prev = (struct isopcb *)off;
if (xpcb.x_next == (struct isopcb *)off) if (xpcb.x_next == (struct isopcb *)off)
return; return;
while (xpcb.x_next != (struct isopcb *)off) { while (xpcb.x_next != (struct isopcb *)off) {
next = isopcb.isop_next; next = isopcb.isop_next;
kvm_read(next, &xpcb, sizeof (struct x25_pcb)); kread((u_long)next, &xpcb, sizeof (struct x25_pcb));
if (xpcb.x_prev != prev) { if (xpcb.x_prev != prev) {
printf("???\n"); printf("???\n");
break; break;
} }
kvm_read(xpcb.x_socket, &sockb, sizeof (sockb)); kread((u_long)xpcb.x_socket, &sockb, sizeof (sockb));
if (!aflag && if (!aflag &&
xpcb.x_state == LISTENING || xpcb.x_state == LISTENING ||
@ -482,9 +514,9 @@ x25_protopr(off, name)
} }
printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc, printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
sockb.so_snd.sb_cc); sockb.so_snd.sb_cc);
isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport, isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport,
sizeof(xpcb.x_lport), 1); sizeof(xpcb.x_lport), 1);
isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport, isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport,
sizeof(xpcb.x_lport), 0); sizeof(xpcb.x_lport), 0);
if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES) if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES)
printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state); printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state);
@ -498,8 +530,9 @@ x25_protopr(off, name)
struct tp_stat tp_stat; struct tp_stat tp_stat;
void
tp_stats(off, name) tp_stats(off, name)
caddr_t off, name; caddr_t off, name;
{ {
if (off == 0) { if (off == 0) {
printf("TP not configured\n\n"); printf("TP not configured\n\n");
@ -512,11 +545,10 @@ caddr_t off, name;
#define OUT stdout #define OUT stdout
#define plural(x) (x>1?"s":"") static void
tprintstat(s, indent) tprintstat(s, indent)
register struct tp_stat *s; register struct tp_stat *s;
int indent; int indent;
{ {
fprintf(OUT, fprintf(OUT,
"%*sReceiving:\n",indent," "); "%*sReceiving:\n",indent," ");
@ -587,7 +619,7 @@ int indent;
"\t%*s%d cluster%s\n", indent, " ", "\t%*s%d cluster%s\n", indent, " ",
s->ts_mb_cluster, plural(s->ts_mb_cluster)); s->ts_mb_cluster, plural(s->ts_mb_cluster));
fprintf(OUT, fprintf(OUT,
"\t%*s%d source quench \n",indent, " ", "\t%*s%d source quench \n",indent, " ",
s->ts_quench); s->ts_quench);
fprintf(OUT, fprintf(OUT,
"\t%*s%d dec bit%s\n", indent, " ", "\t%*s%d dec bit%s\n", indent, " ",
@ -635,46 +667,35 @@ int indent;
fprintf(OUT, fprintf(OUT,
"\t%*s%d tp 0 connection%s\n", indent, " ", "\t%*s%d tp 0 connection%s\n", indent, " ",
s->ts_tp0_conn ,plural(s->ts_tp0_conn)); s->ts_tp0_conn ,plural(s->ts_tp0_conn));
{ {
register int j, div; register int j;
register float f;
static char *name[]= { static char *name[]= {
"~LOCAL, PDN", "~LOCAL, PDN",
"~LOCAL,~PDN", "~LOCAL,~PDN",
" LOCAL,~PDN", " LOCAL,~PDN",
" LOCAL, PDN" " LOCAL, PDN"
}; };
#define factor(i) \
div = (s->ts_rtt[(i)].tv_sec * 1000000) + \
s->ts_rtt[(i)].tv_usec ;\
if(div) {\
f = ((s->ts_rtv[(i)].tv_sec * 1000000) + \
s->ts_rtv[(i)].tv_usec)/div; \
div = (int) (f + 0.5);\
}
fprintf(OUT, fprintf(OUT,
"\n%*sRound trip times, listed in (sec: usec):\n", indent, " "); "\n%*sRound trip times, listed in ticks:\n", indent, " ");
fprintf(OUT, fprintf(OUT,
"\t%*s%11.11s %12.12s | %12.12s | %s\n", indent, " ", "\t%*s%11.11s %12.12s | %12.12s | %s\n", indent, " ",
"Category", "Category",
"Smoothed avg", "Deviation", "Deviation/Avg"); "Smoothed avg", "Deviation", "Deviation/Avg");
for( j=0; j<=3; j++) { for (j = 0; j <= 3; j++) {
factor(j);
fprintf(OUT, fprintf(OUT,
"\t%*s%11.11s: %5d:%-6d | %5d:%-6d | %-6d\n", indent, " ", "\t%*s%11.11s: %-11d | %-11d | %-11d | %-11d\n", indent, " ",
name[j], name[j],
s->ts_rtt[j].tv_sec, s->ts_rtt[j],
s->ts_rtt[j].tv_usec, s->ts_rtt[j],
s->ts_rtv[j].tv_sec, s->ts_rtv[j],
s->ts_rtv[j].tv_usec, s->ts_rtv[j]);
div);
} }
} }
fprintf(OUT, fprintf(OUT,
"\n%*sTpdus RECVD [%d valid, %3.6f %% of total (%d); %d dropped]\n",indent," ", "\n%*sTpdus RECVD [%d valid, %3.6f %% of total (%d); %d dropped]\n",indent," ",
s->ts_tpdu_rcvd , s->ts_tpdu_rcvd ,
((s->ts_pkt_rcvd > 0) ? ((s->ts_pkt_rcvd > 0) ?
((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd) ((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd)
: 0), : 0),
s->ts_pkt_rcvd, s->ts_pkt_rcvd,
@ -714,7 +735,7 @@ int indent;
"\t%*sXPD %6d (%5.2f%%)\n", indent, " ", "\t%*sXPD %6d (%5.2f%%)\n", indent, " ",
s->ts_retrans_xpd, s->ts_retrans_xpd,
PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent)); PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent));
fprintf(OUT, fprintf(OUT,
"\n%*sE Timers: [%6d ticks]\n", indent, " ", s->ts_Eticks); "\n%*sE Timers: [%6d ticks]\n", indent, " ", s->ts_Eticks);
@ -755,30 +776,31 @@ int indent;
fprintf(OUT, fprintf(OUT,
"\n%*sACK reasons:\n", indent, " "); "\n%*sACK reasons:\n", indent, " ");
fprintf(OUT, "\t%*s%6d not acked immediately\n", indent, " ", fprintf(OUT, "\t%*s%6d not acked immediately\n", indent, " ",
s->ts_ackreason[_ACK_DONT_] ); s->ts_ackreason[_ACK_DONT_] );
fprintf(OUT, "\t%*s%6d strategy==each\n", indent, " ", fprintf(OUT, "\t%*s%6d strategy==each\n", indent, " ",
s->ts_ackreason[_ACK_STRAT_EACH_] ); s->ts_ackreason[_ACK_STRAT_EACH_] );
fprintf(OUT, "\t%*s%6d strategy==fullwindow\n", indent, " ", fprintf(OUT, "\t%*s%6d strategy==fullwindow\n", indent, " ",
s->ts_ackreason[_ACK_STRAT_FULLWIN_] ); s->ts_ackreason[_ACK_STRAT_FULLWIN_] );
fprintf(OUT, "\t%*s%6d duplicate DT\n", indent, " ", fprintf(OUT, "\t%*s%6d duplicate DT\n", indent, " ",
s->ts_ackreason[_ACK_DUP_] ); s->ts_ackreason[_ACK_DUP_] );
fprintf(OUT, "\t%*s%6d EOTSDU\n", indent, " ", fprintf(OUT, "\t%*s%6d EOTSDU\n", indent, " ",
s->ts_ackreason[_ACK_EOT_] ); s->ts_ackreason[_ACK_EOT_] );
fprintf(OUT, "\t%*s%6d reordered DT\n", indent, " ", fprintf(OUT, "\t%*s%6d reordered DT\n", indent, " ",
s->ts_ackreason[_ACK_REORDER_] ); s->ts_ackreason[_ACK_REORDER_] );
fprintf(OUT, "\t%*s%6d user rcvd\n", indent, " ", fprintf(OUT, "\t%*s%6d user rcvd\n", indent, " ",
s->ts_ackreason[_ACK_USRRCV_] ); s->ts_ackreason[_ACK_USRRCV_] );
fprintf(OUT, "\t%*s%6d fcc reqd\n", indent, " ", fprintf(OUT, "\t%*s%6d fcc reqd\n", indent, " ",
s->ts_ackreason[_ACK_FCC_] ); s->ts_ackreason[_ACK_FCC_] );
} }
#ifndef SSEL #ifndef SSEL
#define SSEL(s) ((s)->siso_tlen + TSEL(s)) #define SSEL(s) ((s)->siso_tlen + TSEL(s))
#define PSEL(s) ((s)->siso_slen + SSEL(s)) #define PSEL(s) ((s)->siso_slen + SSEL(s))
#endif #endif
static void
isonetprint(siso, islocal) isonetprint(siso, islocal)
register struct sockaddr_iso *siso; register struct sockaddr_iso *siso;
int islocal; int islocal;
{ {
hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}"); hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}");
if (siso->siso_tlen || siso->siso_slen || siso->siso_plen) if (siso->siso_tlen || siso->siso_slen || siso->siso_plen)
@ -789,10 +811,13 @@ int islocal;
hexprint(siso->siso_plen, PSEL(siso), "<>"); hexprint(siso->siso_plen, PSEL(siso), "<>");
putchar(' '); putchar(' ');
} }
static char hexlist[] = "0123456789abcdef", obuf[128]; static char hexlist[] = "0123456789abcdef", obuf[128];
static void
hexprint(n, buf, delim) hexprint(n, buf, delim)
char *buf, *delim; int n;
char *buf, *delim;
{ {
register u_char *in = (u_char *)buf, *top = in + n; register u_char *in = (u_char *)buf, *top = in + n;
register char *out = obuf; register char *out = obuf;

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 1983, 1988 Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -33,27 +33,34 @@
#ifndef lint #ifndef lint
char copyright[] = char copyright[] =
"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ "@(#) Copyright (c) 1983, 1988, 1993\n\
All rights reserved.\n"; Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)main.c 5.23 (Berkeley) 7/1/91";*/ /*static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";*/
static char rcsid[] = "$Id: main.c,v 1.5 1994/04/01 09:18:12 cgd Exp $"; static char *rcsid = "$Id: main.c,v 1.6 1994/05/13 08:08:14 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/socket.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <kvm.h>
#include <limits.h>
#include <netdb.h> #include <netdb.h>
#include <nlist.h> #include <nlist.h>
#include <kvm.h> #include <paths.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <paths.h> #include <unistd.h>
#include "netstat.h"
struct nlist nl[] = { struct nlist nl[] = {
#define N_MBSTAT 0 #define N_MBSTAT 0
@ -72,92 +79,67 @@ struct nlist nl[] = {
{ "_ifnet" }, { "_ifnet" },
#define N_IMP 7 #define N_IMP 7
{ "_imp_softc" }, { "_imp_softc" },
#define N_RTHOST 8 #define N_ICMPSTAT 8
{ "_rthost" },
#define N_RTNET 9
{ "_rtnet" },
#define N_ICMPSTAT 10
{ "_icmpstat" }, { "_icmpstat" },
#define N_RTSTAT 11 #define N_RTSTAT 9
{ "_rtstat" }, { "_rtstat" },
#define N_FILEHEAD 12 #define N_UNIXSW 10
{ "_filehead" },
#define N_FILES 13
{ "_nfiles" },
#define N_UNIXSW 14
{ "_unixsw" }, { "_unixsw" },
#define N_RTHASHSIZE 15 #define N_IDP 11
{ "_rthashsize" },
#define N_IDP 16
{ "_nspcb"}, { "_nspcb"},
#define N_IDPSTAT 17 #define N_IDPSTAT 12
{ "_idpstat"}, { "_idpstat"},
#define N_SPPSTAT 18 #define N_SPPSTAT 13
{ "_spp_istat"}, { "_spp_istat"},
#define N_NSERR 19 #define N_NSERR 14
{ "_ns_errstat"}, { "_ns_errstat"},
#define N_CLNPSTAT 20 #define N_CLNPSTAT 15
{ "_clnp_stat"}, { "_clnp_stat"},
#define IN_TP 21 #define IN_NOTUSED 16
{ "_tp_inpcb" }, { "_tp_inpcb" },
#define ISO_TP 22 #define ISO_TP 17
{ "_tp_isopcb" }, { "_tp_refinfo" },
#define N_TPSTAT 23 #define N_TPSTAT 18
{ "_tp_stat" }, { "_tp_stat" },
#define N_ESISSTAT 24 #define N_ESISSTAT 19
{ "_esis_stat"}, { "_esis_stat"},
#define N_NIMP 25 #define N_NIMP 20
{ "_nimp"}, { "_nimp"},
#define N_RTREE 26 #define N_RTREE 21
{ "_radix_node_head"}, { "_rt_tables"},
#define N_CLTP 27 #define N_CLTP 22
{ "_cltb"}, { "_cltb"},
#define N_CLTPSTAT 28 #define N_CLTPSTAT 23
{ "_cltpstat"}, { "_cltpstat"},
#define N_IGMPSTAT 29 #define N_NFILE 24
{ "_nfile" },
#define N_FILE 25
{ "_file" },
#define N_IGMPSTAT 26
{ "_igmpstat" }, { "_igmpstat" },
#define N_MRTPROTO 30 #define N_MRTPROTO 27
{ "_ip_mrtproto" }, { "_ip_mrtproto" },
#define N_MRTSTAT 31 #define N_MRTSTAT 28
{ "_mrtstat" }, { "_mrtstat" },
#define N_MRTTABLE 32 #define N_MRTTABLE 29
{ "_mrttable" }, { "_mrttable" },
#define N_VIFTABLE 33 #define N_VIFTABLE 30
{ "_viftable" }, { "_viftable" },
"", "",
}; };
/* internet protocols */
extern int protopr();
extern int tcp_stats(), udp_stats(), ip_stats(), icmp_stats();
extern int igmp_stats();
#ifdef NS
/* ns protocols */
extern int nsprotopr();
extern int spp_stats(), idp_stats(), nserr_stats();
#endif
#ifdef ISO
/* iso protocols */
extern int iso_protopr();
extern int tp_stats(), esis_stats(), clnp_stats(), cltp_stats();
#endif
struct protox { struct protox {
u_char pr_index; /* index into nlist of cb head */ u_char pr_index; /* index into nlist of cb head */
u_char pr_sindex; /* index into nlist of stat block */ u_char pr_sindex; /* index into nlist of stat block */
u_char pr_wanted; /* 1 if wanted, 0 otherwise */ u_char pr_wanted; /* 1 if wanted, 0 otherwise */
int (*pr_cblocks)(); /* control blocks printing routine */ void (*pr_cblocks)(); /* control blocks printing routine */
int (*pr_stats)(); /* statistics printing routine */ void (*pr_stats)(); /* statistics printing routine */
char *pr_name; /* well-known name */ char *pr_name; /* well-known name */
} protox[] = { } protox[] = {
{ N_TCB, N_TCPSTAT, 1, protopr, { N_TCB, N_TCPSTAT, 1, protopr,
tcp_stats, "tcp" }, tcp_stats, "tcp" },
{ N_UDB, N_UDPSTAT, 1, protopr, { N_UDB, N_UDPSTAT, 1, protopr,
udp_stats, "udp" }, udp_stats, "udp" },
#ifdef ISO
{ IN_TP, N_TPSTAT, 1, protopr,
tp_stats, "tpip" },
#endif
{ -1, N_IPSTAT, 1, 0, { -1, N_IPSTAT, 1, 0,
ip_stats, "ip" }, ip_stats, "ip" },
{ -1, N_ICMPSTAT, 1, 0, { -1, N_ICMPSTAT, 1, 0,
@ -168,7 +150,6 @@ struct protox {
0, 0 } 0, 0 }
}; };
#ifdef NS
struct protox nsprotox[] = { struct protox nsprotox[] = {
{ N_IDP, N_IDPSTAT, 1, nsprotopr, { N_IDP, N_IDPSTAT, 1, nsprotopr,
idp_stats, "idp" }, idp_stats, "idp" },
@ -179,9 +160,7 @@ struct protox nsprotox[] = {
{ -1, -1, 0, 0, { -1, -1, 0, 0,
0, 0 } 0, 0 }
}; };
#endif
#ifdef ISO
struct protox isoprotox[] = { struct protox isoprotox[] = {
{ ISO_TP, N_TPSTAT, 1, iso_protopr, { ISO_TP, N_TPSTAT, 1, iso_protopr,
tp_stats, "tp" }, tp_stats, "tp" },
@ -194,66 +173,44 @@ struct protox isoprotox[] = {
{ -1, -1, 0, 0, { -1, -1, 0, 0,
0, 0 } 0, 0 }
}; };
#endif
struct protox *protoprotox[] = { protox, struct protox *protoprotox[] = { protox, nsprotox, isoprotox, NULL };
#ifdef NS static void printproto __P((struct protox *, char *));
nsprotox, static void usage __P((void));
#endif static struct protox *name2protox __P((char *));
static struct protox *knownname __P((char *));
#ifdef ISO kvm_t *kvmd;
isoprotox,
#endif
NULL };
char *vmunix = _PATH_UNIX;
char *kmemf;
int kmem;
int kflag;
int Aflag;
int aflag;
int hflag;
int iflag;
int Mflag;
int mflag;
int nflag;
int pflag;
int rflag;
int sflag;
int tflag;
int dflag;
int interval;
char *interface;
int unit;
int af = AF_UNSPEC;
int
main(argc, argv) main(argc, argv)
int argc; int argc;
char **argv; char *argv[];
{ {
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
register struct protoent *p; register struct protoent *p;
register struct protox *tp; /* for printing cblocks & stats */ register struct protox *tp; /* for printing cblocks & stats */
struct protox *name2protox(); /* for -p */ register char *cp;
int ch; int ch;
void usage(); char *nlistf = NULL, *memf = NULL;
char buf[_POSIX2_LINE_MAX];
while ((ch = getopt(argc, argv, "Aac:df:hI:iMmN:np:rstuw:")) != EOF) if (cp = rindex(argv[0], '/'))
switch((char)ch) { prog = cp + 1;
else
prog = argv[0];
af = AF_UNSPEC;
while ((ch = getopt(argc, argv, "Aadf:ghI:iM:mN:np:rstuw:")) != EOF)
switch(ch) {
case 'A': case 'A':
Aflag = 1; Aflag = 1;
break; break;
case 'a': case 'a':
aflag = 1; aflag = 1;
break; break;
case 'c':
kmemf = optarg;
kflag = 1;
break;
case 'd': case 'd':
dflag = 1; dflag = 1;
break; break;
@ -268,18 +225,20 @@ main(argc, argv)
af = AF_ISO; af = AF_ISO;
else { else {
(void)fprintf(stderr, (void)fprintf(stderr,
"%s: unknown address family\n", optarg); "%s: %s: unknown address family\n",
prog, optarg);
exit(1); exit(1);
} }
break; break;
case 'h': case 'g':
hflag = 1; gflag = 1;
break; break;
case 'I': { case 'I': {
char *cp; char *cp;
iflag = 1; iflag = 1;
for (cp = interface = optarg; isalpha(*cp); cp++); for (cp = interface = optarg; isalpha(*cp); cp++)
continue;
unit = atoi(cp); unit = atoi(cp);
*cp = '\0'; *cp = '\0';
break; break;
@ -288,13 +247,13 @@ main(argc, argv)
iflag = 1; iflag = 1;
break; break;
case 'M': case 'M':
Mflag++; memf = optarg;
break; break;
case 'm': case 'm':
mflag = 1; mflag = 1;
break; break;
case 'N': case 'N':
vmunix = optarg; nlistf = optarg;
break; break;
case 'n': case 'n':
nflag = 1; nflag = 1;
@ -302,8 +261,8 @@ main(argc, argv)
case 'p': case 'p':
if ((tp = name2protox(optarg)) == NULL) { if ((tp = name2protox(optarg)) == NULL) {
(void)fprintf(stderr, (void)fprintf(stderr,
"%s: unknown or uninstrumented protocol\n", "%s: %s: unknown or uninstrumented protocol\n",
optarg); prog, optarg);
exit(1); exit(1);
} }
pflag = 1; pflag = 1;
@ -312,7 +271,7 @@ main(argc, argv)
rflag = 1; rflag = 1;
break; break;
case 's': case 's':
sflag = 1; ++sflag;
break; break;
case 't': case 't':
tflag = 1; tflag = 1;
@ -322,6 +281,7 @@ main(argc, argv)
break; break;
case 'w': case 'w':
interval = atoi(optarg); interval = atoi(optarg);
iflag = 1;
break; break;
case '?': case '?':
default: default:
@ -341,20 +301,29 @@ main(argc, argv)
iflag = 1; iflag = 1;
} }
if (*argv) { if (*argv) {
vmunix = *argv; nlistf = *argv;
if (*++argv) { if (*++argv)
kmemf = *argv; memf = *argv;
kflag = 1;
}
} }
} }
#endif #endif
if (kvm_openfiles(vmunix, kmemf, NULL) == -1) {
fprintf(stderr, "netstat: kvm_openfiles: %s\n", kvm_geterr()); /*
* 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)
setgid(getgid());
if ((kvmd = kvm_open(nlistf, memf, NULL, O_RDONLY, prog)) == NULL) {
fprintf(stderr, "%s: kvm_open: %s\n", prog, buf);
exit(1); exit(1);
} }
if (kvm_nlist(nl) < 0 || nl[0].n_type == 0) { if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) {
fprintf(stderr, "%s: no namelist\n", vmunix); if (nlistf)
fprintf(stderr, "%s: %s: no namelist\n", prog, nlistf);
else
fprintf(stderr, "%s: no namelist\n", prog);
exit(1); exit(1);
} }
if (mflag) { if (mflag) {
@ -369,14 +338,6 @@ main(argc, argv)
printf("%s: no stats routine\n", tp->pr_name); printf("%s: no stats routine\n", tp->pr_name);
exit(0); exit(0);
} }
if (hflag) {
#ifdef IMP
hostpr(nl[N_IMP].n_value, nl[N_NIMP].n_value);
#else
(void)fprintf(stderr, "netstat: IMP code not compiled in\n");
#endif
exit(0);
}
/* /*
* Keep file descriptors open to avoid overhead * Keep file descriptors open to avoid overhead
* of open/close on each call to get* routines. * of open/close on each call to get* routines.
@ -391,80 +352,85 @@ main(argc, argv)
if (sflag) if (sflag)
rt_stats(nl[N_RTSTAT].n_value); rt_stats(nl[N_RTSTAT].n_value);
else else
routepr(nl[N_RTHOST].n_value, routepr(nl[N_RTREE].n_value);
nl[N_RTNET].n_value,
nl[N_RTHASHSIZE].n_value,
nl[N_RTREE].n_value);
exit(0); exit(0);
} }
if (Mflag) { if (gflag) {
if (sflag) if (sflag)
mrt_stats(nl[N_MRTPROTO].n_value, mrt_stats(nl[N_MRTPROTO].n_value,
nl[N_MRTSTAT].n_value); nl[N_MRTSTAT].n_value);
else else
mroutepr(nl[N_MRTPROTO].n_value, mroutepr(nl[N_MRTPROTO].n_value,
nl[N_MRTTABLE].n_value, nl[N_MRTTABLE].n_value,
nl[N_VIFTABLE].n_value); nl[N_VIFTABLE].n_value);
exit(0); exit(0);
} }
if (af == AF_INET || af == AF_UNSPEC) {
setprotoent(1);
setservent(1);
/* ugh, this is O(MN) ... why do we do this? */
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;
printproto(tp, p->p_name);
}
endprotoent();
}
if (af == AF_NS || af == AF_UNSPEC)
for (tp = nsprotox; tp->pr_name; tp++)
printproto(tp, tp->pr_name);
if (af == AF_ISO || af == AF_UNSPEC)
for (tp = isoprotox; tp->pr_name; tp++)
printproto(tp, tp->pr_name);
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
unixpr(nl[N_UNIXSW].n_value);
exit(0);
}
if (af == AF_INET || af == AF_UNSPEC) { /*
setprotoent(1); * Print out protocol statistics or control blocks (per sflag).
setservent(1); * If the interface was not specifically requested, and the symbol
while (p = getprotoent()) { * is not in the namelist, ignore this one.
*/
static void
printproto(tp, name)
register struct protox *tp;
char *name;
{
void (*pr)();
u_long off;
for (tp = protox; tp->pr_name; tp++) if (sflag) {
if (strcmp(tp->pr_name, p->p_name) == 0) pr = tp->pr_stats;
break; off = nl[tp->pr_sindex].n_value;
if (tp->pr_name == 0 || tp->pr_wanted == 0) } else {
continue; pr = tp->pr_cblocks;
if (sflag) { off = nl[tp->pr_index].n_value;
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(); if (pr != NULL && (off || af != AF_UNSPEC))
} (*pr)(off, name);
if (af == AF_NS || af == AF_UNSPEC) { }
#ifdef NS
for (tp = nsprotox; tp->pr_name; tp++) { /*
if (sflag) { * Read kernel memory, return 0 on success.
if (tp->pr_stats) */
(*tp->pr_stats)(nl[tp->pr_sindex].n_value, int
tp->pr_name); kread(addr, buf, size)
} else u_long addr;
if (tp->pr_cblocks) char *buf;
(*tp->pr_cblocks)(nl[tp->pr_index].n_value, int size;
tp->pr_name); {
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,
kvm_geterr(kvmd));
return (-1);
} }
#endif return (0);
}
if (af == AF_ISO || af == AF_UNSPEC) {
#ifdef ISO
for (tp = isoprotox; 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
}
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
unixpr(nl[N_FILEHEAD].n_value, nl[N_FILES].n_value,
(struct protosw *)nl[N_UNIXSW].n_value);
if (af == AF_UNSPEC && sflag)
#ifdef IMP
impstats(nl[N_IMP].n_value, nl[N_NIMP].n_value);
#endif
exit(0);
} }
char * char *
@ -474,26 +440,33 @@ plural(n)
return (n != 1 ? "s" : ""); return (n != 1 ? "s" : "");
} }
char *
plurales(n)
int n;
{
return (n != 1 ? "es" : "");
}
/* /*
* Find the protox for the given "well-known" name. * Find the protox for the given "well-known" name.
*/ */
struct protox * static struct protox *
knownname(name) knownname(name)
char *name; char *name;
{ {
struct protox **tpp, *tp; struct protox **tpp, *tp;
for (tpp = protoprotox; *tpp; tpp++) for (tpp = protoprotox; *tpp; tpp++)
for (tp = *tpp; tp->pr_name; tp++) for (tp = *tpp; tp->pr_name; tp++)
if (strcmp(tp->pr_name, name) == 0) if (strcmp(tp->pr_name, name) == 0)
return(tp); return (tp);
return(NULL); return (NULL);
} }
/* /*
* Find the protox corresponding to name. * Find the protox corresponding to name.
*/ */
struct protox * static struct protox *
name2protox(name) name2protox(name)
char *name; char *name;
{ {
@ -506,7 +479,7 @@ name2protox(name)
* fails, check if name is an alias for an Internet protocol. * fails, check if name is an alias for an Internet protocol.
*/ */
if (tp = knownname(name)) if (tp = knownname(name))
return(tp); return (tp);
setprotoent(1); /* make protocol lookup cheaper */ setprotoent(1); /* make protocol lookup cheaper */
while (p = getprotoent()) { while (p = getprotoent()) {
@ -514,23 +487,23 @@ name2protox(name)
for (alias = p->p_aliases; *alias; alias++) for (alias = p->p_aliases; *alias; alias++)
if (strcmp(name, *alias) == 0) { if (strcmp(name, *alias) == 0) {
endprotoent(); endprotoent();
return(knownname(p->p_name)); return (knownname(p->p_name));
} }
} }
endprotoent(); endprotoent();
return(NULL); return (NULL);
} }
void static void
usage() usage()
{ {
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: netstat [-Aan] [-f address_family] [-c core] [-N system]\n"); "usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", prog);
(void)fprintf(stderr, (void)fprintf(stderr,
" [-himnrs] [-f address_family] [-c core] [-N system]\n"); " %s [-ghimnrs] [-f address_family] [-M core] [-N system]\n", prog);
(void)fprintf(stderr, (void)fprintf(stderr,
" [-n] [-I interface] [-c core] [-N system] [-w wait]\n"); " %s [-n] [-I interface] [-M core] [-N system] [-w wait]\n", prog);
(void)fprintf(stderr, (void)fprintf(stderr,
" [-c core] [-N system] [-p protocol]\n"); " %s [-M core] [-N system] [-p protocol]\n", prog);
exit(1); exit(1);
} }

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 1983, 1988 Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,15 +32,18 @@
*/ */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)mbuf.c 5.10 (Berkeley) 1/30/91";*/ /*static char sccsid[] = "from: @(#)mbuf.c 8.1 (Berkeley) 6/6/93";*/
static char rcsid[] = "$Id: mbuf.c,v 1.4 1994/04/01 09:18:13 cgd Exp $"; static char *rcsid = "$Id: mbuf.c,v 1.5 1994/05/13 08:08:16 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
#include <stdio.h>
#include <nlist.h>
#include <kvm.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <stdio.h>
#include "netstat.h"
#define YES 1 #define YES 1
typedef int bool; typedef int bool;
@ -63,7 +66,7 @@ static struct mbtypes {
{ MT_SONAME, "socket names and addresses" }, { MT_SONAME, "socket names and addresses" },
{ MT_SOOPTS, "socket options" }, { MT_SOOPTS, "socket options" },
{ MT_RIGHTS, "access rights" }, { MT_RIGHTS, "access rights" },
{ MT_IFADDR, "interface addresses" }, /* XXX */ { MT_IFADDR, "interface addresses" }, /* XXX */
{ 0, 0 } { 0, 0 }
}; };
@ -73,6 +76,7 @@ bool seen[256]; /* "have we seen this type yet?" */
/* /*
* Print mbuf statistics. * Print mbuf statistics.
*/ */
void
mbpr(mbaddr) mbpr(mbaddr)
u_long mbaddr; u_long mbaddr;
{ {
@ -81,18 +85,16 @@ mbpr(mbaddr)
register struct mbtypes *mp; register struct mbtypes *mp;
if (nmbtypes != 256) { if (nmbtypes != 256) {
fprintf(stderr, "unexpected change to mbstat; check source\n"); fprintf(stderr,
"%s: unexpected change to mbstat; check source\n", prog);
return; return;
} }
if (mbaddr == 0) { if (mbaddr == 0) {
printf("mbstat: symbol not in namelist\n"); fprintf(stderr, "%s: mbstat: symbol not in namelist\n", prog);
return; return;
} }
if (kvm_read((void *)(long)mbaddr, (char *)&mbstat, sizeof (mbstat)) if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat)))
!= sizeof (mbstat)) {
printf("mbstat: bad read\n");
return; return;
}
totmbufs = 0; totmbufs = 0;
for (mp = mbtypes; mp->mt_name; mp++) for (mp = mbtypes; mp->mt_name; mp++)
totmbufs += mbstat.m_mtypes[mp->mt_type]; totmbufs += mbstat.m_mtypes[mp->mt_type];

View File

@ -1,76 +1,96 @@
/*
* Copyright (c) 1989 Stephen Deering
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Stephen Deering of Stanford University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)mroute.c 8.1 (Berkeley) 6/6/93
* $Id: mroute.c,v 1.4 1994/05/13 08:08:17 mycroft Exp $
*/
/* /*
* Print DVMRP multicast routing structures and statistics. * Print DVMRP multicast routing structures and statistics.
* *
* MROUTING 1.0 * MROUTING 1.0
*/ */
#ifndef lint
static char rcsid[] = "$Id: mroute.c,v 1.3 1994/04/01 09:18:14 cgd Exp $";
#endif /* not lint */
#include <stdio.h>
#include <nlist.h>
#include <kvm.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/mbuf.h> #include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/igmp.h> #include <netinet/igmp.h>
#define KERNEL 1 #define KERNEL 1
struct socket; /* shut up warning */
struct ip;
#include <netinet/ip_mroute.h> #include <netinet/ip_mroute.h>
#undef KERNEL #undef KERNEL
extern int kmem; #include <stdio.h>
extern int nflag; #include <stdlib.h>
extern char *routename(); #include "netstat.h"
extern char *netname();
extern char *plural();
char *plurales(n)
int n;
{
return (n == 1? "" : "es");
}
void
mroutepr(mrpaddr, mrtaddr, vifaddr) mroutepr(mrpaddr, mrtaddr, vifaddr)
u_long mrpaddr, mrtaddr, vifaddr; u_long mrpaddr, mrtaddr, vifaddr;
{ {
u_int mrtproto; u_int mrtproto;
#if BSD >= 199006
struct mrt *mrttable[MRTHASHSIZ]; struct mrt *mrttable[MRTHASHSIZ];
struct mrt *mp;
struct mrt mb;
struct mrt *mrt = &mb;
#else
struct mbuf *mrttable[MRTHASHSIZ];
struct mbuf *mp;
struct mbuf mb;
struct mrt *mrt = mtod(&mb, struct mrt *);
#endif
struct vif viftable[MAXVIFS]; struct vif viftable[MAXVIFS];
register struct mrt *mrt;
struct mrt smrt;
register struct vif *v; register struct vif *v;
register vifi_t vifi; register vifi_t vifi;
struct in_addr *grp; register struct in_addr *grp;
int i, n; register int i, n;
int banner_printed; register int banner_printed;
int saved_nflag; register int saved_nflag;
if(mrpaddr == 0) { if (mrpaddr == 0) {
printf("ip_mrtproto: symbol not in namelist\n"); printf("ip_mrtproto: symbol not in namelist\n");
return; return;
} }
kvm_read((void *)(long)mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
switch (mrtproto) { switch (mrtproto) {
case 0:
case 0:
printf("no multicast routing compiled into this system\n"); printf("no multicast routing compiled into this system\n");
return; return;
case IGMP_DVMRP: case IGMP_DVMRP:
break; break;
default: default:
printf("multicast routing protocol %u, unknown\n", mrtproto); printf("multicast routing protocol %u, unknown\n", mrtproto);
return; return;
} }
@ -87,86 +107,73 @@ mroutepr(mrpaddr, mrtaddr, vifaddr)
saved_nflag = nflag; saved_nflag = nflag;
nflag = 1; nflag = 1;
kvm_read((void *)(long)vifaddr, (char *)viftable, sizeof(viftable)); kread(vifaddr, (char *)&viftable, sizeof(viftable));
banner_printed = 0; banner_printed = 0;
for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
struct in_addr v_lcl_grps[1024]; if (v->v_lcl_addr.s_addr == 0)
continue;
if (v->v_lcl_addr.s_addr == 0) continue;
if (!banner_printed) { if (!banner_printed) {
printf("\nVirtual Interface Table\n%s%s", printf("\nVirtual Interface Table\n%s%s",
" Vif Threshold Local-Address ", " Vif Threshold Local-Address ",
"Remote-Address Groups\n"); "Remote-Address Groups\n");
banner_printed = 1; banner_printed = 1;
} }
printf(" %2u %3u %-15.15s", printf(" %2u %3u %-15.15s",
vifi, v->v_threshold, routename(v->v_lcl_addr)); vifi, v->v_threshold, routename(v->v_lcl_addr.s_addr));
printf(" %-15.15s\n", printf(" %-15.15s\n", (v->v_flags & VIFF_TUNNEL) ?
(v->v_flags & VIFF_TUNNEL) ? routename(v->v_rmt_addr.s_addr) : "");
routename(v->v_rmt_addr) : "");
n = v->v_lcl_grps_n; n = v->v_lcl_grps_n;
if (n == 0) grp = (struct in_addr *)malloc(n * sizeof(*grp));
continue; if (grp == NULL) {
if (n < 0 || n > 1024) printf("v_lcl_grps_n: malloc failed\n");
printf("[v_lcl_grps_n = %d!]\n", n); return;
}
kvm_read(v->v_lcl_grps, (char *)v_lcl_grps, kread((u_long)v->v_lcl_grps, (caddr_t)grp, n * sizeof(*grp));
n * sizeof(struct in_addr));
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
printf("%51s %-15.15s\n", "", printf("%51s %-15.15s\n",
routename(v_lcl_grps[i])); "", routename((grp++)->s_addr));
free(grp);
} }
if (!banner_printed) printf("\nVirtual Interface Table is empty\n"); if (!banner_printed)
printf("\nVirtual Interface Table is empty\n");
kvm_read((void *)(long)mrtaddr, (char *)mrttable, sizeof(mrttable)); kread(mrtaddr, (char *)&mrttable, sizeof(mrttable));
banner_printed = 0; banner_printed = 0;
for (i = 0; i < MRTHASHSIZ; ++i) { for (i = 0; i < MRTHASHSIZ; ++i) {
for (mp = mrttable[i]; mp != NULL; for (mrt = mrttable[i]; mrt != NULL; mrt = mrt->mrt_next) {
#if BSD >= 199006 if (!banner_printed) {
mp = mb.mrt_next printf("\nMulticast Routing Table\n%s",
#else " Hash Origin-Subnet In-Vif Out-Vifs\n");
mp = mb.m_next banner_printed = 1;
#endif
) {
if (!banner_printed) {
printf("\nMulticast Routing Table\n%s",
" Hash Origin-Subnet In-Vif Out-Vifs\n");
banner_printed = 1;
}
kvm_read(mp, (char *)&mb, sizeof(mb));
printf(" %3u %-15.15s %2u ",
i,
netname(mrt->mrt_origin.s_addr,
ntohl(mrt->mrt_originmask.s_addr)),
mrt->mrt_parent);
for (vifi = 0; vifi < MAXVIFS; ++vifi) {
if (viftable[vifi].v_lcl_addr.s_addr) {
if (VIFM_ISSET(vifi, mrt->mrt_children)) {
printf(" %u%c",
vifi,
VIFM_ISSET(vifi,
mrt->mrt_leaves) ?
'*' : ' ');
} else
printf(" ");
} }
kread((u_long)mrt, (char *)&smrt, sizeof(*mrt));
mrt = &smrt;
printf(" %3u %-15.15s %2u ",
i, netname(mrt->mrt_origin.s_addr,
ntohl(mrt->mrt_originmask.s_addr)),
mrt->mrt_parent);
for (vifi = 0; vifi < MAXVIFS; ++vifi)
if (VIFM_ISSET(vifi, mrt->mrt_children))
printf(" %u%c",
vifi,
VIFM_ISSET(vifi, mrt->mrt_leaves) ?
'*' : ' ');
printf("\n");
} }
printf("\n");
}
} }
if (!banner_printed) printf("\nMulticast Routing Table is empty\n"); if (!banner_printed)
printf("\nMulticast Routing Table is empty\n");
printf("\n"); printf("\n");
nflag = saved_nflag; nflag = saved_nflag;
} }
void
mrt_stats(mrpaddr, mstaddr) mrt_stats(mrpaddr, mstaddr)
u_long mrpaddr, mstaddr; u_long mrpaddr, mstaddr;
{ {
@ -178,7 +185,7 @@ mrt_stats(mrpaddr, mstaddr)
return; return;
} }
kvm_read((void *)(long)mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
switch (mrtproto) { switch (mrtproto) {
case 0: case 0:
printf("no multicast routing compiled into this system\n"); printf("no multicast routing compiled into this system\n");
@ -197,7 +204,7 @@ mrt_stats(mrpaddr, mstaddr)
return; return;
} }
kvm_read((void *)(long)mstaddr, (char *)&mrtstat, sizeof(mrtstat)); kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
printf("multicast routing:\n"); printf("multicast routing:\n");
printf(" %10u multicast route lookup%s\n", printf(" %10u multicast route lookup%s\n",
mrtstat.mrts_mrt_lookups, plural(mrtstat.mrts_mrt_lookups)); mrtstat.mrts_mrt_lookups, plural(mrtstat.mrts_mrt_lookups));
@ -213,6 +220,4 @@ mrt_stats(mrpaddr, mstaddr)
mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
printf(" %10u datagram%s with no room for tunnel options\n", printf(" %10u datagram%s with no room for tunnel options\n",
mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel)); mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
printf(" %10u datagram%s arrived on wrong interface\n",
mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
} }

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1983, 1990 The Regents of the University of California. .\" Copyright (c) 1983, 1990, 1992, 1993
.\" All rights reserved. .\" The Regents of the University of California. All rights reserved.
.\" .\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions .\" modification, are permitted provided that the following conditions
@ -29,10 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" from: @(#)netstat.1 6.14 (Berkeley) 7/27/91 .\" from: @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\" $Id: netstat.1,v 1.5 1994/04/01 08:27:29 cgd Exp $ .\" $Id: netstat.1,v 1.6 1994/05/13 08:08:18 mycroft Exp $
.\" .\"
.Dd July 27, 1991 .Dd April 18, 1994
.Dt NETSTAT 1 .Dt NETSTAT 1
.Os BSD 4.2 .Os BSD 4.2
.Sh NAME .Sh NAME
@ -42,22 +42,22 @@
.Nm netstat .Nm netstat
.Op Fl Aan .Op Fl Aan
.Op Fl f Ar address_family .Op Fl f Ar address_family
.Op Ar system .Op Fl M Ar core
.Op Ar core
.Nm netstat
.Op Fl himnrs
.Op Fl f Ar address_family
.Op Fl c Ar core
.Op Fl N Ar system .Op Fl N Ar system
.Nm netstat .Nm netstat
.Op Fl n .Op Fl dghimnrs
.Op Fl I Op Ar interface .Op Fl f Ar address_family
.Op Fl c Ar core .Op Fl M Ar core
.Op Fl N Ar system
.Nm netstat
.Op Fl dn
.Op Fl I Ar interface
.Op Fl M Ar core
.Op Fl N Ar system .Op Fl N Ar system
.Op Fl w Ar wait .Op Fl w Ar wait
.Nm netstat .Nm netstat
.Op Fl p Ar protocol .Op Fl p Ar protocol
.Op Fl c Ar core .Op Fl M Ar core
.Op Fl N Ar system .Op Fl N Ar system
.Sh DESCRIPTION .Sh DESCRIPTION
The The
@ -93,31 +93,60 @@ With either interface display (option
.Fl i .Fl i
or an interval, as described below), or an interval, as described below),
show the number of dropped packets. show the number of dropped packets.
.It Fl f Ar address_family
Limit statistics or address control block reports to those
of the specified
.Ar address family .
The following address families
are recognized:
.Ar inet ,
for
.Dv AF_INET ,
.Ar ns ,
for
.Dv AF_NS ,
.Ar iso ,
for
.Dv AF_ISO ,
and
.Ar unix ,
for
.Dv AF_UNIX .
.It Fl g
Show information related to multicast (group address) routing.
By default, show the IP Multicast virtual-interface and routing tables.
If the
.Fl s
option is also present, show multicast routing statistics.
.It Fl h .It Fl h
Show the state of the Show the state of the
.Tn IMP .Tn IMP
host table. host table (obsolete).
.It Fl I Ar interface
Show information about the specified interface;
used with a
.Ar wait
interval as described below.
.It Fl i .It Fl i
Show the state of interfaces which have been auto-configured Show the state of interfaces which have been auto-configured
(interfaces statically configured into a system, but not (interfaces statically configured into a system, but not
located at boot time are not shown). located at boot time are not shown).
.It Fl I Ar interface If the
Show information only about this interface; .Fl a
used with an options is also present, multicast addresses currently in use are shown
.Ar wait for each Ethernet interface and for each IP interface address.
interval as described below. Multicast addresses are shown on separate lines following the interface
.It Fl c address with which they are associated.
.It Fl M
Extract values associated with the name list from the specified core Extract values associated with the name list from the specified core
instead of the default instead of the default
.Pa /dev/kmem . .Pa /dev/kmem .
.It Fl m .It Fl m
Show statistics recorded by the memory management routines Show statistics recorded by the memory management routines
(the network manages a private pool of memory buffers). (the network manages a private pool of memory buffers).
.It Fl M
Show multicast routing statistics.
.It Fl N .It Fl N
Extract the name list from the specified system instead of the default Extract the name list from the specified system instead of the default
.Pa /netbsd .Pa /vmunix .
.It Fl n .It Fl n
Show network addresses as numbers (normally Show network addresses as numbers (normally
.Nm netstat .Nm netstat
@ -137,27 +166,16 @@ The program will complain if
is unknown or if there is no statistics routine for it. is unknown or if there is no statistics routine for it.
.It Fl s .It Fl s
Show per-protocol statistics. Show per-protocol statistics.
If this option is repeated, counters with a value of zero are suppressed.
.It Fl r .It Fl r
Show the routing tables. Show the routing tables.
When When
.Fl s .Fl s
is also present, show routing statistics instead. is also present, show routing statistics instead.
.It Fl f Ar address_family .It Fl w Ar wait
Limit statistics or address control block reports to those Show network interface statistics at intervals of
of the specified .Ar wait
.Ar address family . seconds.
The following address families
are recognized:
.Ar inet ,
for
.Dv AF_INET ,
.Ar ns ,
for
.Dv AF_NS ,
and
.Ar unix ,
for
.Dv AF_UNIX .
.El .El
.Pp .Pp
The default display, for active sockets, shows the local The default display, for active sockets, shows the local
@ -190,10 +208,31 @@ and the maximum transmission unit (``mtu'') are also displayed.
The routing table display indicates the available routes and The routing table display indicates the available routes and
their status. Each route consists of a destination host or network their status. Each route consists of a destination host or network
and a gateway to use in forwarding packets. The flags field shows and a gateway to use in forwarding packets. The flags field shows
the state of the route (``U'' if ``up''), whether the route a collection of information about the route stored as
is to a gateway (``G''), whether the route was created dynamically binary choices. The individual flags are discussed in more
by a redirect (``D''), and whether the route has been modified detail in the
by a redirect (``M''). Direct routes are created for each .Xr route 8
and
.Xr route 4
manual pages.
The mapping between letters and flags is:
.Bl -column XXXX RTF_BLACKHOLE
1 RTF_PROTO2 Protocol specific routing flag #1
2 RTF_PROTO1 Protocol specific routing flag #2
B RTF_BLACKHOLE Just discard pkts (during updates)
C RTF_CLONING Generate new routes on use
D RTF_DYNAMIC Created dynamically (by redirect)
G RTF_GATEWAY Destination requires forwarding by intermediary
H RTF_HOST Host entry (net otherwise)
L RTF_LLINFO Valid protocol to link address translation.
M RTF_MODIFIED Modified dynamically (by redirect)
R RTF_REJECT Host or net unreachable
S RTF_STATIC Manually added
U RTF_UP Route usable
X RTF_XRESOLVE External daemon translates proto to link address
.El
.Pp
Direct routes are created for each
interface attached to the local host; interface attached to the local host;
the gateway field for such entries shows the address of the outgoing interface. the gateway field for such entries shows the address of the outgoing interface.
The refcnt field gives the The refcnt field gives the
@ -207,10 +246,14 @@ interface utilized for the route.
.Pp .Pp
When When
.Nm netstat .Nm netstat
is invoked with a is invoked with the
.Fl w
option and a
.Ar wait .Ar wait
interval argument, it displays a running count of statistics related to interval argument, it displays a running count of statistics related to
network interfaces. network interfaces.
An obsolescent version of this option used a numeric parameter
with no option, and is currently supported for backward compatibility.
This display consists of a column for the primary interface (the first This display consists of a column for the primary interface (the first
interface found during autoconfiguration) and a column summarizing interface found during autoconfiguration) and a column summarizing
information for all interfaces. information for all interfaces.
@ -238,13 +281,10 @@ command appeared in
.Bx 4.2 . .Bx 4.2 .
.\" .Sh FILES .\" .Sh FILES
.\" .Bl -tag -width /dev/kmem -compact .\" .Bl -tag -width /dev/kmem -compact
.\" .It Pa /netbsd .\" .It Pa /vmunix
.\" default kernel namelist .\" default kernel namelist
.\" .It Pa /dev/kmem .\" .It Pa /dev/kmem
.\" default memory file .\" default memory file
.\" .El .\" .El
.Sh BUGS .Sh BUGS
The notion of errors is ill-defined. The notion of errors is ill-defined.
.Pp
Collisions mean something else for the
.Tn IMP .

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* from: @(#)netstat.h 8.2 (Berkeley) 1/4/94 * from: @(#)netstat.h 8.2 (Berkeley) 1/4/94
* $Id: netstat.h,v 1.1 1994/05/13 08:06:36 mycroft Exp $ * $Id: netstat.h,v 1.2 1994/05/13 08:08:20 mycroft Exp $
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 1985, 1988 Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,8 +32,8 @@
*/ */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)ns.c 5.13 (Berkeley) 3/1/91";*/ /*static char sccsid[] = "from: @(#)ns.c 8.1 (Berkeley) 6/6/93";*/
static char rcsid[] = "$Id: ns.c,v 1.6 1994/04/01 09:18:15 cgd Exp $"; static char *rcsid = "$Id: ns.c,v 1.7 1994/05/13 08:08:21 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -60,19 +60,17 @@ static char rcsid[] = "$Id: ns.c,v 1.6 1994/04/01 09:18:15 cgd Exp $";
#include <netns/spp_debug.h> #include <netns/spp_debug.h>
#include <nlist.h> #include <nlist.h>
#include <kvm.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "netstat.h"
struct nspcb nspcb; struct nspcb nspcb;
struct sppcb sppcb; struct sppcb sppcb;
struct socket sockb; struct socket sockb;
extern int Aflag;
extern int aflag; static char *ns_prpr __P((struct ns_addr *));
extern int nflag; static void ns_erputil __P((int, int));
extern char *plural();
char *ns_prpr();
static int first = 1; static int first = 1;
@ -83,6 +81,7 @@ static int first = 1;
* -a (all) flag is specified. * -a (all) flag is specified.
*/ */
void
nsprotopr(off, name) nsprotopr(off, name)
u_long off; u_long off;
char *name; char *name;
@ -94,16 +93,16 @@ nsprotopr(off, name)
if (off == 0) if (off == 0)
return; return;
isspp = strcmp(name, "spp") == 0; isspp = strcmp(name, "spp") == 0;
kvm_read((void *)(long)off, (char *)&cb, sizeof (struct nspcb)); kread(off, (char *)&cb, sizeof (struct nspcb));
nspcb = cb; nspcb = cb;
prev = (struct nspcb *)(long)off; prev = (struct nspcb *)off;
if (nspcb.nsp_next == (struct nspcb *)(long)off) if (nspcb.nsp_next == (struct nspcb *)off)
return; return;
for (;nspcb.nsp_next != (struct nspcb *)(long)off; prev = next) { for (;nspcb.nsp_next != (struct nspcb *)off; prev = next) {
u_long ppcb; u_long ppcb;
next = nspcb.nsp_next; next = nspcb.nsp_next;
kvm_read(next, (char *)&nspcb, sizeof (nspcb)); kread((u_long)next, (char *)&nspcb, sizeof (nspcb));
if (nspcb.nsp_prev != prev) { if (nspcb.nsp_prev != prev) {
printf("???\n"); printf("???\n");
break; break;
@ -111,13 +110,12 @@ nsprotopr(off, name)
if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) { if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) {
continue; continue;
} }
kvm_read(nspcb.nsp_socket, kread((u_long)nspcb.nsp_socket,
(char *)&sockb, sizeof (sockb)); (char *)&sockb, sizeof (sockb));
ppcb = (long)nspcb.nsp_pcb; ppcb = (u_long) nspcb.nsp_pcb;
if (ppcb) { if (ppcb) {
if (isspp) { if (isspp) {
kvm_read((void *)(long)ppcb, (char *)&sppcb, kread(ppcb, (char *)&sppcb, sizeof (sppcb));
sizeof (sppcb));
} else continue; } else continue;
} else } else
if (isspp) continue; if (isspp) continue;
@ -158,6 +156,7 @@ nsprotopr(off, name)
/* /*
* Dump SPP statistics structure. * Dump SPP statistics structure.
*/ */
void
spp_stats(off, name) spp_stats(off, name)
u_long off; u_long off;
char *name; char *name;
@ -167,7 +166,7 @@ spp_stats(off, name)
if (off == 0) if (off == 0)
return; return;
kvm_read((void *)(long)off, (char *)&spp_istat, sizeof (spp_istat)); kread(off, (char *)&spp_istat, sizeof (spp_istat));
printf("%s:\n", name); printf("%s:\n", name);
ANY(spp_istat.nonucn, "connection", " dropped due to no new sockets "); 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.gonawy, "connection", " terminated due to our end dying");
@ -235,6 +234,7 @@ spp_stats(off, name)
/* /*
* Dump IDP statistics structure. * Dump IDP statistics structure.
*/ */
void
idp_stats(off, name) idp_stats(off, name)
u_long off; u_long off;
char *name; char *name;
@ -243,7 +243,7 @@ idp_stats(off, name)
if (off == 0) if (off == 0)
return; return;
kvm_read((void *)(long)off, (char *)&idpstat, sizeof (idpstat)); kread(off, (char *)&idpstat, sizeof (idpstat));
printf("%s:\n", name); printf("%s:\n", name);
ANY(idpstat.idps_toosmall, "packet", " smaller than a header"); ANY(idpstat.idps_toosmall, "packet", " smaller than a header");
ANY(idpstat.idps_tooshort, "packet", " smaller than advertised"); ANY(idpstat.idps_tooshort, "packet", " smaller than advertised");
@ -270,6 +270,7 @@ static struct {
* Dump NS Error statistics structure. * Dump NS Error statistics structure.
*/ */
/*ARGSUSED*/ /*ARGSUSED*/
void
nserr_stats(off, name) nserr_stats(off, name)
u_long off; u_long off;
char *name; char *name;
@ -281,7 +282,7 @@ nserr_stats(off, name)
if (off == 0) if (off == 0)
return; return;
kvm_read((void *)(long)off, (char *)&ns_errstat, sizeof (ns_errstat)); kread(off, (char *)&ns_errstat, sizeof (ns_errstat));
printf("NS error statistics:\n"); printf("NS error statistics:\n");
ANY(ns_errstat.ns_es_error, "call", " to ns_error"); ANY(ns_errstat.ns_es_error, "call", " to ns_error");
ANY(ns_errstat.ns_es_oldshort, "error", ANY(ns_errstat.ns_es_oldshort, "error",
@ -312,7 +313,9 @@ nserr_stats(off, name)
} }
} }
static void
ns_erputil(z, c) ns_erputil(z, c)
int z, c;
{ {
int j; int j;
char codebuf[30]; char codebuf[30];
@ -331,19 +334,19 @@ ns_erputil(z, c)
where = "at destination"; where = "at destination";
sprintf(codebuf, "Unknown XNS error code 0%o", c); sprintf(codebuf, "Unknown XNS error code 0%o", c);
name = codebuf; name = codebuf;
} else } else
where = ns_errnames[j].where; where = ns_errnames[j].where;
ANY(z, name, where); ANY(z, name, where);
} }
static struct sockaddr_ns ssns = {AF_NS}; static struct sockaddr_ns ssns = {AF_NS};
static
char *ns_prpr(x) char *ns_prpr(x)
struct ns_addr *x; struct ns_addr *x;
{ {
struct sockaddr_ns *sns = &ssns; struct sockaddr_ns *sns = &ssns;
extern char *ns_print();
sns->sns_addr = *x; sns->sns_addr = *x;
return(ns_print(sns)); return(ns_print((struct sockaddr *)sns));
} }

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 1983, 1988 Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,47 +32,35 @@
*/ */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)route.c 5.20 (Berkeley) 11/29/90";*/ /*static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";*/
static char rcsid[] = "$Id: route.c,v 1.9 1994/04/01 09:18:16 cgd Exp $"; static char *rcsid = "$Id: route.c,v 1.10 1994/05/13 08:08:22 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
#include <sys/protosw.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <net/if.h> #include <net/if.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#define KERNEL #define KERNEL
#include <net/route.h> #include <net/route.h>
#undef KERNEL #undef KERNEL
#include <netinet/in.h> #include <netinet/in.h>
#ifdef NS
#include <netns/ns.h> #include <netns/ns.h>
#endif
#ifdef ISO #include <sys/sysctl.h>
#include <netiso/iso.h>
#include <net/if_dl.h>
#include <netiso/iso_snpac.h>
#endif
#include <netdb.h> #include <netdb.h>
#include <sys/kinfo.h>
#include <stdio.h> #include <stdio.h>
#include <nlist.h> #include <stdlib.h>
#include <kvm.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "netstat.h"
extern int nflag, aflag, Aflag, af; #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
int do_rtent;
extern char *routename(), *netname(), *plural();
#ifdef NS
extern char *ns_print();
#endif
extern char *malloc();
#define kget(p, d) \
(kvm_read((p), (char *)&(d), sizeof (d)))
/* /*
* Definitions for showing gateway flags. * Definitions for showing gateway flags.
@ -84,180 +72,146 @@ struct bits {
{ RTF_UP, 'U' }, { RTF_UP, 'U' },
{ RTF_GATEWAY, 'G' }, { RTF_GATEWAY, 'G' },
{ RTF_HOST, 'H' }, { RTF_HOST, 'H' },
{ RTF_REJECT, 'R' },
{ RTF_DYNAMIC, 'D' }, { RTF_DYNAMIC, 'D' },
{ RTF_MODIFIED, 'M' }, { RTF_MODIFIED, 'M' },
{ RTF_DONE, 'd' }, /* Completed -- for routing messages only */
{ RTF_MASK, 'm' }, /* Mask Present -- for routing messages only */
{ RTF_CLONING, 'C' }, { RTF_CLONING, 'C' },
{ RTF_XRESOLVE, 'X' }, { RTF_XRESOLVE, 'X' },
{ RTF_LLINFO, 'L' }, { RTF_LLINFO, 'L' },
{ RTF_REJECT, 'R' }, { RTF_STATIC, 'S' },
{ RTF_PROTO1, '1' },
{ RTF_PROTO2, '2' },
{ 0 } { 0 }
}; };
#ifdef ISO
struct bits2 {
short b_mask;
char b_val;
} bits2[] = {
{ SNPA_ES, 'E' },
{ SNPA_IS, 'I' },
{ SNPA_PERM, 'P' },
{ 0 }
};
#endif
/*
* Print routing tables.
*/
routepr(hostaddr, netaddr, hashsizeaddr, treeaddr)
u_long hostaddr, netaddr, hashsizeaddr, treeaddr;
{
struct mbuf mb;
register struct ortentry *rt;
register struct mbuf *m;
char name[16], *flags;
struct mbuf **routehash;
int hashsize;
int i, doinghost = 1;
printf("Routing tables\n");
if (treeaddr)
return treestuff(treeaddr);
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;
}
kget((void *)(long)hashsizeaddr, hashsize);
routehash = (struct mbuf **)malloc( hashsize*sizeof (struct mbuf *) );
kvm_read((void *)(long)hostaddr, (char *)routehash,
hashsize*sizeof (struct mbuf *));
again:
for (i = 0; i < hashsize; i++) {
if (routehash[i] == 0)
continue;
m = routehash[i];
while (m) {
kget(m, mb);
if (Aflag)
printf("%8.8x ", m);
p_ortentry((struct ortentry *)(mb.m_dat));
m = mb.m_next;
}
}
if (doinghost) {
kvm_read((void *)(long)netaddr, (char *)routehash,
hashsize*sizeof (struct mbuf *));
doinghost = 0;
goto again;
}
free((char *)routehash);
return;
}
char *
af_name(af)
{
static char buf[10];
switch(af) {
case AF_INET:
return "inet";
case AF_UNIX:
return "unix";
case AF_NS:
return "ns";
case AF_ISO:
return "iso";
default:
sprintf(buf, "%d", af);
}
return buf;
}
void
p_heading(af)
{
if (Aflag)
printf("%-8.8s ","Address");
switch(af) {
case AF_INET:
printf("%-16.16s %-18.18s %-6.6s %6.6s %8.8s %s\n",
"Destination", "Gateway",
"Flags", "Refs", "Use", "Interface");
break;
case AF_ISO:
if (nflag) {
printf("%-50.50s %-17.17s %-5.5s %s\n",
"Destination", "Media addr", "Flags", "Intf");
} else {
printf("%-12.12s %-19.19s %-17.17s %-6.6s %6s %8s %s\n",
"NSAP-prefix", "Area/Id", "Media addr",
"Flags", "Refs", "Use", "Intf");
}
break;
default:
printf("%-16.16s %-18.18s %-6.6s %6.6s%8.8s %s\n",
"Destination", "Gateway",
"Flags", "Refs", "Use", "Interface");
}
}
static union { static union {
struct sockaddr u_sa; struct sockaddr u_sa;
u_short u_data[128]; u_short u_data[128];
} pt_u; } pt_u;
int do_rtent = 0;
struct rtentry rtentry;
struct radix_node rnode;
struct radix_mask rmask;
int NewTree = 0; int do_rtent = 0;
treestuff(rtree) struct rtentry rtentry;
u_long rtree; struct radix_node rnode;
struct radix_mask rmask;
int NewTree = 0;
static struct sockaddr *kgetsa __P((struct sockaddr *));
static void p_tree __P((struct radix_node *));
static void p_rtnode __P(());
static void ntreestuff __P(());
static void np_rtentry __P((struct rt_msghdr *));
static void p_sockaddr __P((struct sockaddr *, int, int));
static void p_flags __P((int, char *));
static void p_rtentry __P((struct rtentry *));
/*
* Print routing tables.
*/
void
routepr(rtree)
u_long rtree;
{ {
struct radix_node_head *rnh, head; struct radix_node_head *rnh, head;
int i;
printf("Routing tables\n");
if (Aflag == 0 && NewTree) if (Aflag == 0 && NewTree)
return(ntreestuff()); ntreestuff();
for (kget((void *)(long)rtree, rnh); rnh; rnh = head.rnh_next) { else {
kget(rnh, head); if (rtree == 0) {
if (head.rnh_af == 0) { printf("rt_tables: symbol not in namelist\n");
if (Aflag || af == AF_UNSPEC) { return;
printf("Netmasks:\n"); }
kget(rtree, rt_tables);
for (i = 0; i <= AF_MAX; i++) {
if ((rnh = rt_tables[i]) == 0)
continue;
kget(rnh, head);
if (i == AF_UNSPEC) {
if (Aflag && af == 0) {
printf("Netmasks:\n");
p_tree(head.rnh_treetop);
}
} else if (af == AF_UNSPEC || af == i) {
pr_family(i);
do_rtent = 1;
pr_rthdr();
p_tree(head.rnh_treetop); p_tree(head.rnh_treetop);
} }
} else if (af == AF_UNSPEC || af == head.rnh_af) {
printf("\nRoute Tree for Protocol Family %s:\n",
af_name(head.rnh_af));
p_heading(head.rnh_af);
do_rtent = 1;
p_tree(head.rnh_treetop);
} }
} }
} }
struct sockaddr * /*
kgetsa(dst) * Print address family header before a section of the routing table.
register struct sockaddr *dst; */
void
pr_family(af)
int af;
{ {
kget(dst, pt_u.u_sa); char *afname;
if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa)) {
kvm_read(dst, pt_u.u_data, pt_u.u_sa.sa_len); switch (af) {
case AF_INET:
afname = "Internet";
break;
case AF_NS:
afname = "XNS";
break;
case AF_ISO:
afname = "ISO";
break;
case AF_CCITT:
afname = "X.25";
break;
default:
afname = NULL;
break;
} }
if (afname)
printf("\n%s:\n", afname);
else
printf("\nProtocol Family %d:\n", af);
}
/* column widths; each followed by one space */
#define WID_DST 16 /* width of destination column */
#define WID_GW 18 /* width of gateway column */
/*
* Print header for routing table columns.
*/
void
pr_rthdr()
{
if (Aflag)
printf("%-8.8s ","Address");
printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %s\n",
WID_DST, WID_DST, "Destination",
WID_GW, WID_GW, "Gateway",
"Flags", "Refs", "Use", "Interface");
}
static struct sockaddr *
kgetsa(dst)
register struct sockaddr *dst;
{
kget(dst, pt_u.u_sa);
if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
kread((u_long)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len);
return (&pt_u.u_sa); return (&pt_u.u_sa);
} }
static void
p_tree(rn) p_tree(rn)
struct radix_node *rn; struct radix_node *rn;
{ {
again: again:
@ -265,17 +219,18 @@ again:
if (rnode.rn_b < 0) { if (rnode.rn_b < 0) {
if (Aflag) if (Aflag)
printf("%-8.8x ", rn); printf("%-8.8x ", rn);
if (rnode.rn_flags & RNF_ROOT) if (rnode.rn_flags & RNF_ROOT) {
printf("(root node)%s", if (Aflag)
printf("(root node)%s",
rnode.rn_dupedkey ? " =>\n" : "\n"); rnode.rn_dupedkey ? " =>\n" : "\n");
else if (do_rtent) { } else if (do_rtent) {
kget(rn, rtentry); kget(rn, rtentry);
p_rtentry(&rtentry); p_rtentry(&rtentry);
if (Aflag) if (Aflag)
p_rtnode(); p_rtnode();
} else { } else {
p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key), p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key),
0, 44); 0, 44);
putchar('\n'); putchar('\n');
} }
if (rn = rnode.rn_dupedkey) if (rn = rnode.rn_dupedkey)
@ -290,12 +245,14 @@ again:
p_tree(rn); p_tree(rn);
} }
} }
char nbuf[20];
char nbuf[20];
static void
p_rtnode() p_rtnode()
{ {
struct radix_mask *rm = rnode.rn_mklist; struct radix_mask *rm = rnode.rn_mklist;
if (rnode.rn_b < 0) { if (rnode.rn_b < 0) {
if (rnode.rn_mask) { if (rnode.rn_mask) {
printf("\t mask "); printf("\t mask ");
@ -320,18 +277,26 @@ p_rtnode()
putchar('\n'); putchar('\n');
} }
static void
ntreestuff() ntreestuff()
{ {
int needed; size_t needed;
int mib[6];
char *buf, *next, *lim; char *buf, *next, *lim;
register struct rt_msghdr *rtm; register struct rt_msghdr *rtm;
if ((needed = getkerninfo(KINFO_RT_DUMP, 0, 0, 0)) < 0) mib[0] = CTL_NET;
{ perror("route-getkerninfo-estimate"); exit(1);} mib[1] = PF_ROUTE;
mib[2] = 0;
mib[3] = 0;
mib[4] = NET_RT_DUMP;
mib[5] = 0;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
{ perror("route-sysctl-estimate"); exit(1);}
if ((buf = malloc(needed)) == 0) if ((buf = malloc(needed)) == 0)
{ printf("out of space\n"); exit(1);} { printf("out of space\n"); exit(1);}
if (getkerninfo(KINFO_RT_DUMP, buf, &needed, 0) < 0) if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
{ perror("actual retrieval of routing table"); exit(1);} { perror("sysctl of routing table"); exit(1);}
lim = buf + needed; lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen) { for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next; rtm = (struct rt_msghdr *)next;
@ -339,11 +304,15 @@ ntreestuff()
} }
} }
static void
np_rtentry(rtm) np_rtentry(rtm)
register struct rt_msghdr *rtm; register struct rt_msghdr *rtm;
{ {
register struct sockaddr *sa = (struct sockaddr *)(rtm + 1); register struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
static int masks_done, old_af, banner_printed; #ifdef notdef
static int masks_done, banner_printed;
#endif
static int old_af;
int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST; int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST;
#ifdef notdef #ifdef notdef
@ -361,7 +330,7 @@ register struct rt_msghdr *rtm;
#endif #endif
af = sa->sa_family; af = sa->sa_family;
if (af != old_af) { if (af != old_af) {
printf("\nRoute Tree for Protocol Family %d:\n", af); pr_family(af);
old_af = af; old_af = af;
} }
if (rtm->rtm_addrs == RTA_DST) if (rtm->rtm_addrs == RTA_DST)
@ -377,16 +346,13 @@ register struct rt_msghdr *rtm;
putchar('\n'); putchar('\n');
} }
#ifdef ISO static void
extern char* dl_print();
#endif
p_sockaddr(sa, flags, width) p_sockaddr(sa, flags, width)
struct sockaddr *sa; struct sockaddr *sa;
int flags, width; int flags, width;
{ {
char format[20], workbuf[128], *cp, *cplim; char workbuf[128], *cplim;
register char *cpout; register char *cp = workbuf;
switch(sa->sa_family) { switch(sa->sa_family) {
case AF_INET: case AF_INET:
@ -395,37 +361,55 @@ int flags, width;
cp = (sin->sin_addr.s_addr == 0) ? "default" : cp = (sin->sin_addr.s_addr == 0) ? "default" :
((flags & RTF_HOST) ? ((flags & RTF_HOST) ?
routename(sin->sin_addr) : netname(sin->sin_addr, 0L)); routename(sin->sin_addr.s_addr) :
netname(sin->sin_addr.s_addr, 0L));
break;
} }
break;
#ifdef NS
case AF_NS: case AF_NS:
cp = ns_print((struct sockaddr_ns *)sa); cp = ns_print(sa);
break;
#endif
#ifdef ISO
case AF_ISO:
cp = iso_ntoa(&((struct sockaddr_iso *)sa)->siso_addr);
break; break;
case AF_LINK: case AF_LINK:
cp = dl_print((struct sockaddr_dl *)sa); {
register struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
sdl->sdl_slen == 0)
(void) sprintf(workbuf, "link#%d", sdl->sdl_index);
else switch (sdl->sdl_type) {
case IFT_ETHER:
{
register int i;
register u_char *lla = (u_char *)sdl->sdl_data +
sdl->sdl_nlen;
cplim = "";
for (i = 0; i < sdl->sdl_alen; i++, lla++) {
cp += sprintf(cp, "%s%x", cplim, *lla);
cplim = ":";
}
cp = workbuf;
break;
}
default:
cp = link_ntoa(sdl);
break;
}
break; break;
#endif }
default: default:
{ {
register u_char *s = ((u_char *)sa->sa_data), *slim; register u_char *s = (u_char *)sa->sa_data, *slim;
slim = (u_char *) sa + sa->sa_len; slim = sa->sa_len + (u_char *) sa;
cp = workbuf;
cplim = cp + sizeof(workbuf) - 6; cplim = cp + sizeof(workbuf) - 6;
cp += sprintf(cp, "(%d)", sa->sa_family); cp += sprintf(cp, "(%d)", sa->sa_family);
while (s < slim && cp < cplim) { while (s < slim && cp < cplim) {
cp += sprintf(cp, " %02x", *s++); cp += sprintf(cp, " %02x", *s++);
if (s < slim) if (s < slim)
cp += sprintf(cp, "%02x", *s++); cp += sprintf(cp, "%02x", *s++);
} }
cp = workbuf; cp = workbuf;
} }
@ -440,185 +424,53 @@ int flags, width;
} }
} }
static void
p_flags(f, format) p_flags(f, format)
register int f;
char *format;
{
char name[33], *flags;
register struct bits *p = bits;
for (flags = name; p->b_mask; p++)
if (p->b_mask & f)
*flags++ = p->b_val;
*flags = '\0';
printf(format, name);
}
#ifdef ISO
p_iso_flags(f, lli, format)
register int f; register int f;
char *format; char *format;
caddr_t lli;
{ {
struct llinfo_llc ls;
char name[33], *flags; char name[33], *flags;
register struct bits *p = bits; register struct bits *p = bits;
register struct bits2 *p2 = bits2;
for (flags = name; p->b_mask; p++) for (flags = name; p->b_mask; p++)
if (p->b_mask & f) if (p->b_mask & f)
*flags++ = p->b_val; *flags++ = p->b_val;
if (lli) {
kget(lli, ls);
for (; p2->b_mask; p2++)
if (p2->b_mask & ls.lc_flags)
*flags++ = p2->b_val;
}
*flags = '\0'; *flags = '\0';
printf(format, name); printf(format, name);
} }
static char *hexlist = "0123456789abcdef"; static void
char *
iso_areatoa(isoa)
const struct iso_addr *isoa;
{
static char obuf[16];
register char *out = obuf;
register int i;
/* Assumption: ISO address always with 2 byte area, 1 byte NSEL */
/* and 6 bytes ID */
register u_char *in = (u_char*)isoa->isoa_genaddr + isoa->isoa_len - 9;
u_char *inlim = in + 2;
if (isoa->isoa_len < 10) return "";
while (in < inlim) {
i = *in++;
out[1] = hexlist[i & 0xf];
i >>= 4;
out[0] = hexlist[i];
out += 2;
}
*out = 0;
return(obuf);
}
char *
iso_idtoa(isoa)
const struct iso_addr *isoa;
{
static char obuf[16];
register char *out = obuf;
register int i;
/* Assumption: ISO address always with 1 byte NSEL and 6 bytes ID */
register u_char *in = (u_char*)isoa->isoa_genaddr + isoa->isoa_len - 7;
u_char *inlim = in + 6;
if (isoa->isoa_len < 10) return "";
out[1] = 0;
while (in < inlim) {
i = *in++;
if ((inlim - in) % 2 || out == obuf)
*out++ = '.';
out[1] = hexlist[i & 0xf];
i >>= 4;
out[0] = hexlist[i];
out += 2;
}
*out = 0;
return(obuf + 1);
}
p_iso_route(rt, sa)
struct rtentry *rt;
struct sockaddr *sa;
{
struct sockaddr_iso *siso = (struct sockaddr_iso *)sa;
if (nflag) {
p_sockaddr(sa, rt->rt_flags, 50);
p_sockaddr(kgetsa(rt->rt_gateway), 0, 17);
p_iso_flags(rt->rt_flags, rt->rt_llinfo, "%-6.6s");
p_interface_nl(rt);
} else {
p_sockaddr(sa, rt->rt_flags, 12);
printf("%4.4s/%14.14s ",
iso_areatoa(&siso->siso_addr),
iso_idtoa(&siso->siso_addr));
p_sockaddr(kgetsa(rt->rt_gateway), 0, 17);
p_iso_flags(rt->rt_flags, rt->rt_llinfo, "%-6.6s ");
printf("%6d %8d", rt->rt_refcnt, rt->rt_use);
p_interface_nl(rt);
}
}
#endif /* ISO */
p_interface_nl(rt)
struct rtentry *rt;
{
struct ifnet ifnet;
char name[16];
if (rt->rt_ifp == 0) {
putchar('\n');
return;
}
kget(rt->rt_ifp, ifnet);
kvm_read(ifnet.if_name, name, 16);
printf(" %.15s%d%s", name, ifnet.if_unit,
rt->rt_nodes[0].rn_dupedkey ? " =>\n" : "\n");
}
p_rtentry(rt) p_rtentry(rt)
register struct rtentry *rt; register struct rtentry *rt;
{ {
struct sockaddr *sa; static struct ifnet ifnet, *lastif;
static char name[16];
sa = kgetsa(rt_key(rt)); p_sockaddr(kgetsa(rt_key(rt)), rt->rt_flags, WID_DST);
if (sa->sa_family == AF_ISO) { p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, WID_GW);
p_iso_route(rt, sa);
return;
}
p_sockaddr(sa, rt->rt_flags, 16);
p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, 18);
p_flags(rt->rt_flags, "%-6.6s "); p_flags(rt->rt_flags, "%-6.6s ");
printf("%6d %8d ", rt->rt_refcnt, rt->rt_use); printf("%6d %8d ", rt->rt_refcnt, rt->rt_use);
p_interface_nl(rt); if (rt->rt_ifp) {
} if (rt->rt_ifp != lastif) {
kget(rt->rt_ifp, ifnet);
p_ortentry(rt) kread((u_long)ifnet.if_name, name, 16);
register struct ortentry *rt; lastif = rt->rt_ifp;
{ }
char name[16], *flags; printf(" %.15s%d%s", name, ifnet.if_unit,
register struct bits *p; rt->rt_nodes[0].rn_dupedkey ? " =>" : "");
register struct sockaddr_in *sin;
struct ifnet ifnet;
p_sockaddr(&rt->rt_dst, rt->rt_flags, 16);
p_sockaddr(&rt->rt_gateway, 0, 18);
p_flags(rt->rt_flags, "%-6.6s ");
printf("%6d %8d ", rt->rt_refcnt, rt->rt_use);
if (rt->rt_ifp == 0) {
putchar('\n');
return;
} }
kget(rt->rt_ifp, ifnet); putchar('\n');
kvm_read(ifnet.if_name, name, 16);
printf(" %.15s%d\n", name, ifnet.if_unit);
} }
char * char *
routename(in) routename(in)
struct in_addr in; u_long in;
{ {
register char *cp; register char *cp;
static char line[MAXHOSTNAMELEN + 1]; static char line[MAXHOSTNAMELEN + 1];
struct hostent *hp; struct hostent *hp;
static char domain[MAXHOSTNAMELEN + 1]; static char domain[MAXHOSTNAMELEN + 1];
static int first = 1; static int first = 1;
char *index();
if (first) { if (first) {
first = 0; first = 0;
@ -643,9 +495,9 @@ routename(in)
strncpy(line, cp, sizeof(line) - 1); strncpy(line, cp, sizeof(line) - 1);
else { else {
#define C(x) ((x) & 0xff) #define C(x) ((x) & 0xff)
in.s_addr = ntohl(in.s_addr); in = ntohl(in);
sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24), sprintf(line, "%u.%u.%u.%u",
C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); C(in >> 24), C(in >> 16), C(in >> 8), C(in));
} }
return (line); return (line);
} }
@ -656,17 +508,16 @@ routename(in)
*/ */
char * char *
netname(in, mask) netname(in, mask)
struct in_addr in; u_long in, mask;
u_long mask;
{ {
char *cp = 0; char *cp = 0;
static char line[MAXHOSTNAMELEN + 1]; static char line[MAXHOSTNAMELEN + 1];
struct netent *np = 0; struct netent *np = 0;
u_long net; u_long net;
register i; register int i;
int subnetshift; int subnetshift;
i = ntohl(in.s_addr); i = ntohl(in);
if (!nflag && i) { if (!nflag && i) {
if (mask == 0) { if (mask == 0) {
if (IN_CLASSA(i)) { if (IN_CLASSA(i)) {
@ -694,7 +545,7 @@ netname(in, mask)
np = getnetbyaddr(net, AF_INET); np = getnetbyaddr(net, AF_INET);
if (np) if (np)
cp = np->n_name; cp = np->n_name;
} }
if (cp) if (cp)
strncpy(line, cp, sizeof(line) - 1); strncpy(line, cp, sizeof(line) - 1);
else if ((i & 0xffffff) == 0) else if ((i & 0xffffff) == 0)
@ -712,6 +563,7 @@ netname(in, mask)
/* /*
* Print routing statistics * Print routing statistics
*/ */
void
rt_stats(off) rt_stats(off)
u_long off; u_long off;
{ {
@ -721,7 +573,7 @@ rt_stats(off)
printf("rtstat: symbol not in namelist\n"); printf("rtstat: symbol not in namelist\n");
return; return;
} }
kvm_read((void *)(long)off, (char *)&rtstat, sizeof (rtstat)); kread(off, (char *)&rtstat, sizeof (rtstat));
printf("routing:\n"); printf("routing:\n");
printf("\t%u bad routing redirect%s\n", printf("\t%u bad routing redirect%s\n",
rtstat.rts_badredirect, plural(rtstat.rts_badredirect)); rtstat.rts_badredirect, plural(rtstat.rts_badredirect));
@ -734,14 +586,14 @@ rt_stats(off)
printf("\t%u use%s of a wildcard route\n", printf("\t%u use%s of a wildcard route\n",
rtstat.rts_wildcard, plural(rtstat.rts_wildcard)); rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
} }
#ifdef NS
short ns_nullh[] = {0,0,0}; short ns_nullh[] = {0,0,0};
short ns_bh[] = {-1,-1,-1}; short ns_bh[] = {-1,-1,-1};
char * char *
ns_print(sns) ns_print(sa)
struct sockaddr_ns *sns; register struct sockaddr *sa;
{ {
register struct sockaddr_ns *sns = (struct sockaddr_ns*)sa;
struct ns_addr work; struct ns_addr work;
union { union ns_net net_e; u_long long_e; } net; union { union ns_net net_e; u_long long_e; } net;
u_short port; u_short port;
@ -770,7 +622,8 @@ struct sockaddr_ns *sns;
q = work.x_host.c_host; q = work.x_host.c_host;
sprintf(chost, "%02x%02x%02x%02x%02x%02xH", sprintf(chost, "%02x%02x%02x%02x%02x%02xH",
q[0], q[1], q[2], q[3], q[4], q[5]); q[0], q[1], q[2], q[3], q[4], q[5]);
for (p = chost; *p == '0' && p < chost + 12; p++); for (p = chost; *p == '0' && p < chost + 12; p++)
continue;
host = p; host = p;
} }
if (port) if (port)
@ -784,23 +637,26 @@ struct sockaddr_ns *sns;
} }
char * char *
ns_phost(sns) ns_phost(sa)
struct sockaddr_ns *sns; struct sockaddr *sa;
{ {
register struct sockaddr_ns *sns = (struct sockaddr_ns *)sa;
struct sockaddr_ns work; struct sockaddr_ns work;
static union ns_net ns_zeronet; static union ns_net ns_zeronet;
char *p; char *p;
work = *sns; work = *sns;
work.sns_addr.x_port = 0; work.sns_addr.x_port = 0;
work.sns_addr.x_net = ns_zeronet; work.sns_addr.x_net = ns_zeronet;
p = ns_print(&work); p = ns_print((struct sockaddr *)&work);
if (strncmp("0H.", p, 3) == 0) p += 3; if (strncmp("0H.", p, 3) == 0) p += 3;
return(p); return(p);
} }
void
upHex(p0) upHex(p0)
char *p0; char *p0;
{ {
register char *p = p0; register char *p = p0;
for (; *p; p++) switch (*p) { for (; *p; p++) switch (*p) {
@ -809,26 +665,3 @@ char *p0;
*p += ('A' - 'a'); *p += ('A' - 'a');
} }
} }
#endif /* NS */
#ifdef ISO
char *
dl_print(sdl)
struct sockaddr_dl *sdl;
{
static char buf[20];
char *cp = buf, *dp;
int i;
dp = sdl->sdl_data;
for (i = 0; i < sdl->sdl_nlen; i++)
*cp++ = *dp++;
if (sdl->sdl_nlen != 0 && sdl->sdl_alen != 0)
*cp++ = ':';
for (; i < sdl->sdl_nlen + sdl->sdl_alen; i++)
cp += sprintf(cp, "%x%c", *dp++ & 0xff,
i + 1 == sdl->sdl_nlen + sdl->sdl_alen ? ' ' : '.');
*cp = 0;
return buf;
}
#endif /* ISO */

View File

@ -1,6 +1,6 @@
/*- /*-
* Copyright (c) 1983, 1988 Regents of the University of California. * Copyright (c) 1983, 1988, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,91 +32,71 @@
*/ */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)unix.c 5.11 (Berkeley) 7/1/91";*/ /*static char sccsid[] = "from: @(#)unix.c 8.1 (Berkeley) 6/6/93";*/
static char rcsid[] = "$Id: unix.c,v 1.9 1994/04/01 09:18:17 cgd Exp $"; static char *rcsid = "$Id: unix.c,v 1.10 1994/05/13 08:08:23 mycroft Exp $";
#endif /* not lint */ #endif /* not lint */
/* /*
* Display protocol blocks in the unix domain. * Display protocol blocks in the unix domain.
*/ */
#include <kvm.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/protosw.h> #include <sys/protosw.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/socketvar.h> #include <sys/socketvar.h>
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <sys/sysctl.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/unpcb.h> #include <sys/unpcb.h>
#include <sys/time.h>
#include <sys/proc.h>
#define KERNEL #define KERNEL
struct uio; struct uio;
#include <sys/time.h> struct proc;
#include <sys/proc.h>
#include <sys/file.h> #include <sys/file.h>
#include <nlist.h>
#include <kvm.h>
struct file *file, *fileNFILE;
int nfiles;
int Aflag; #include <netinet/in.h>
extern char *calloc();
unixpr(fileheadaddr, nfilesaddr, unixsw) #include <stdio.h>
u_long fileheadaddr, nfilesaddr; #include <stdlib.h>
struct protosw *unixsw; #include "netstat.h"
static void unixdomainpr __P((struct socket *, caddr_t));
static struct file *file, *fileNFILE;
static int nfiles;
extern kvm_t *kvmd;
void
unixpr(off)
u_long off;
{ {
register struct file *fp, *lfp; register struct file *fp;
struct file *filep;
struct socket sock, *so = &sock; struct socket sock, *so = &sock;
int i; char *filebuf;
struct protosw *unixsw = (struct protosw *)off;
if (fileheadaddr == 0 || nfilesaddr == 0) { filebuf = (char *)kvm_getfiles(kvmd, KERN_FILE, 0, &nfiles);
printf("filehead or nfiles not in namelist.\n"); if (filebuf == 0) {
return;
}
if (kvm_read((void *)(long)nfilesaddr, (char *)&nfiles,
sizeof (nfiles)) != sizeof (nfiles)) {
printf("nfiles: bad read.\n");
return;
}
if (kvm_read((void *)(long)fileheadaddr, (char *)&filep, sizeof (filep))
!= sizeof (filep)) {
printf("File table address, bad read.\n");
return;
}
file = (struct file *)calloc(nfiles, sizeof (struct file));
if (file == (struct file *)0) {
printf("Out of memory (file table).\n"); printf("Out of memory (file table).\n");
return; return;
} }
for (lfp = file, i = nfiles; file = (struct file *)(filebuf + sizeof(fp));
filep != NULL && i-- > 0;
filep = lfp->f_filef, lfp++)
{
if(kvm_read(filep, (char *)lfp, sizeof (struct file))
!= sizeof(struct file)) {
printf("File table read error.\n");
return;
}
}
fileNFILE = file + nfiles; fileNFILE = file + nfiles;
for (fp = file; fp < fileNFILE; fp++) { for (fp = file; fp < fileNFILE; fp++) {
if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET) if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
continue; continue;
if (kvm_read(fp->f_data, (char *)so, sizeof (*so)) if (kread((u_long)fp->f_data, (char *)so, sizeof (*so)))
!= sizeof (*so))
continue; continue;
/* kludge */ /* kludge */
if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2) if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
if (so->so_pcb) if (so->so_pcb)
unixdomainpr(so, fp->f_data); unixdomainpr(so, fp->f_data);
} }
free((char *)file);
} }
static char *socktype[] = static char *socktype[] =
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
static void
unixdomainpr(so, soaddr) unixdomainpr(so, soaddr)
register struct socket *so; register struct socket *so;
caddr_t soaddr; caddr_t soaddr;
@ -126,13 +106,11 @@ unixdomainpr(so, soaddr)
struct sockaddr_un *sa; struct sockaddr_un *sa;
static int first = 1; static int first = 1;
if (kvm_read(so->so_pcb, (char *)unp, sizeof (*unp)) if (kread((u_long)so->so_pcb, (char *)unp, sizeof (*unp)))
!= sizeof (*unp))
return; return;
if (unp->unp_addr) { if (unp->unp_addr) {
m = &mbuf; m = &mbuf;
if (kvm_read(unp->unp_addr, (char *)m, sizeof (*m)) if (kread((u_long)unp->unp_addr, (char *)m, sizeof (*m)))
!= sizeof (*m))
m = (struct mbuf *)0; m = (struct mbuf *)0;
sa = (struct sockaddr_un *)(m->m_dat); sa = (struct sockaddr_un *)(m->m_dat);
} else } else
@ -150,7 +128,8 @@ unixdomainpr(so, soaddr)
unp->unp_vnode, unp->unp_conn, unp->unp_vnode, unp->unp_conn,
unp->unp_refs, unp->unp_nextref); unp->unp_refs, unp->unp_nextref);
if (m) if (m)
printf(" %.*s", sa->sun_len - sizeof (sa->sun_len) - printf(" %.*s",
sizeof (sa->sun_family), sa->sun_path); m->m_len - (int)(sizeof(*sa) - sizeof(sa->sun_path)),
sa->sun_path);
putchar('\n'); putchar('\n');
} }