forced commit to test new log_accum.pl script
[dragonfly.git] / usr.bin / netstat / ipx.c
blobb5ee622e263c1afd31a7c7efd0756bd36f32e293
1 /*
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
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.
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.
33 * @(#)ns.c 8.1 (Berkeley) 6/6/93
34 * $FreeBSD: src/usr.bin/netstat/ipx.c,v 1.13.2.1 2001/08/10 09:07:09 ru Exp $
35 * $DragonFly: src/usr.bin/netstat/ipx.c,v 1.3 2005/08/04 17:31:23 drhodus Exp $
38 #include <sys/param.h>
39 #include <sys/queue.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
42 #include <sys/protosw.h>
44 #include <net/route.h>
46 #include <netinet/tcp_fsm.h>
48 #include <netipx/ipx.h>
49 #include <netipx/ipx_pcb.h>
50 #include <netipx/ipx_var.h>
51 #ifdef IPXERRORMSGS
52 #include <netipx/ipx_error.h>
53 #endif
54 #include <netipx/spx.h>
55 #include <netipx/spx_timer.h>
56 #include <netipx/spx_var.h>
57 #define SANAMES
58 #include <netipx/spx_debug.h>
60 #include <nlist.h>
61 #include <errno.h>
62 #include <stdio.h>
63 #include <string.h>
64 #include "netstat.h"
66 struct ipxpcb ipxpcb;
67 struct spxpcb spxpcb;
68 struct socket sockb;
70 static char *ipx_prpr (struct ipx_addr *);
72 static int first = 1;
75 * Print a summary of connections related to a Network Systems
76 * protocol. For SPX, also give state of connection.
77 * Listening processes (aflag) are suppressed unless the
78 * -a (all) flag is specified.
81 void
82 ipxprotopr(u_long off, char *name, int af __unused)
84 struct ipxpcb cb;
85 struct ipxpcb *prev, *next;
86 int isspx;
88 if (off == 0)
89 return;
90 isspx = strcmp(name, "spx") == 0;
91 kread(off, (char *)&cb, sizeof (struct ipxpcb));
92 ipxpcb = cb;
93 prev = (struct ipxpcb *)off;
94 if (ipxpcb.ipxp_next == (struct ipxpcb *)off)
95 return;
96 for (;ipxpcb.ipxp_next != (struct ipxpcb *)off; prev = next) {
97 u_long ppcb;
99 next = ipxpcb.ipxp_next;
100 kread((u_long)next, (char *)&ipxpcb, sizeof (ipxpcb));
101 if (ipxpcb.ipxp_prev != prev) {
102 printf("???\n");
103 break;
105 if (!aflag && ipx_nullhost(ipxpcb.ipxp_faddr) ) {
106 continue;
108 kread((u_long)ipxpcb.ipxp_socket,
109 (char *)&sockb, sizeof (sockb));
110 ppcb = (u_long) ipxpcb.ipxp_pcb;
111 if (ppcb) {
112 if (isspx) {
113 kread(ppcb, (char *)&spxpcb, sizeof (spxpcb));
114 } else continue;
115 } else
116 if (isspx) continue;
117 if (first) {
118 printf("Active IPX connections");
119 if (aflag)
120 printf(" (including servers)");
121 putchar('\n');
122 if (Aflag)
123 printf("%-8.8s ", "PCB");
124 printf(Aflag ?
125 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
126 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
127 "Proto", "Recv-Q", "Send-Q",
128 "Local Address", "Foreign Address", "(state)");
129 first = 0;
131 if (Aflag)
132 printf("%8lx ", ppcb);
133 printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
134 sockb.so_snd.sb_cc);
135 printf(Aflag?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb.ipxp_laddr));
136 printf(Aflag?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb.ipxp_faddr));
137 if (isspx) {
138 extern char *tcpstates[];
139 if (spxpcb.s_state >= TCP_NSTATES)
140 printf(" %d", spxpcb.s_state);
141 else
142 printf(" %s", tcpstates[spxpcb.s_state]);
144 putchar('\n');
145 prev = next;
149 #define ANY(x,y,z) \
150 if (x || sflag <= 1) printf("\t%u %s%s%s\n", x, y, plural(x), z)
151 #define ANYl(x,y,z) \
152 if (x || sflag <= 1) printf("\t%lu %s%s%s\n", x, y, plural(x), z)
155 * Dump SPX statistics structure.
157 void
158 spx_stats(u_long off, char *name, int af __unused)
160 struct spx_istat spx_istat;
161 #define spxstat spx_istat.newstats
163 if (off == 0)
164 return;
165 kread(off, (char *)&spx_istat, sizeof (spx_istat));
166 printf("%s:\n", name);
167 ANY(spx_istat.nonucn, "connection", " dropped due to no new sockets ");
168 ANY(spx_istat.gonawy, "connection", " terminated due to our end dying");
169 ANY(spx_istat.nonucn, "connection",
170 " dropped due to inability to connect");
171 ANY(spx_istat.noconn, "connection",
172 " dropped due to inability to connect");
173 ANY(spx_istat.notme, "connection",
174 " incompleted due to mismatched id's");
175 ANY(spx_istat.wrncon, "connection", " dropped due to mismatched id's");
176 ANY(spx_istat.bdreas, "packet", " dropped out of sequence");
177 ANY(spx_istat.lstdup, "packet", " duplicating the highest packet");
178 ANY(spx_istat.notyet, "packet", " refused as exceeding allocation");
179 ANYl(spxstat.spxs_connattempt, "connection", " initiated");
180 ANYl(spxstat.spxs_accepts, "connection", " accepted");
181 ANYl(spxstat.spxs_connects, "connection", " established");
182 ANYl(spxstat.spxs_drops, "connection", " dropped");
183 ANYl(spxstat.spxs_conndrops, "embryonic connection", " dropped");
184 ANYl(spxstat.spxs_closed, "connection", " closed (includes drops)");
185 ANYl(spxstat.spxs_segstimed, "packet", " where we tried to get rtt");
186 ANYl(spxstat.spxs_rttupdated, "time", " we got rtt");
187 ANYl(spxstat.spxs_delack, "delayed ack", " sent");
188 ANYl(spxstat.spxs_timeoutdrop, "connection",
189 " dropped in rxmt timeout");
190 ANYl(spxstat.spxs_rexmttimeo, "retransmit timeout", "");
191 ANYl(spxstat.spxs_persisttimeo, "persist timeout", "");
192 ANYl(spxstat.spxs_keeptimeo, "keepalive timeout", "");
193 ANYl(spxstat.spxs_keepprobe, "keepalive probe", " sent");
194 ANYl(spxstat.spxs_keepdrops, "connection", " dropped in keepalive");
195 ANYl(spxstat.spxs_sndtotal, "total packet", " sent");
196 ANYl(spxstat.spxs_sndpack, "data packet", " sent");
197 ANYl(spxstat.spxs_sndbyte, "data byte", " sent");
198 ANYl(spxstat.spxs_sndrexmitpack, "data packet", " retransmitted");
199 ANYl(spxstat.spxs_sndrexmitbyte, "data byte", " retransmitted");
200 ANYl(spxstat.spxs_sndacks, "ack-only packet", " sent");
201 ANYl(spxstat.spxs_sndprobe, "window probe", " sent");
202 ANYl(spxstat.spxs_sndurg, "packet", " sent with URG only");
203 ANYl(spxstat.spxs_sndwinup, "window update-only packet", " sent");
204 ANYl(spxstat.spxs_sndctrl, "control (SYN|FIN|RST) packet", " sent");
205 ANYl(spxstat.spxs_sndvoid, "request", " to send a non-existant packet");
206 ANYl(spxstat.spxs_rcvtotal, "total packet", " received");
207 ANYl(spxstat.spxs_rcvpack, "packet", " received in sequence");
208 ANYl(spxstat.spxs_rcvbyte, "byte", " received in sequence");
209 ANYl(spxstat.spxs_rcvbadsum, "packet", " received with ccksum errs");
210 ANYl(spxstat.spxs_rcvbadoff, "packet", " received with bad offset");
211 ANYl(spxstat.spxs_rcvshort, "packet", " received too short");
212 ANYl(spxstat.spxs_rcvduppack, "duplicate-only packet", " received");
213 ANYl(spxstat.spxs_rcvdupbyte, "duplicate-only byte", " received");
214 ANYl(spxstat.spxs_rcvpartduppack, "packet",
215 " with some duplicate data");
216 ANYl(spxstat.spxs_rcvpartdupbyte, "dup. byte", " in part-dup. packet");
217 ANYl(spxstat.spxs_rcvoopack, "out-of-order packet", " received");
218 ANYl(spxstat.spxs_rcvoobyte, "out-of-order byte", " received");
219 ANYl(spxstat.spxs_rcvpackafterwin, "packet", " with data after window");
220 ANYl(spxstat.spxs_rcvbyteafterwin, "byte", " rcvd after window");
221 ANYl(spxstat.spxs_rcvafterclose, "packet", " rcvd after 'close'");
222 ANYl(spxstat.spxs_rcvwinprobe, "rcvd window probe packet", "");
223 ANYl(spxstat.spxs_rcvdupack, "rcvd duplicate ack", "");
224 ANYl(spxstat.spxs_rcvacktoomuch, "rcvd ack", " for unsent data");
225 ANYl(spxstat.spxs_rcvackpack, "rcvd ack packet", "");
226 ANYl(spxstat.spxs_rcvackbyte, "byte", " acked by rcvd acks");
227 ANYl(spxstat.spxs_rcvwinupd, "rcvd window update packet", "");
231 * Dump IPX statistics structure.
233 void
234 ipx_stats(u_long off, char *name, int af __unused)
236 struct ipxstat ipxstat;
238 if (off == 0)
239 return;
240 kread(off, (char *)&ipxstat, sizeof (ipxstat));
241 printf("%s:\n", name);
242 ANYl(ipxstat.ipxs_total, "total packet", " received");
243 ANYl(ipxstat.ipxs_badsum, "packet", " with bad checksums");
244 ANYl(ipxstat.ipxs_tooshort, "packet", " smaller than advertised");
245 ANYl(ipxstat.ipxs_toosmall, "packet", " smaller than a header");
246 ANYl(ipxstat.ipxs_forward, "packet", " forwarded");
247 ANYl(ipxstat.ipxs_cantforward, "packet", " not forwardable");
248 ANYl(ipxstat.ipxs_delivered, "packet", " for this host");
249 ANYl(ipxstat.ipxs_localout, "packet", " sent from this host");
250 ANYl(ipxstat.ipxs_odropped, "packet", " dropped due to no bufs, etc.");
251 ANYl(ipxstat.ipxs_noroute, "packet", " discarded due to no route");
252 ANYl(ipxstat.ipxs_mtutoosmall, "packet", " too big");
255 #ifdef IPXERRORMSGS
256 static struct {
257 u_short code;
258 char *name;
259 char *where;
260 } ipx_errnames[] = {
261 {0, "Unspecified Error", " at Destination"},
262 {1, "Bad Checksum", " at Destination"},
263 {2, "No Listener", " at Socket"},
264 {3, "Packet", " Refused due to lack of space at Destination"},
265 {01000, "Unspecified Error", " while gatewayed"},
266 {01001, "Bad Checksum", " while gatewayed"},
267 {01002, "Packet", " forwarded too many times"},
268 {01003, "Packet", " too large to be forwarded"},
269 {-1, 0, 0},
273 * Dump IPX Error statistics structure.
275 /*ARGSUSED*/
276 void
277 ipxerr_stats(u_long off, char *name, int af __unused)
279 struct ipx_errstat ipx_errstat;
280 int j;
281 int histoprint = 1;
282 int z;
284 if (off == 0)
285 return;
286 kread(off, (char *)&ipx_errstat, sizeof (ipx_errstat));
287 printf("IPX error statistics:\n");
288 ANY(ipx_errstat.ipx_es_error, "call", " to ipx_error");
289 ANY(ipx_errstat.ipx_es_oldshort, "error",
290 " ignored due to insufficient addressing");
291 ANY(ipx_errstat.ipx_es_oldipx_err, "error request",
292 " in response to error packets");
293 ANY(ipx_errstat.ipx_es_tooshort, "error packet",
294 " received incomplete");
295 ANY(ipx_errstat.ipx_es_badcode, "error packet",
296 " received of unknown type");
297 for(j = 0; j < IPX_ERR_MAX; j ++) {
298 z = ipx_errstat.ipx_es_outhist[j];
299 if (z && histoprint) {
300 printf("Output Error Histogram:\n");
301 histoprint = 0;
303 ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
305 histoprint = 1;
306 for(j = 0; j < IPX_ERR_MAX; j ++) {
307 z = ipx_errstat.ipx_es_inhist[j];
308 if (z && histoprint) {
309 printf("Input Error Histogram:\n");
310 histoprint = 0;
312 ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
316 static void
317 ipx_erputil(int z, int c)
319 int j;
320 char codebuf[30];
321 char *name, *where;
323 for(j = 0;; j ++) {
324 if ((name = ipx_errnames[j].name) == 0)
325 break;
326 if (ipx_errnames[j].code == c)
327 break;
329 if (name == 0) {
330 if (c > 01000)
331 where = "in transit";
332 else
333 where = "at destination";
334 sprintf(codebuf, "Unknown IPX error code 0%o", c);
335 name = codebuf;
336 } else
337 where = ipx_errnames[j].where;
338 ANY(z, name, where);
340 #endif /* IPXERRORMSGS */
342 static struct sockaddr_ipx ssipx = {AF_IPX};
344 static
345 char *ipx_prpr(struct ipx_addr *x)
347 struct sockaddr_ipx *sipx = &ssipx;
349 sipx->sipx_addr = *x;
350 return(ipx_print((struct sockaddr *)sipx));