1 /*
2 * Copyright (c) 1983, 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #ifndef lint
35 static char sccsid[] = "@(#)host.c 5.12 (Berkeley) 2/2/91";
36 #endif /* not lint */
37
38 #include <sys/param.h>
39 #include <sys/mbuf.h>
40 #include <sys/socket.h>
41
42 #include <net/if.h>
43
44 #include <netinet/in.h>
45 #include <netimp/if_imp.h>
46 #include <netimp/if_imphost.h>
47
48 extern int kmem;
49 extern int nflag;
50 extern char *inetname();
51
52 /*
53 * Print the host tables associated with the ARPANET IMP.
54 * Symbolic addresses are shown unless the nflag is given.
55 */
hostpr(impsoftcaddr,nimpaddr)56 hostpr(impsoftcaddr, nimpaddr)
57 off_t impsoftcaddr, nimpaddr;
58 {
59 struct mbuf *hosts, mb;
60 struct imp_softc imp_softc;
61 register struct mbuf *m;
62 register struct hmbuf *mh;
63 register struct host *hp;
64 char flagbuf[10], *flags;
65 int i, nimp;
66
67 if (impsoftcaddr == 0) {
68 printf("imp_softc: symbol not in namelist\n");
69 return;
70 }
71 if (nimpaddr == 0) {
72 printf("nimp: symbol not in namelist\n");
73 return;
74 }
75 kvm_read(nimpaddr, (char *)&nimp, sizeof (nimp));
76 for (i = 0; i < nimp; i++) {
77 kvm_read(impsoftcaddr, (char *)&imp_softc, sizeof (imp_softc));
78 impsoftcaddr += sizeof (imp_softc);
79 m = imp_softc.imp_hosts;
80 printf("IMP%d Host Table\n", i);
81 printf("%-5.5s %-6.6s %-8.8s %-4.4s %-9.9s %-4.4s %s\n", "Flags",
82 "Host", "Imp", "Qcnt", "Q Address", "RFNM", "Timer");
83 while (m) {
84 kvm_read((off_t)m, (char *)&mb, sizeof (mb));
85 m = &mb;
86 mh = (struct hmbuf *)(m->m_dat);
87 if (mh->hm_count == 0) {
88 m = m->m_next;
89 continue;
90 }
91 for (hp = mh->hm_hosts; hp < mh->hm_hosts + HPMBUF; hp++) {
92 if ((hp->h_flags&HF_INUSE) == 0 && hp->h_timer == 0)
93 continue;
94 flags = flagbuf;
95 *flags++ = hp->h_flags&HF_INUSE ? 'A' : 'F';
96 if (hp->h_flags&HF_DEAD)
97 *flags++ = 'D';
98 if (hp->h_flags&HF_UNREACH)
99 *flags++ = 'U';
100 *flags = '\0';
101 printf("%-5.5s %-6d %-8d %-4d %-9x %-4d %d\n",
102 flagbuf,
103 hp->h_host,
104 ntohs(hp->h_imp),
105 hp->h_qcnt,
106 hp->h_q,
107 hp->h_rfnm,
108 hp->h_timer);
109 }
110 m = m->m_next;
111 }
112 }
113 }
114
impstats(impsoftcaddr,nimpaddr)115 impstats(impsoftcaddr, nimpaddr)
116 off_t impsoftcaddr, nimpaddr;
117 {
118 struct imp_softc imp_softc;
119 int i, nimp;
120 extern char *plural();
121
122 if (impsoftcaddr == 0 || nimpaddr == 0)
123 return;
124 kvm_read(nimpaddr, (char *)&nimp, sizeof (nimp));
125 for (i = 0; i < nimp; i++) {
126 kvm_read(impsoftcaddr, (char *)&imp_softc, sizeof (imp_softc));
127 impsoftcaddr += sizeof(imp_softc);
128 printf("imp%d statistics:\n", i);
129 #define p(f, m) printf(m, imp_softc.f, plural(imp_softc.f))
130 p(imp_if.if_ipackets, "\t%u input message%s\n");
131 p(imp_if.if_opackets, "\t%u output message%s\n");
132 printf("\t%u times output blocked at least %d sec.\n",
133 imp_softc.imp_block, IMP_OTIMER);
134 p(imp_incomplete, "\t%u \"incomplete\" message%s\n");
135 p(imp_lostrfnm, "\t%u lost RFNM message%s\n");
136 p(imp_badrfnm, "\t%u late/bogus RFNM/incomplete message%s\n");
137 p(imp_garbage, "\t%u unknown message type%s\n");
138 }
139 }
140