]>
git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/ns.c
8ceff197d6523b13a899855f945478b9fbdabb68
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1983, 1988, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 static char sccsid
[] = "@(#)ns.c 8.1 (Berkeley) 6/6/93";
61 #include <sys/param.h>
62 #include <sys/socket.h>
63 #include <sys/socketvar.h>
66 #include <net/route.h>
69 #include <netinet/tcp_fsm.h>
72 #include <netns/ns_pcb.h>
73 #include <netns/idp.h>
74 #include <netns/idp_var.h>
75 #include <netns/ns_error.h>
77 #include <netns/spidp.h>
78 #include <netns/spp_timer.h>
79 #include <netns/spp_var.h>
81 #include <netns/spp_debug.h>
91 static struct socket sockb
;
93 static char *ns_prpr
__P((struct ns_addr
*));
94 static void ns_erputil
__P((int, int));
99 * Print a summary of connections related to a Network Systems
100 * protocol. For SPP, also give state of connection.
101 * Listening processes (aflag) are suppressed unless the
102 * -a (all) flag is specified.
111 register struct nspcb
*prev
, *next
;
116 isspp
= strcmp(name
, "spp") == 0;
117 kread(off
, (char *)&cb
, sizeof (struct nspcb
));
119 prev
= (struct nspcb
*)off
;
120 if (nspcb
.nsp_next
== (struct nspcb
*)off
)
122 for (;nspcb
.nsp_next
!= (struct nspcb
*)off
; prev
= next
) {
125 next
= nspcb
.nsp_next
;
126 kread((u_long
)next
, (char *)&nspcb
, sizeof (nspcb
));
127 if (nspcb
.nsp_prev
!= prev
) {
131 if (!aflag
&& ns_nullhost(nspcb
.nsp_faddr
) ) {
134 kread((u_long
)nspcb
.nsp_socket
,
135 (char *)&sockb
, sizeof (sockb
));
136 ppcb
= (u_long
) nspcb
.nsp_pcb
;
139 kread(ppcb
, (char *)&sppcb
, sizeof (sppcb
));
144 printf("Active NS connections");
146 printf(" (including servers)");
149 printf("%-8.8s ", "PCB");
151 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
152 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
153 "Proto", "Recv-Q", "Send-Q",
154 "Local Address", "Foreign Address", "(state)");
158 printf("%8x ", ppcb
);
159 printf("%-5.5s %6d %6d ", name
, sockb
.so_rcv
.sb_cc
,
161 printf(" %-22.22s", ns_prpr(&nspcb
.nsp_laddr
));
162 printf(" %-22.22s", ns_prpr(&nspcb
.nsp_faddr
));
164 extern char *tcpstates
[];
165 if (sppcb
.s_state
>= TCP_NSTATES
)
166 printf(" %d", sppcb
.s_state
);
168 printf(" %s", tcpstates
[sppcb
.s_state
]);
175 ((x) ? printf("\t%d %s%s%s -- %s\n",x,y,plural(x),z,"x") : 0)
178 * Dump SPP statistics structure.
185 struct spp_istat spp_istat
;
186 #define sppstat spp_istat.newstats
190 kread(off
, (char *)&spp_istat
, sizeof (spp_istat
));
191 printf("%s:\n", name
);
192 ANY(spp_istat
.nonucn
, "connection", " dropped due to no new sockets ");
193 ANY(spp_istat
.gonawy
, "connection", " terminated due to our end dying");
194 ANY(spp_istat
.nonucn
, "connection",
195 " dropped due to inability to connect");
196 ANY(spp_istat
.noconn
, "connection",
197 " dropped due to inability to connect");
198 ANY(spp_istat
.notme
, "connection",
199 " incompleted due to mismatched id's");
200 ANY(spp_istat
.wrncon
, "connection", " dropped due to mismatched id's");
201 ANY(spp_istat
.bdreas
, "packet", " dropped out of sequence");
202 ANY(spp_istat
.lstdup
, "packet", " duplicating the highest packet");
203 ANY(spp_istat
.notyet
, "packet", " refused as exceeding allocation");
204 ANY(sppstat
.spps_connattempt
, "connection", " initiated");
205 ANY(sppstat
.spps_accepts
, "connection", " accepted");
206 ANY(sppstat
.spps_connects
, "connection", " established");
207 ANY(sppstat
.spps_drops
, "connection", " dropped");
208 ANY(sppstat
.spps_conndrops
, "embryonic connection", " dropped");
209 ANY(sppstat
.spps_closed
, "connection", " closed (includes drops)");
210 ANY(sppstat
.spps_segstimed
, "packet", " where we tried to get rtt");
211 ANY(sppstat
.spps_rttupdated
, "time", " we got rtt");
212 ANY(sppstat
.spps_delack
, "delayed ack", " sent");
213 ANY(sppstat
.spps_timeoutdrop
, "connection", " dropped in rxmt timeout");
214 ANY(sppstat
.spps_rexmttimeo
, "retransmit timeout", "");
215 ANY(sppstat
.spps_persisttimeo
, "persist timeout", "");
216 ANY(sppstat
.spps_keeptimeo
, "keepalive timeout", "");
217 ANY(sppstat
.spps_keepprobe
, "keepalive probe", " sent");
218 ANY(sppstat
.spps_keepdrops
, "connection", " dropped in keepalive");
219 ANY(sppstat
.spps_sndtotal
, "total packet", " sent");
220 ANY(sppstat
.spps_sndpack
, "data packet", " sent");
221 ANY(sppstat
.spps_sndbyte
, "data byte", " sent");
222 ANY(sppstat
.spps_sndrexmitpack
, "data packet", " retransmitted");
223 ANY(sppstat
.spps_sndrexmitbyte
, "data byte", " retransmitted");
224 ANY(sppstat
.spps_sndacks
, "ack-only packet", " sent");
225 ANY(sppstat
.spps_sndprobe
, "window probe", " sent");
226 ANY(sppstat
.spps_sndurg
, "packet", " sent with URG only");
227 ANY(sppstat
.spps_sndwinup
, "window update-only packet", " sent");
228 ANY(sppstat
.spps_sndctrl
, "control (SYN|FIN|RST) packet", " sent");
229 ANY(sppstat
.spps_sndvoid
, "request", " to send a non-existant packet");
230 ANY(sppstat
.spps_rcvtotal
, "total packet", " received");
231 ANY(sppstat
.spps_rcvpack
, "packet", " received in sequence");
232 ANY(sppstat
.spps_rcvbyte
, "byte", " received in sequence");
233 ANY(sppstat
.spps_rcvbadsum
, "packet", " received with ccksum errs");
234 ANY(sppstat
.spps_rcvbadoff
, "packet", " received with bad offset");
235 ANY(sppstat
.spps_rcvshort
, "packet", " received too short");
236 ANY(sppstat
.spps_rcvduppack
, "duplicate-only packet", " received");
237 ANY(sppstat
.spps_rcvdupbyte
, "duplicate-only byte", " received");
238 ANY(sppstat
.spps_rcvpartduppack
, "packet", " with some duplicate data");
239 ANY(sppstat
.spps_rcvpartdupbyte
, "dup. byte", " in part-dup. packet");
240 ANY(sppstat
.spps_rcvoopack
, "out-of-order packet", " received");
241 ANY(sppstat
.spps_rcvoobyte
, "out-of-order byte", " received");
242 ANY(sppstat
.spps_rcvpackafterwin
, "packet", " with data after window");
243 ANY(sppstat
.spps_rcvbyteafterwin
, "byte", " rcvd after window");
244 ANY(sppstat
.spps_rcvafterclose
, "packet", " rcvd after 'close'");
245 ANY(sppstat
.spps_rcvwinprobe
, "rcvd window probe packet", "");
246 ANY(sppstat
.spps_rcvdupack
, "rcvd duplicate ack", "");
247 ANY(sppstat
.spps_rcvacktoomuch
, "rcvd ack", " for unsent data");
248 ANY(sppstat
.spps_rcvackpack
, "rcvd ack packet", "");
249 ANY(sppstat
.spps_rcvackbyte
, "byte", " acked by rcvd acks");
250 ANY(sppstat
.spps_rcvwinupd
, "rcvd window update packet", "");
253 #define ANY(x,y,z) ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0)
256 * Dump IDP statistics structure.
263 struct idpstat idpstat
;
267 kread(off
, (char *)&idpstat
, sizeof (idpstat
));
268 printf("%s:\n", name
);
269 ANY(idpstat
.idps_toosmall
, "packet", " smaller than a header");
270 ANY(idpstat
.idps_tooshort
, "packet", " smaller than advertised");
271 ANY(idpstat
.idps_badsum
, "packet", " with bad checksums");
279 {0, "Unspecified Error", " at Destination"},
280 {1, "Bad Checksum", " at Destination"},
281 {2, "No Listener", " at Socket"},
282 {3, "Packet", " Refused due to lack of space at Destination"},
283 {01000, "Unspecified Error", " while gatewayed"},
284 {01001, "Bad Checksum", " while gatewayed"},
285 {01002, "Packet", " forwarded too many times"},
286 {01003, "Packet", " too large to be forwarded"},
291 * Dump NS Error statistics structure.
295 nserr_stats(off
, name
)
299 struct ns_errstat ns_errstat
;
301 register int histoprint
= 1;
306 kread(off
, (char *)&ns_errstat
, sizeof (ns_errstat
));
307 printf("NS error statistics:\n");
308 ANY(ns_errstat
.ns_es_error
, "call", " to ns_error");
309 ANY(ns_errstat
.ns_es_oldshort
, "error",
310 " ignored due to insufficient addressing");
311 ANY(ns_errstat
.ns_es_oldns_err
, "error request",
312 " in response to error packets");
313 ANY(ns_errstat
.ns_es_tooshort
, "error packet",
314 " received incomplete");
315 ANY(ns_errstat
.ns_es_badcode
, "error packet",
316 " received of unknown type");
317 for(j
= 0; j
< NS_ERR_MAX
; j
++) {
318 z
= ns_errstat
.ns_es_outhist
[j
];
319 if (z
&& histoprint
) {
320 printf("Output Error Histogram:\n");
323 ns_erputil(z
, ns_errstat
.ns_es_codes
[j
]);
327 for(j
= 0; j
< NS_ERR_MAX
; j
++) {
328 z
= ns_errstat
.ns_es_inhist
[j
];
329 if (z
&& histoprint
) {
330 printf("Input Error Histogram:\n");
333 ns_erputil(z
, ns_errstat
.ns_es_codes
[j
]);
346 if ((name
= ns_errnames
[j
].name
) == 0)
348 if (ns_errnames
[j
].code
== c
)
353 where
= "in transit";
355 where
= "at destination";
356 sprintf(codebuf
, "Unknown XNS error code 0%o", c
);
359 where
= ns_errnames
[j
].where
;
363 static struct sockaddr_ns ssns
= {AF_NS
};
369 struct sockaddr_ns
*sns
= &ssns
;
372 return(ns_print((struct sockaddr
*)sns
));