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
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.6 2007/05/17 08:19:02 swildner Exp $
38 #define _KERNEL_STRUCTURES
39 #include <sys/param.h>
40 #include <sys/queue.h>
41 #include <sys/socket.h>
42 #include <sys/socketvar.h>
43 #include <sys/protosw.h>
45 #include <net/route.h>
47 #include <netinet/tcp_fsm.h>
49 #include <netipx/ipx.h>
50 #include <netipx/ipx_pcb.h>
51 #include <netipx/ipx_var.h>
53 #include <netipx/ipx_error.h>
55 #include <netipx/spx.h>
56 #include <netipx/spx_timer.h>
57 #include <netipx/spx_var.h>
59 #include <netipx/spx_debug.h>
67 extern char *tcpstates
[];
73 static char *ipx_prpr (struct ipx_addr
*);
78 * Print a summary of connections related to a Network Systems
79 * protocol. For SPX, also give state of connection.
80 * Listening processes (aflag) are suppressed unless the
81 * -a (all) flag is specified.
85 ipxprotopr(u_long off
, const char *name
, int af1 __unused
)
88 struct ipxpcb
*prev
, *next
;
93 isspx
= strcmp(name
, "spx") == 0;
94 kread(off
, (char *)&cb
, sizeof (struct ipxpcb
));
96 prev
= (struct ipxpcb
*)off
;
97 if (ipxpcb
.ipxp_next
== (struct ipxpcb
*)off
)
99 for (;ipxpcb
.ipxp_next
!= (struct ipxpcb
*)off
; prev
= next
) {
102 next
= ipxpcb
.ipxp_next
;
103 kread((u_long
)next
, (char *)&ipxpcb
, sizeof (ipxpcb
));
104 if (ipxpcb
.ipxp_prev
!= prev
) {
108 if (!aflag
&& ipx_nullhost(ipxpcb
.ipxp_faddr
) ) {
111 kread((u_long
)ipxpcb
.ipxp_socket
,
112 (char *)&sockb
, sizeof (sockb
));
113 ppcb
= (u_long
) ipxpcb
.ipxp_pcb
;
116 kread(ppcb
, (char *)&spxpcb
, sizeof (spxpcb
));
121 printf("Active IPX connections");
123 printf(" (including servers)");
126 printf("%-8.8s ", "PCB");
128 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
129 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
130 "Proto", "Recv-Q", "Send-Q",
131 "Local Address", "Foreign Address", "(state)");
135 printf("%8lx ", ppcb
);
136 printf("%-5.5s %6ld %6ld ", name
, sockb
.so_rcv
.ssb_cc
,
137 sockb
.so_snd
.ssb_cc
);
138 printf(Aflag
?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb
.ipxp_laddr
));
139 printf(Aflag
?" %-18.18s":" %-22.22s", ipx_prpr(&ipxpcb
.ipxp_faddr
));
141 if (spxpcb
.s_state
>= TCP_NSTATES
)
142 printf(" %d", spxpcb
.s_state
);
144 printf(" %s", tcpstates
[spxpcb
.s_state
]);
152 if (x || sflag <= 1) printf("\t%u %s%s%s\n", x, y, plural(x), z)
153 #define ANYl(x,y,z) \
154 if (x || sflag <= 1) printf("\t%lu %s%s%s\n", x, y, plural(x), z)
157 * Dump SPX statistics structure.
160 spx_stats(u_long off
, const char *name
, int af1 __unused
)
162 struct spx_istat spx_istat
;
163 #define spxstat spx_istat.newstats
167 kread(off
, (char *)&spx_istat
, sizeof (spx_istat
));
168 printf("%s:\n", name
);
169 ANY(spx_istat
.nonucn
, "connection", " dropped due to no new sockets ");
170 ANY(spx_istat
.gonawy
, "connection", " terminated due to our end dying");
171 ANY(spx_istat
.nonucn
, "connection",
172 " dropped due to inability to connect");
173 ANY(spx_istat
.noconn
, "connection",
174 " dropped due to inability to connect");
175 ANY(spx_istat
.notme
, "connection",
176 " incompleted due to mismatched id's");
177 ANY(spx_istat
.wrncon
, "connection", " dropped due to mismatched id's");
178 ANY(spx_istat
.bdreas
, "packet", " dropped out of sequence");
179 ANY(spx_istat
.lstdup
, "packet", " duplicating the highest packet");
180 ANY(spx_istat
.notyet
, "packet", " refused as exceeding allocation");
181 ANYl(spxstat
.spxs_connattempt
, "connection", " initiated");
182 ANYl(spxstat
.spxs_accepts
, "connection", " accepted");
183 ANYl(spxstat
.spxs_connects
, "connection", " established");
184 ANYl(spxstat
.spxs_drops
, "connection", " dropped");
185 ANYl(spxstat
.spxs_conndrops
, "embryonic connection", " dropped");
186 ANYl(spxstat
.spxs_closed
, "connection", " closed (includes drops)");
187 ANYl(spxstat
.spxs_segstimed
, "packet", " where we tried to get rtt");
188 ANYl(spxstat
.spxs_rttupdated
, "time", " we got rtt");
189 ANYl(spxstat
.spxs_delack
, "delayed ack", " sent");
190 ANYl(spxstat
.spxs_timeoutdrop
, "connection",
191 " dropped in rxmt timeout");
192 ANYl(spxstat
.spxs_rexmttimeo
, "retransmit timeout", "");
193 ANYl(spxstat
.spxs_persisttimeo
, "persist timeout", "");
194 ANYl(spxstat
.spxs_keeptimeo
, "keepalive timeout", "");
195 ANYl(spxstat
.spxs_keepprobe
, "keepalive probe", " sent");
196 ANYl(spxstat
.spxs_keepdrops
, "connection", " dropped in keepalive");
197 ANYl(spxstat
.spxs_sndtotal
, "total packet", " sent");
198 ANYl(spxstat
.spxs_sndpack
, "data packet", " sent");
199 ANYl(spxstat
.spxs_sndbyte
, "data byte", " sent");
200 ANYl(spxstat
.spxs_sndrexmitpack
, "data packet", " retransmitted");
201 ANYl(spxstat
.spxs_sndrexmitbyte
, "data byte", " retransmitted");
202 ANYl(spxstat
.spxs_sndacks
, "ack-only packet", " sent");
203 ANYl(spxstat
.spxs_sndprobe
, "window probe", " sent");
204 ANYl(spxstat
.spxs_sndurg
, "packet", " sent with URG only");
205 ANYl(spxstat
.spxs_sndwinup
, "window update-only packet", " sent");
206 ANYl(spxstat
.spxs_sndctrl
, "control (SYN|FIN|RST) packet", " sent");
207 ANYl(spxstat
.spxs_sndvoid
, "request", " to send a non-existent packet");
208 ANYl(spxstat
.spxs_rcvtotal
, "total packet", " received");
209 ANYl(spxstat
.spxs_rcvpack
, "packet", " received in sequence");
210 ANYl(spxstat
.spxs_rcvbyte
, "byte", " received in sequence");
211 ANYl(spxstat
.spxs_rcvbadsum
, "packet", " received with ccksum errs");
212 ANYl(spxstat
.spxs_rcvbadoff
, "packet", " received with bad offset");
213 ANYl(spxstat
.spxs_rcvshort
, "packet", " received too short");
214 ANYl(spxstat
.spxs_rcvduppack
, "duplicate-only packet", " received");
215 ANYl(spxstat
.spxs_rcvdupbyte
, "duplicate-only byte", " received");
216 ANYl(spxstat
.spxs_rcvpartduppack
, "packet",
217 " with some duplicate data");
218 ANYl(spxstat
.spxs_rcvpartdupbyte
, "dup. byte", " in part-dup. packet");
219 ANYl(spxstat
.spxs_rcvoopack
, "out-of-order packet", " received");
220 ANYl(spxstat
.spxs_rcvoobyte
, "out-of-order byte", " received");
221 ANYl(spxstat
.spxs_rcvpackafterwin
, "packet", " with data after window");
222 ANYl(spxstat
.spxs_rcvbyteafterwin
, "byte", " rcvd after window");
223 ANYl(spxstat
.spxs_rcvafterclose
, "packet", " rcvd after 'close'");
224 ANYl(spxstat
.spxs_rcvwinprobe
, "rcvd window probe packet", "");
225 ANYl(spxstat
.spxs_rcvdupack
, "rcvd duplicate ack", "");
226 ANYl(spxstat
.spxs_rcvacktoomuch
, "rcvd ack", " for unsent data");
227 ANYl(spxstat
.spxs_rcvackpack
, "rcvd ack packet", "");
228 ANYl(spxstat
.spxs_rcvackbyte
, "byte", " acked by rcvd acks");
229 ANYl(spxstat
.spxs_rcvwinupd
, "rcvd window update packet", "");
233 * Dump IPX statistics structure.
236 ipx_stats(u_long off
, const char *name
, int af1 __unused
)
238 struct ipxstat ipxstat
;
242 kread(off
, (char *)&ipxstat
, sizeof (ipxstat
));
243 printf("%s:\n", name
);
244 ANYl(ipxstat
.ipxs_total
, "total packet", " received");
245 ANYl(ipxstat
.ipxs_badsum
, "packet", " with bad checksums");
246 ANYl(ipxstat
.ipxs_tooshort
, "packet", " smaller than advertised");
247 ANYl(ipxstat
.ipxs_toosmall
, "packet", " smaller than a header");
248 ANYl(ipxstat
.ipxs_forward
, "packet", " forwarded");
249 ANYl(ipxstat
.ipxs_cantforward
, "packet", " not forwardable");
250 ANYl(ipxstat
.ipxs_delivered
, "packet", " for this host");
251 ANYl(ipxstat
.ipxs_localout
, "packet", " sent from this host");
252 ANYl(ipxstat
.ipxs_odropped
, "packet", " dropped due to no bufs, etc.");
253 ANYl(ipxstat
.ipxs_noroute
, "packet", " discarded due to no route");
254 ANYl(ipxstat
.ipxs_mtutoosmall
, "packet", " too big");
263 {0, "Unspecified Error", " at Destination"},
264 {1, "Bad Checksum", " at Destination"},
265 {2, "No Listener", " at Socket"},
266 {3, "Packet", " Refused due to lack of space at Destination"},
267 {01000, "Unspecified Error", " while gatewayed"},
268 {01001, "Bad Checksum", " while gatewayed"},
269 {01002, "Packet", " forwarded too many times"},
270 {01003, "Packet", " too large to be forwarded"},
275 * Dump IPX Error statistics structure.
279 ipxerr_stats(u_long off
, char *name
, int af __unused
)
281 struct ipx_errstat ipx_errstat
;
288 kread(off
, (char *)&ipx_errstat
, sizeof (ipx_errstat
));
289 printf("IPX error statistics:\n");
290 ANY(ipx_errstat
.ipx_es_error
, "call", " to ipx_error");
291 ANY(ipx_errstat
.ipx_es_oldshort
, "error",
292 " ignored due to insufficient addressing");
293 ANY(ipx_errstat
.ipx_es_oldipx_err
, "error request",
294 " in response to error packets");
295 ANY(ipx_errstat
.ipx_es_tooshort
, "error packet",
296 " received incomplete");
297 ANY(ipx_errstat
.ipx_es_badcode
, "error packet",
298 " received of unknown type");
299 for(j
= 0; j
< IPX_ERR_MAX
; j
++) {
300 z
= ipx_errstat
.ipx_es_outhist
[j
];
301 if (z
&& histoprint
) {
302 printf("Output Error Histogram:\n");
305 ipx_erputil(z
, ipx_errstat
.ipx_es_codes
[j
]);
308 for(j
= 0; j
< IPX_ERR_MAX
; j
++) {
309 z
= ipx_errstat
.ipx_es_inhist
[j
];
310 if (z
&& histoprint
) {
311 printf("Input Error Histogram:\n");
314 ipx_erputil(z
, ipx_errstat
.ipx_es_codes
[j
]);
319 ipx_erputil(int z
, int c
)
326 if ((name
= ipx_errnames
[j
].name
) == 0)
328 if (ipx_errnames
[j
].code
== c
)
333 where
= "in transit";
335 where
= "at destination";
336 sprintf(codebuf
, "Unknown IPX error code 0%o", c
);
339 where
= ipx_errnames
[j
].where
;
342 #endif /* IPXERRORMSGS */
344 static struct sockaddr_ipx ssipx
= { .sipx_family
= AF_IPX
};
347 char *ipx_prpr(struct ipx_addr
*x
)
349 struct sockaddr_ipx
*sipx
= &ssipx
;
351 sipx
->sipx_addr
= *x
;
352 return(ipx_print((struct sockaddr
*)sipx
));