Pthread version of stdio warns about bogus size casting.
[unix-history] / usr.bin / netstat / iso.c
CommitLineData
15637ed4
RG
1/*-
2 * Copyright (c) 1989, 1990 The 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
49f80972
GW
35/* From: static char sccsid[] = "@(#)iso.c 5.6 (Berkeley) 4/27/91"; */
36static const char iso_c_rcsid[] =
37 "$Id$";
15637ed4
RG
38#endif /* not lint */
39
15637ed4
RG
40/*******************************************************************************
41 Copyright IBM Corporation 1987
42
43 All Rights Reserved
44
45Permission to use, copy, modify, and distribute this software and its
46documentation for any purpose and without fee is hereby granted,
47provided that the above copyright notice appear in all copies and that
48both that copyright notice and this permission notice appear in
49supporting documentation, and that the name of IBM not be
50used in advertising or publicity pertaining to distribution of the
51software without specific, written prior permission.
52
53IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
54ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
55IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
56ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
57WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
58ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
59SOFTWARE.
60
61*******************************************************************************/
62
63/*
64 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
65 */
66
67#include <sys/param.h>
68#include <sys/mbuf.h>
69#include <sys/time.h>
70#include <sys/domain.h>
71#include <sys/protosw.h>
72#include <sys/socket.h>
73#include <sys/socketvar.h>
74#include <errno.h>
75#include <net/if.h>
76#include <net/route.h>
77#include <netiso/iso.h>
78#include <netiso/iso_errno.h>
79#include <netiso/clnp.h>
80#include <netiso/esis.h>
81#include <netiso/clnp_stat.h>
82#include <netiso/argo_debug.h>
83#undef satosiso
84#include <netiso/tp_param.h>
85#include <netiso/tp_states.h>
ad0448d8 86#include "tp_astring.c"
15637ed4
RG
87#include <netiso/tp_pcb.h>
88#include <netiso/tp_stat.h>
89#include <netiso/iso_pcb.h>
90#include <netiso/cltp_var.h>
91#include <netiso/cons.h>
92#ifdef IncStat
93#undef IncStat
94#endif
95#include <netiso/cons_pcb.h>
96#include <netdb.h>
97
98
99/*
100 * Dump esis stats
101 */
102esis_stats(off, name)
103 off_t off;
104 char *name;
105{
106 struct esis_stat esis_stat;
107
108 if (off == 0)
109 return;
110 kvm_read(off, (char *)&esis_stat, sizeof (struct esis_stat));
111 printf("%s:\n", name);
112 printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent,
113 esis_stat.es_eshrcvd);
114 printf("\t%d ish sent, %d ish received\n", esis_stat.es_ishsent,
115 esis_stat.es_ishrcvd);
116 printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,
117 esis_stat.es_rdrcvd);
118 printf("\t%d pdus not sent due to insufficient memory\n",
119 esis_stat.es_nomem);
120 printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum);
121 printf("\t%d pdus received with bad version number\n",
122 esis_stat.es_badvers);
123 printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype);
124 printf("\t%d short pdus received\n", esis_stat.es_toosmall);
125}
126
127/*
128 * Dump clnp statistics structure.
129 */
130clnp_stats(off, name)
131 off_t off;
132 char *name;
133{
134 struct clnp_stat clnp_stat;
135
136 if (off == 0)
137 return;
138 kvm_read(off, (char *)&clnp_stat, sizeof (clnp_stat));
139
140 printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent);
141 printf("\t%d total fragments sent\n", clnp_stat.cns_fragments);
142 printf("\t%d total packets received\n", clnp_stat.cns_total);
143 printf("\t%d with fixed part of header too small\n",
144 clnp_stat.cns_toosmall);
145 printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);
146 printf("\t%d incorrect checksum%s\n",
147 clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));
148 printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);
149 printf("\t%d with forgotten segmentation information\n",
150 clnp_stat.cns_noseg);
151 printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto);
152 printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers);
153 printf("\t%d dropped because the ttl has expired\n",
154 clnp_stat.cns_ttlexpired);
155 printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);
156 printf("\t%d clnp congestion experience bits set\n",
157 clnp_stat.cns_congest_set);
158 printf("\t%d clnp congestion experience bits received\n",
159 clnp_stat.cns_congest_rcvd);
160}
161/*
162 * Dump CLTP statistics structure.
163 */
164cltp_stats(off, name)
165 off_t off;
166 char *name;
167{
168 struct cltpstat cltpstat;
169
170 if (off == 0)
171 return;
172 kvm_read(off, (char *)&cltpstat, sizeof (cltpstat));
173 printf("%s:\n\t%u incomplete header%s\n", name,
174 cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops));
175 printf("\t%u bad data length field%s\n",
176 cltpstat.cltps_badlen, plural(cltpstat.cltps_badlen));
177 printf("\t%u bad checksum%s\n",
178 cltpstat.cltps_badsum, plural(cltpstat.cltps_badsum));
179}
180
181struct tp_pcb tpcb;
182struct isopcb isopcb;
183struct socket sockb;
184union {
185struct sockaddr_iso siso;
186char data[128];
187} laddr, faddr;
188#define kget(o, p) \
189 (kvm_read((off_t)(o), (char *)&p, sizeof (p)))
190extern int Aflag;
191extern int aflag;
192extern int nflag;
193
194static int first = 1;
195
196/*
197 * Print a summary of connections related to an Internet
198 * protocol. For TP, also give state of connection.
199 * Listening processes (aflag) are suppressed unless the
200 * -a (all) flag is specified.
201 */
202iso_protopr(off, name)
203 off_t off;
204 char *name;
205{
206 struct isopcb cb;
207 register struct isopcb *prev, *next;
208 int istp = (strcmp(name, "tp") == 0);
209
210 if (off == 0) {
10948f21 211 /*
15637ed4 212 printf("%s control block: symbol not in namelist\n", name);
10948f21 213 */
15637ed4
RG
214 return;
215 }
216 kget(off, cb);
217 isopcb = cb;
218 prev = (struct isopcb *)off;
219 if (isopcb.isop_next == (struct isopcb *)off)
220 return;
221 while (isopcb.isop_next != (struct isopcb *)off) {
222 next = isopcb.isop_next;
223 kget(next, isopcb);
224 if (isopcb.isop_prev != prev) {
225 printf("prev 0x%x next 0x%x isop_prev 0x%x isop_next 0x%x???\n",
226 prev, next, isopcb.isop_prev, isopcb.isop_next);
227 break;
228 }
229 kget(isopcb.isop_socket, sockb);
230 if (istp) {
231 kget(sockb.so_tpcb, tpcb);
232 if (tpcb.tp_state == ST_ERROR)
233 fprintf(stderr,"addr: 0x%x, prev 0x%x\n", next, prev);
234 if (!aflag &&
235 tpcb.tp_state == TP_LISTENING ||
236 tpcb.tp_state == TP_CLOSED ||
237 tpcb.tp_state == TP_REFWAIT) {
238 prev = next;
239 continue;
240 }
241 }
242 if (first) {
243 printf("Active ISO net connections");
244 if (aflag)
245 printf(" (including servers)");
246 putchar('\n');
247 if (Aflag)
248 printf("%-8.8s ", "PCB");
249 printf(Aflag ?
250 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
251 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
252 "Proto", "Recv-Q", "Send-Q",
253 "Local Address", "Foreign Address", "(state)");
254 first = 0;
255 }
256 if (Aflag)
257 printf("%8x ",
258 (istp ? (off_t)sockb.so_tpcb : (off_t)next));
259 printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
260 sockb.so_snd.sb_cc);
261 if (isopcb.isop_laddr == 0)
262 printf("*.*\t");
263 else {
264 if ((char *)isopcb.isop_laddr == ((char *)next) +
265 _offsetof(struct isopcb, isop_sladdr))
266 laddr.siso = isopcb.isop_sladdr;
267 else
268 kget(isopcb.isop_laddr, laddr);
269 isonetprint(&laddr, 1);
270 }
271 if (isopcb.isop_faddr == 0)
272 printf("*.*\t");
273 else {
274 if ((char *)isopcb.isop_faddr == ((char *)next) +
275 _offsetof(struct isopcb, isop_sfaddr))
276 faddr.siso = isopcb.isop_sfaddr;
277 else
278 kget(isopcb.isop_faddr, faddr);
279 isonetprint(&faddr, 0);
280 }
281 if (istp) {
282 if (tpcb.tp_state >= tp_NSTATES)
283 printf(" %d", tpcb.tp_state);
284 else
285 printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
286 }
287 putchar('\n');
288 prev = next;
289 }
290}
291
292/*
293 * Pretty print an iso address (net address + port).
294 * If the nflag was specified, use numbers instead of names.
295 */
296
297#ifdef notdef
298char *
299isonetname(iso)
300 register struct iso_addr *iso;
301{
302 struct sockaddr_iso sa;
303 struct iso_hostent *ihe = 0;
304 struct iso_hostent *iso_gethostentrybyaddr();
305 struct iso_hostent *iso_getserventrybytsel();
306 struct iso_hostent Ihe;
307 static char line[80];
308 char *index();
309
310 bzero(line, sizeof(line));
311 if( iso->isoa_afi ) {
312 sa.siso_family = AF_ISO;
313 sa.siso_addr = *iso;
314 sa.siso_tsuffix = 0;
315
316 if (!nflag )
317 ihe = iso_gethostentrybyaddr( &sa, 0, 0 );
318 if( ihe ) {
319 Ihe = *ihe;
320 ihe = &Ihe;
321 sprintf(line, "%s", ihe->isoh_hname);
322 } else {
323 sprintf(line, "%s", iso_ntoa(iso));
324 }
325 } else {
326 sprintf(line, "*");
327 }
328 return line;
329}
330
331isonetprint(iso, sufx, sufxlen, islocal)
332 register struct iso_addr *iso;
333 char *sufx;
334 u_short sufxlen;
335 int islocal;
336{
337 struct iso_hostent *iso_getserventrybytsel(), *ihe;
338 struct iso_hostent Ihe;
339 char *line, *cp, *index();
340 int Alen = Aflag?18:22;
341
342 line = isonetname(iso);
343 cp = index(line, '\0');
344 ihe = (struct iso_hostent *)0;
345
346 if( islocal )
347 islocal = 20;
348 else
349 islocal = 22 + Alen;
350
351 if(Aflag)
352 islocal += 10 ;
353
354 if(!nflag) {
355 if( (cp -line)>10 ) {
356 cp = line+10;
357 bzero(cp, sizeof(line)-10);
358 }
359 }
360
361 *cp++ = '.';
362 if(sufxlen) {
363 if( !Aflag && !nflag && (ihe=iso_getserventrybytsel(sufx, sufxlen))) {
364 Ihe = *ihe;
365 ihe = &Ihe;
366 }
367 if( ihe && (strlen(ihe->isoh_aname)>0) ) {
368 sprintf(cp, "%s", ihe->isoh_aname);
369 } else {
370 iso_sprinttsel(cp, sufx, sufxlen);
371 }
372 } else
373 sprintf(cp, "*");
374 /*
375 fprintf(stdout, Aflag?" %-18.18s":" %-22.22s", line);
376 */
377
378 if( strlen(line) > Alen ) {
379 fprintf(stdout, " %s", line);
380 fprintf(stdout, "\n %*.s", islocal+Alen," ");
381 } else {
382 fprintf(stdout, " %-*.*s", Alen, Alen,line);
383 }
384}
385#endif
386
387#ifdef notdef
388x25_protopr(off, name)
389 off_t off;
390 char *name;
391{
392 static char *xpcb_states[] = {
393 "CLOSED",
394 "LISTENING",
395 "CLOSING",
396 "CONNECTING",
397 "ACKWAIT",
398 "OPEN",
399 };
400 register struct isopcb *prev, *next;
401 struct x25_pcb xpcb;
402
403 if (off == 0) {
10948f21 404 /*
15637ed4 405 printf("%s control block: symbol not in namelist\n", name);
10948f21 406 */
15637ed4
RG
407 return;
408 }
409 kvm_read(off, &xpcb, sizeof (struct x25_pcb));
410 prev = (struct isopcb *)off;
411 if (xpcb.x_next == (struct isopcb *)off)
412 return;
413 while (xpcb.x_next != (struct isopcb *)off) {
414 next = isopcb.isop_next;
415 kvm_read((off_t)next, &xpcb, sizeof (struct x25_pcb));
416 if (xpcb.x_prev != prev) {
417 printf("???\n");
418 break;
419 }
420 kvm_read((off_t)xpcb.x_socket, &sockb, sizeof (sockb));
421
422 if (!aflag &&
423 xpcb.x_state == LISTENING ||
424 xpcb.x_state == TP_CLOSED ) {
425 prev = next;
426 continue;
427 }
428 if (first) {
429 printf("Active X25 net connections");
430 if (aflag)
431 printf(" (including servers)");
432 putchar('\n');
433 if (Aflag)
434 printf("%-8.8s ", "PCB");
435 printf(Aflag ?
436 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
437 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
438 "Proto", "Recv-Q", "Send-Q",
439 "Local Address", "Foreign Address", "(state)");
440 first = 0;
441 }
442 printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
443 sockb.so_snd.sb_cc);
444 isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport,
445 sizeof(xpcb.x_lport), 1);
446 isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport,
447 sizeof(xpcb.x_lport), 0);
448 if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES)
449 printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state);
450 else
451 printf(" %-12.12s", xpcb_states[xpcb.x_state]);
452 putchar('\n');
453 prev = next;
454 }
455}
456#endif
457
458struct tp_stat tp_stat;
459
460tp_stats(off, name)
461caddr_t off, name;
462{
463 if (off == 0) {
464 printf("TP not configured\n\n");
465 return;
466 }
467 printf("%s:\n", name);
468 kget(off, tp_stat);
469 tprintstat(&tp_stat, 8);
470}
471
472#define OUT stdout
473
474#define plural(x) (x>1?"s":"")
475
476tprintstat(s, indent)
477register struct tp_stat *s;
478int indent;
479{
480 fprintf(OUT,
481 "%*sReceiving:\n",indent," ");
482 fprintf(OUT,
483 "\t%*s%d variable parameter%s ignored\n", indent," ",
484 s->ts_param_ignored ,plural(s->ts_param_ignored));
485 fprintf(OUT,
486 "\t%*s%d invalid parameter code%s\n", indent, " ",
487 s->ts_inv_pcode ,plural(s->ts_inv_pcode));
488 fprintf(OUT,
489 "\t%*s%d invalid parameter value%s\n", indent, " ",
490 s->ts_inv_pval ,plural(s->ts_inv_pval));
491 fprintf(OUT,
492 "\t%*s%d invalid dutype%s\n", indent, " ",
493 s->ts_inv_dutype ,plural(s->ts_inv_dutype));
494 fprintf(OUT,
495 "\t%*s%d negotiation failure%s\n", indent, " ",
496 s->ts_negotfailed ,plural(s->ts_negotfailed));
497 fprintf(OUT,
498 "\t%*s%d invalid destination reference%s\n", indent, " ",
499 s->ts_inv_dref ,plural(s->ts_inv_dref));
500 fprintf(OUT,
501 "\t%*s%d invalid suffix parameter%s\n", indent, " ",
502 s->ts_inv_sufx ,plural(s->ts_inv_sufx));
503 fprintf(OUT,
504 "\t%*s%d invalid length\n",indent, " ", s->ts_inv_length);
505 fprintf(OUT,
506 "\t%*s%d invalid checksum%s\n", indent, " ",
507 s->ts_bad_csum ,plural(s->ts_bad_csum));
508 fprintf(OUT,
509 "\t%*s%d DT%s out of order\n", indent, " ",
510 s->ts_dt_ooo ,plural(s->ts_dt_ooo));
511 fprintf(OUT,
512 "\t%*s%d DT%s not in window\n", indent, " ",
513 s->ts_dt_niw ,plural(s->ts_dt_niw));
514 fprintf(OUT,
515 "\t%*s%d duplicate DT%s\n", indent, " ",
516 s->ts_dt_dup ,plural(s->ts_dt_dup));
517 fprintf(OUT,
518 "\t%*s%d XPD%s not in window\n", indent, " ",
519 s->ts_xpd_niw ,plural(s->ts_xpd_niw));
520 fprintf(OUT,
521 "\t%*s%d XPD%s w/o credit to stash\n", indent, " ",
522 s->ts_xpd_dup ,plural(s->ts_xpd_dup));
523 fprintf(OUT,
524 "\t%*s%d time%s local credit reneged\n", indent, " ",
525 s->ts_lcdt_reduced ,plural(s->ts_lcdt_reduced));
526 fprintf(OUT,
527 "\t%*s%d concatenated TPDU%s\n", indent, " ",
528 s->ts_concat_rcvd ,plural(s->ts_concat_rcvd));
529 fprintf(OUT,
530 "%*sSending:\n", indent, " ");
531 fprintf(OUT,
532 "\t%*s%d XPD mark%s discarded\n", indent, " ",
533 s->ts_xpdmark_del ,plural(s->ts_xpdmark_del));
534 fprintf(OUT,
535 "\t%*sXPD stopped data flow %d time%s\n", indent, " ",
536 s->ts_xpd_intheway ,plural(s->ts_xpd_intheway));
537 fprintf(OUT,
538 "\t%*s%d time%s foreign window closed\n", indent, " ",
539 s->ts_zfcdt ,plural(s->ts_zfcdt));
540 fprintf(OUT,
541 "%*sMiscellaneous:\n", indent, " ");
542 fprintf(OUT,
543 "\t%*s%d small mbuf%s\n", indent, " ",
544 s->ts_mb_small ,plural(s->ts_mb_small));
545 fprintf(OUT,
546 "\t%*s%d cluster%s\n", indent, " ",
547 s->ts_mb_cluster, plural(s->ts_mb_cluster));
548 fprintf(OUT,
549 "\t%*s%d source quench \n",indent, " ",
550 s->ts_quench);
551 fprintf(OUT,
552 "\t%*s%d dec bit%s\n", indent, " ",
553 s->ts_rcvdecbit, plural(s->ts_rcvdecbit));
554 fprintf(OUT,
555 "\t%*sM:L ( M mbuf chains of length L)\n", indent, " ");
556 {
557 register int j;
558
559 fprintf(OUT, "\t%*s%d: over 16\n", indent, " ",
560 s->ts_mb_len_distr[0]);
561 for( j=1; j<=8; j++) {
562 fprintf(OUT,
563 "\t%*s%d: %d\t\t%d: %d\n", indent, " ",
564 s->ts_mb_len_distr[j],j,
565 s->ts_mb_len_distr[j<<1],j<<1
566 );
567 }
568 }
569 fprintf(OUT,
570 "\t%*s%d EOT rcvd\n", indent, " ", s->ts_eot_input);
571 fprintf(OUT,
572 "\t%*s%d EOT sent\n", indent, " ", s->ts_EOT_sent);
573 fprintf(OUT,
574 "\t%*s%d EOT indication%s\n", indent, " ",
575 s->ts_eot_user ,plural(s->ts_eot_user));
576
577 fprintf(OUT,
578 "%*sConnections:\n", indent, " ");
579 fprintf(OUT,
580 "\t%*s%d connection%s used extended format\n", indent, " ",
581 s->ts_xtd_fmt ,plural(s->ts_xtd_fmt));
582 fprintf(OUT,
583 "\t%*s%d connection%s allowed transport expedited data\n", indent, " ",
584 s->ts_use_txpd ,plural(s->ts_use_txpd));
585 fprintf(OUT,
586 "\t%*s%d connection%s turned off checksumming\n", indent, " ",
587 s->ts_csum_off ,plural(s->ts_csum_off));
588 fprintf(OUT,
589 "\t%*s%d connection%s dropped due to retrans limit\n", indent, " ",
590 s->ts_conn_gaveup ,plural(s->ts_conn_gaveup));
591 fprintf(OUT,
592 "\t%*s%d tp 4 connection%s\n", indent, " ",
593 s->ts_tp4_conn ,plural(s->ts_tp4_conn));
594 fprintf(OUT,
595 "\t%*s%d tp 0 connection%s\n", indent, " ",
596 s->ts_tp0_conn ,plural(s->ts_tp0_conn));
597 {
598 register int j, div;
599 register float f;
600 static char *name[]= {
601 "~LOCAL, PDN",
602 "~LOCAL,~PDN",
603 " LOCAL,~PDN",
604 " LOCAL, PDN"
605 };
606#define factor(i) \
607 div = (s->ts_rtt[(i)].tv_sec * 1000000) + \
608 s->ts_rtt[(i)].tv_usec ;\
609 if(div) {\
610 f = ((s->ts_rtv[(i)].tv_sec * 1000000) + \
611 s->ts_rtv[(i)].tv_usec)/div; \
612 div = (int) (f + 0.5);\
613 }
614
615 fprintf(OUT,
616 "\n%*sRound trip times, listed in (sec: usec):\n", indent, " ");
617 fprintf(OUT,
618 "\t%*s%11.11s %12.12s | %12.12s | %s\n", indent, " ",
619 "Category",
620 "Smoothed avg", "Deviation", "Deviation/Avg");
621 for( j=0; j<=3; j++) {
622 factor(j);
623 fprintf(OUT,
624 "\t%*s%11.11s: %5d:%-6d | %5d:%-6d | %-6d\n", indent, " ",
625 name[j],
626 s->ts_rtt[j].tv_sec,
627 s->ts_rtt[j].tv_usec,
628 s->ts_rtv[j].tv_sec,
629 s->ts_rtv[j].tv_usec,
630 div);
631 }
632 }
633 fprintf(OUT,
634"\n%*sTpdus RECVD [%d valid, %3.6f %% of total (%d); %d dropped]\n",indent," ",
635 s->ts_tpdu_rcvd ,
636 ((s->ts_pkt_rcvd > 0) ?
637 ((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd)
638 : 0),
639 s->ts_pkt_rcvd,
640 s->ts_recv_drop );
641
642 fprintf(OUT,
643 "\t%*sDT %6d AK %6d DR %4d CR %4d \n", indent, " ",
644 s->ts_DT_rcvd, s->ts_AK_rcvd, s->ts_DR_rcvd, s->ts_CR_rcvd);
645 fprintf(OUT,
646 "\t%*sXPD %6d XAK %6d DC %4d CC %4d ER %4d\n", indent, " ",
647 s->ts_XPD_rcvd, s->ts_XAK_rcvd, s->ts_DC_rcvd, s->ts_CC_rcvd,
648 s->ts_ER_rcvd);
649 fprintf(OUT,
650 "\n%*sTpdus SENT [%d total, %d dropped]\n", indent, " ",
651 s->ts_tpdu_sent, s->ts_send_drop);
652
653 fprintf(OUT,
654 "\t%*sDT %6d AK %6d DR %4d CR %4d \n", indent, " ",
655 s->ts_DT_sent, s->ts_AK_sent, s->ts_DR_sent, s->ts_CR_sent);
656 fprintf(OUT,
657 "\t%*sXPD %6d XAK %6d DC %4d CC %4d ER %4d\n", indent, " ",
658 s->ts_XPD_sent, s->ts_XAK_sent, s->ts_DC_sent, s->ts_CC_sent,
659 s->ts_ER_sent);
660
661 fprintf(OUT,
662 "\n%*sRetransmissions:\n", indent, " ");
663#define PERCENT(X,Y) (((Y)>0)?((100 *(float)(X)) / (float) (Y)):0)
664
665 fprintf(OUT,
666 "\t%*sCR %6d CC %6d DR %6d \n", indent, " ",
667 s->ts_retrans_cr, s->ts_retrans_cc, s->ts_retrans_dr);
668 fprintf(OUT,
669 "\t%*sDT %6d (%5.2f%%)\n", indent, " ",
670 s->ts_retrans_dt,
671 PERCENT(s->ts_retrans_dt, s->ts_DT_sent));
672 fprintf(OUT,
673 "\t%*sXPD %6d (%5.2f%%)\n", indent, " ",
674 s->ts_retrans_xpd,
675 PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent));
676
677
678 fprintf(OUT,
679 "\n%*sE Timers: [%6d ticks]\n", indent, " ", s->ts_Eticks);
680 fprintf(OUT,
681 "%*s%6d timer%s set \t%6d timer%s expired \t%6d timer%s cancelled\n",indent, " ",
682 s->ts_Eset ,plural(s->ts_Eset),
683 s->ts_Eexpired ,plural(s->ts_Eexpired),
684 s->ts_Ecan_act ,plural(s->ts_Ecan_act));
685
686 fprintf(OUT,
687 "\n%*sC Timers: [%6d ticks]\n", indent, " ",s->ts_Cticks);
688 fprintf(OUT,
689 "%*s%6d timer%s set \t%6d timer%s expired \t%6d timer%s cancelled\n",
690 indent, " ",
691 s->ts_Cset ,plural(s->ts_Cset),
692 s->ts_Cexpired ,plural(s->ts_Cexpired),
693 s->ts_Ccan_act ,plural(s->ts_Ccan_act));
694 fprintf(OUT,
695 "%*s%6d inactive timer%s cancelled\n", indent, " ",
696 s->ts_Ccan_inact ,plural(s->ts_Ccan_inact));
697
698 fprintf(OUT,
699 "\n%*sPathological debugging activity:\n", indent, " ");
700 fprintf(OUT,
701 "\t%*s%6d CC%s sent to zero dref\n", indent, " ",
702 s->ts_zdebug ,plural(s->ts_zdebug));
703 /* SAME LINE AS ABOVE */
704 fprintf(OUT,
705 "\t%*s%6d random DT%s dropped\n", indent, " ",
706 s->ts_ydebug ,plural(s->ts_ydebug));
707 fprintf(OUT,
708 "\t%*s%6d illegally large XPD TPDU%s\n", indent, " ",
709 s->ts_vdebug ,plural(s->ts_vdebug));
710 fprintf(OUT,
711 "\t%*s%6d faked reneging of cdt\n", indent, " ",
712 s->ts_ldebug );
713
714 fprintf(OUT,
715 "\n%*sACK reasons:\n", indent, " ");
716 fprintf(OUT, "\t%*s%6d not acked immediately\n", indent, " ",
717 s->ts_ackreason[_ACK_DONT_] );
718 fprintf(OUT, "\t%*s%6d strategy==each\n", indent, " ",
719 s->ts_ackreason[_ACK_STRAT_EACH_] );
720 fprintf(OUT, "\t%*s%6d strategy==fullwindow\n", indent, " ",
721 s->ts_ackreason[_ACK_STRAT_FULLWIN_] );
722 fprintf(OUT, "\t%*s%6d duplicate DT\n", indent, " ",
723 s->ts_ackreason[_ACK_DUP_] );
724 fprintf(OUT, "\t%*s%6d EOTSDU\n", indent, " ",
725 s->ts_ackreason[_ACK_EOT_] );
726 fprintf(OUT, "\t%*s%6d reordered DT\n", indent, " ",
727 s->ts_ackreason[_ACK_REORDER_] );
728 fprintf(OUT, "\t%*s%6d user rcvd\n", indent, " ",
729 s->ts_ackreason[_ACK_USRRCV_] );
730 fprintf(OUT, "\t%*s%6d fcc reqd\n", indent, " ",
731 s->ts_ackreason[_ACK_FCC_] );
732}
733#ifndef SSEL
734#define SSEL(s) ((s)->siso_tlen + TSEL(s))
735#define PSEL(s) ((s)->siso_slen + SSEL(s))
736#endif
737
738isonetprint(siso, islocal)
739register struct sockaddr_iso *siso;
740int islocal;
741{
742 hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}");
743 if (siso->siso_tlen || siso->siso_slen || siso->siso_plen)
744 hexprint(siso->siso_tlen, TSEL(siso), "()");
745 if (siso->siso_slen || siso->siso_plen)
746 hexprint(siso->siso_slen, SSEL(siso), "[]");
747 if (siso->siso_plen)
748 hexprint(siso->siso_plen, PSEL(siso), "<>");
749 putchar(' ');
750}
751static char hexlist[] = "0123456789abcdef", obuf[128];
752
753hexprint(n, buf, delim)
754char *buf, *delim;
755{
756 register u_char *in = (u_char *)buf, *top = in + n;
757 register char *out = obuf;
758 register int i;
759
760 if (n == 0)
761 return;
762 while (in < top) {
763 i = *in++;
764 *out++ = '.';
765 if (i > 0xf) {
766 out[1] = hexlist[i & 0xf];
767 i >>= 4;
768 out[0] = hexlist[i];
769 out += 2;
770 } else
771 *out++ = hexlist[i];
772 }
773 *obuf = *delim; *out++ = delim[1]; *out = 0;
774 printf("%s", obuf);
775}