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
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
36 static char sccsid[] = "@(#)ns.c 8.1 (Berkeley) 6/6/93";
38 static const char rcsid[] =
39 "$FreeBSD: src/usr.bin/netstat/ipx.c,v 1.13.2.1 2001/08/10 09:07:09 ru Exp $";
42 #include <sys/param.h>
43 #include <sys/queue.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
46 #include <sys/protosw.h>
48 #include <net/route.h>
50 #include <netinet/tcp_fsm.h>
52 #include <netipx/ipx.h>
53 #include <netipx/ipx_pcb.h>
54 #include <netipx/ipx_var.h>
56 #include <netipx/ipx_error.h>
58 #include <netipx/spx.h>
59 #include <netipx/spx_timer.h>
60 #include <netipx/spx_var.h>
62 #include <netipx/spx_debug.h>
74 static char *ipx_prpr (struct ipx_addr *);
79 * Print a summary of connections related to a Network Systems
80 * protocol. For SPX, also give state of connection.
81 * Listening processes (aflag) are suppressed unless the
82 * -a (all) flag is specified.
86 ipxprotopr(u_long off, char *name, int af __unused)
89 register struct ipxpcb *prev, *next;
94 isspx = strcmp(name, "spx") == 0;
95 kread(off, (char *)&cb, sizeof (struct ipxpcb));
97 prev = (struct ipxpcb *)off;
98 if (ipxpcb.ipxp_next == (struct ipxpcb *)off)
100 for (;ipxpcb.ipxp_next != (struct ipxpcb *)off; prev = next) {
103 next = ipxpcb.ipxp_next;
104 kread((u_long)next, (char *)&ipxpcb, sizeof (ipxpcb));
105 if (ipxpcb.ipxp_prev != prev) {
109 if (!aflag && ipx_nullhost(ipxpcb.ipxp_faddr) ) {
112 kread((u_long)ipxpcb.ipxp_socket,
113 (char *)&sockb, sizeof (sockb));
114 ppcb = (u_long) ipxpcb.ipxp_pcb;
117 kread(ppcb, (char *)&spxpcb, sizeof (spxpcb));
122 printf("Active IPX connections");
124 printf(" (including servers)");
127 printf("%-8.8s ", "PCB");
129 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
130 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
131 "Proto", "Recv-Q", "Send-Q",
132 "Local Address", "Foreign Address", "(state)");
136 printf("%8lx ", ppcb);
137 printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
139 printf(Aflag?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb.ipxp_laddr));
140 printf(Aflag?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb.ipxp_faddr));
142 extern char *tcpstates[];
143 if (spxpcb.s_state >= TCP_NSTATES)
144 printf(" %d", spxpcb.s_state);
146 printf(" %s", tcpstates[spxpcb.s_state]);
154 if (x || sflag <= 1) printf("\t%u %s%s%s\n", x, y, plural(x), z)
155 #define ANYl(x,y,z) \
156 if (x || sflag <= 1) printf("\t%lu %s%s%s\n", x, y, plural(x), z)
159 * Dump SPX statistics structure.
162 spx_stats(u_long off, char *name, int af __unused)
164 struct spx_istat spx_istat;
165 #define spxstat spx_istat.newstats
169 kread(off, (char *)&spx_istat, sizeof (spx_istat));
170 printf("%s:\n", name);
171 ANY(spx_istat.nonucn, "connection", " dropped due to no new sockets ");
172 ANY(spx_istat.gonawy, "connection", " terminated due to our end dying");
173 ANY(spx_istat.nonucn, "connection",
174 " dropped due to inability to connect");
175 ANY(spx_istat.noconn, "connection",
176 " dropped due to inability to connect");
177 ANY(spx_istat.notme, "connection",
178 " incompleted due to mismatched id's");
179 ANY(spx_istat.wrncon, "connection", " dropped due to mismatched id's");
180 ANY(spx_istat.bdreas, "packet", " dropped out of sequence");
181 ANY(spx_istat.lstdup, "packet", " duplicating the highest packet");
182 ANY(spx_istat.notyet, "packet", " refused as exceeding allocation");
183 ANYl(spxstat.spxs_connattempt, "connection", " initiated");
184 ANYl(spxstat.spxs_accepts, "connection", " accepted");
185 ANYl(spxstat.spxs_connects, "connection", " established");
186 ANYl(spxstat.spxs_drops, "connection", " dropped");
187 ANYl(spxstat.spxs_conndrops, "embryonic connection", " dropped");
188 ANYl(spxstat.spxs_closed, "connection", " closed (includes drops)");
189 ANYl(spxstat.spxs_segstimed, "packet", " where we tried to get rtt");
190 ANYl(spxstat.spxs_rttupdated, "time", " we got rtt");
191 ANYl(spxstat.spxs_delack, "delayed ack", " sent");
192 ANYl(spxstat.spxs_timeoutdrop, "connection",
193 " dropped in rxmt timeout");
194 ANYl(spxstat.spxs_rexmttimeo, "retransmit timeout", "");
195 ANYl(spxstat.spxs_persisttimeo, "persist timeout", "");
196 ANYl(spxstat.spxs_keeptimeo, "keepalive timeout", "");
197 ANYl(spxstat.spxs_keepprobe, "keepalive probe", " sent");
198 ANYl(spxstat.spxs_keepdrops, "connection", " dropped in keepalive");
199 ANYl(spxstat.spxs_sndtotal, "total packet", " sent");
200 ANYl(spxstat.spxs_sndpack, "data packet", " sent");
201 ANYl(spxstat.spxs_sndbyte, "data byte", " sent");
202 ANYl(spxstat.spxs_sndrexmitpack, "data packet", " retransmitted");
203 ANYl(spxstat.spxs_sndrexmitbyte, "data byte", " retransmitted");
204 ANYl(spxstat.spxs_sndacks, "ack-only packet", " sent");
205 ANYl(spxstat.spxs_sndprobe, "window probe", " sent");
206 ANYl(spxstat.spxs_sndurg, "packet", " sent with URG only");
207 ANYl(spxstat.spxs_sndwinup, "window update-only packet", " sent");
208 ANYl(spxstat.spxs_sndctrl, "control (SYN|FIN|RST) packet", " sent");
209 ANYl(spxstat.spxs_sndvoid, "request", " to send a non-existant packet");
210 ANYl(spxstat.spxs_rcvtotal, "total packet", " received");
211 ANYl(spxstat.spxs_rcvpack, "packet", " received in sequence");
212 ANYl(spxstat.spxs_rcvbyte, "byte", " received in sequence");
213 ANYl(spxstat.spxs_rcvbadsum, "packet", " received with ccksum errs");
214 ANYl(spxstat.spxs_rcvbadoff, "packet", " received with bad offset");
215 ANYl(spxstat.spxs_rcvshort, "packet", " received too short");
216 ANYl(spxstat.spxs_rcvduppack, "duplicate-only packet", " received");
217 ANYl(spxstat.spxs_rcvdupbyte, "duplicate-only byte", " received");
218 ANYl(spxstat.spxs_rcvpartduppack, "packet",
219 " with some duplicate data");
220 ANYl(spxstat.spxs_rcvpartdupbyte, "dup. byte", " in part-dup. packet");
221 ANYl(spxstat.spxs_rcvoopack, "out-of-order packet", " received");
222 ANYl(spxstat.spxs_rcvoobyte, "out-of-order byte", " received");
223 ANYl(spxstat.spxs_rcvpackafterwin, "packet", " with data after window");
224 ANYl(spxstat.spxs_rcvbyteafterwin, "byte", " rcvd after window");
225 ANYl(spxstat.spxs_rcvafterclose, "packet", " rcvd after 'close'");
226 ANYl(spxstat.spxs_rcvwinprobe, "rcvd window probe packet", "");
227 ANYl(spxstat.spxs_rcvdupack, "rcvd duplicate ack", "");
228 ANYl(spxstat.spxs_rcvacktoomuch, "rcvd ack", " for unsent data");
229 ANYl(spxstat.spxs_rcvackpack, "rcvd ack packet", "");
230 ANYl(spxstat.spxs_rcvackbyte, "byte", " acked by rcvd acks");
231 ANYl(spxstat.spxs_rcvwinupd, "rcvd window update packet", "");
235 * Dump IPX statistics structure.
238 ipx_stats(u_long off, char *name, int af __unused)
240 struct ipxstat ipxstat;
244 kread(off, (char *)&ipxstat, sizeof (ipxstat));
245 printf("%s:\n", name);
246 ANYl(ipxstat.ipxs_total, "total packet", " received");
247 ANYl(ipxstat.ipxs_badsum, "packet", " with bad checksums");
248 ANYl(ipxstat.ipxs_tooshort, "packet", " smaller than advertised");
249 ANYl(ipxstat.ipxs_toosmall, "packet", " smaller than a header");
250 ANYl(ipxstat.ipxs_forward, "packet", " forwarded");
251 ANYl(ipxstat.ipxs_cantforward, "packet", " not forwardable");
252 ANYl(ipxstat.ipxs_delivered, "packet", " for this host");
253 ANYl(ipxstat.ipxs_localout, "packet", " sent from this host");
254 ANYl(ipxstat.ipxs_odropped, "packet", " dropped due to no bufs, etc.");
255 ANYl(ipxstat.ipxs_noroute, "packet", " discarded due to no route");
256 ANYl(ipxstat.ipxs_mtutoosmall, "packet", " too big");
265 {0, "Unspecified Error", " at Destination"},
266 {1, "Bad Checksum", " at Destination"},
267 {2, "No Listener", " at Socket"},
268 {3, "Packet", " Refused due to lack of space at Destination"},
269 {01000, "Unspecified Error", " while gatewayed"},
270 {01001, "Bad Checksum", " while gatewayed"},
271 {01002, "Packet", " forwarded too many times"},
272 {01003, "Packet", " too large to be forwarded"},
277 * Dump IPX Error statistics structure.
281 ipxerr_stats(u_long off, char *name, int af __unused)
283 struct ipx_errstat ipx_errstat;
285 register int histoprint = 1;
290 kread(off, (char *)&ipx_errstat, sizeof (ipx_errstat));
291 printf("IPX error statistics:\n");
292 ANY(ipx_errstat.ipx_es_error, "call", " to ipx_error");
293 ANY(ipx_errstat.ipx_es_oldshort, "error",
294 " ignored due to insufficient addressing");
295 ANY(ipx_errstat.ipx_es_oldipx_err, "error request",
296 " in response to error packets");
297 ANY(ipx_errstat.ipx_es_tooshort, "error packet",
298 " received incomplete");
299 ANY(ipx_errstat.ipx_es_badcode, "error packet",
300 " received of unknown type");
301 for(j = 0; j < IPX_ERR_MAX; j ++) {
302 z = ipx_errstat.ipx_es_outhist[j];
303 if (z && histoprint) {
304 printf("Output Error Histogram:\n");
307 ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
310 for(j = 0; j < IPX_ERR_MAX; j ++) {
311 z = ipx_errstat.ipx_es_inhist[j];
312 if (z && histoprint) {
313 printf("Input Error Histogram:\n");
316 ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
321 ipx_erputil(int z, int c)
328 if ((name = ipx_errnames[j].name) == 0)
330 if (ipx_errnames[j].code == c)
335 where = "in transit";
337 where = "at destination";
338 sprintf(codebuf, "Unknown IPX error code 0%o", c);
341 where = ipx_errnames[j].where;
344 #endif /* IPXERRORMSGS */
346 static struct sockaddr_ipx ssipx = {AF_IPX};
349 char *ipx_prpr(struct ipx_addr *x)
351 struct sockaddr_ipx *sipx = &ssipx;
353 sipx->sipx_addr = *x;
354 return(ipx_print((struct sockaddr *)sipx));