Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / common / C / netstat / iso.c
blobbb7a321b6be88d5dbca0626933046450e9294d93
1 /*
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2006
5 * Pavel Fedin
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 /* "@(#)iso.c 8.1 (Berkeley) 6/6/93" */
39 * $Header: /cvsroot/unmorphos/ezTCP/C/netstat/iso.c,v 1.3 2006/12/15 08:45:21 sonic_amiga Exp $
40 * $Source: /cvsroot/unmorphos/ezTCP/C/netstat/iso.c,v $
42 /*******************************************************************************
43 Copyright IBM Corporation 1987
45 All Rights Reserved
47 Permission to use, copy, modify, and distribute this software and its
48 documentation for any purpose and without fee is hereby granted,
49 provided that the above copyright notice appear in all copies and that
50 both that copyright notice and this permission notice appear in
51 supporting documentation, and that the name of IBM not be
52 used in advertising or publicity pertaining to distribution of the
53 software without specific, written prior permission.
55 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
56 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
57 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
58 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
59 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
60 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
61 SOFTWARE.
63 *******************************************************************************/
66 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
69 #ifdef ISO
70 #include <sys/param.h>
71 #include <sys/mbuf.h>
72 #include <sys/time.h>
73 #include <sys/domain.h>
74 #include <sys/protosw.h>
75 #include <sys/socket.h>
76 #include <sys/socketvar.h>
77 #include <sys/queue.h>
78 #include <errno.h>
79 #include <net/if.h>
80 #include <net/route.h>
81 #include <netinet/in.h>
82 #include <netinet/in_systm.h>
83 #include <netinet/ip.h>
84 #include <netinet/in_pcb.h>
85 #include <netinet/ip_var.h>
86 #include <netiso/iso.h>
87 #include <netiso/iso_errno.h>
88 #include <netiso/clnp.h>
89 #include <netiso/esis.h>
90 #include <netiso/clnp_stat.h>
91 #include <netiso/argo_debug.h>
92 #undef satosiso
93 #include <netiso/tp_param.h>
94 #include <netiso/tp_states.h>
95 #include <netiso/tp_pcb.h>
96 #include <netiso/tp_stat.h>
97 #include <netiso/iso_pcb.h>
98 #include <netiso/cltp_var.h>
99 #include <netiso/cons.h>
100 #ifdef IncStat
101 #undef IncStat
102 #endif
103 #include <netiso/cons_pcb.h>
104 #include <arpa/inet.h>
105 #include <netdb.h>
106 #include <string.h>
107 #include <stdio.h>
108 #include <stdlib.h>
109 #include "netstat.h"
111 static void tprintstat __P((struct tp_stat *, int));
112 static void isonetprint __P((struct sockaddr_iso *, int));
113 static void hexprint __P((int, char *, char *));
114 extern void inetprint __P((struct in_addr *, int, char *));
117 * Dump esis stats
119 void
120 esis_stats(off, name)
121 u_long off;
122 char *name;
124 struct esis_stat esis_stat;
126 if (off == 0 ||
127 kread(off, (char *)&esis_stat, sizeof (struct esis_stat)))
128 return;
129 printf("%s:\n", name);
130 printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent,
131 esis_stat.es_eshrcvd);
132 printf("\t%d ish sent, %d ish received\n", esis_stat.es_ishsent,
133 esis_stat.es_ishrcvd);
134 printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,
135 esis_stat.es_rdrcvd);
136 printf("\t%d pdus not sent due to insufficient memory\n",
137 esis_stat.es_nomem);
138 printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum);
139 printf("\t%d pdus received with bad version number\n",
140 esis_stat.es_badvers);
141 printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype);
142 printf("\t%d short pdus received\n", esis_stat.es_toosmall);
146 * Dump clnp statistics structure.
148 void
149 clnp_stats(off, name)
150 u_long off;
151 char *name;
153 struct clnp_stat clnp_stat;
155 if (off == 0 ||
156 kread(off, (char *)&clnp_stat, sizeof (clnp_stat)))
157 return;
159 printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent);
160 printf("\t%d total fragments sent\n", clnp_stat.cns_fragments);
161 printf("\t%d total packets received\n", clnp_stat.cns_total);
162 printf("\t%d with fixed part of header too small\n",
163 clnp_stat.cns_toosmall);
164 printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);
165 printf("\t%d incorrect checksum%s\n",
166 clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));
167 printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);
168 printf("\t%d with forgotten segmentation information\n",
169 clnp_stat.cns_noseg);
170 printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto);
171 printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers);
172 printf("\t%d dropped because the ttl has expired\n",
173 clnp_stat.cns_ttlexpired);
174 printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);
175 printf("\t%d clnp congestion experience bits set\n",
176 clnp_stat.cns_congest_set);
177 printf("\t%d clnp congestion experience bits received\n",
178 clnp_stat.cns_congest_rcvd);
181 * Dump CLTP statistics structure.
183 void
184 cltp_stats(off, name)
185 u_long off;
186 char *name;
188 struct cltpstat cltpstat;
190 if (off == 0 ||
191 kread(off, (char *)&cltpstat, sizeof (cltpstat)))
192 return;
193 printf("%s:\n\t%u incomplete header%s\n", name,
194 cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops));
195 printf("\t%u bad data length field%s\n",
196 cltpstat.cltps_badlen, plural(cltpstat.cltps_badlen));
197 printf("\t%u bad checksum%s\n",
198 cltpstat.cltps_badsum, plural(cltpstat.cltps_badsum));
201 struct tp_pcb tpcb;
202 struct isopcb isopcb;
203 struct socket sockb;
204 union {
205 struct sockaddr_iso siso;
206 char data[128];
207 } laddr, faddr;
208 #define kget(o, p) \
209 (kread((u_long)(o), (char *)&p, sizeof (p)))
211 static int first = 1;
214 * Print a summary of connections related to an Internet
215 * protocol. For TP, also give state of connection.
216 * Listening processes (aflag) are suppressed unless the
217 * -a (all) flag is specified.
219 void
220 iso_protopr(off, name)
221 u_long off;
222 char *name;
224 struct isopcb cb;
225 register struct isopcb *prev, *next;
227 if (off == 0) {
228 printf("%s control block: symbol not in namelist\n", name);
229 return;
231 if (strcmp(name, "tp") == 0) {
232 tp_protopr(off, name);
233 return;
235 if (kread(off, (char *)&cb, sizeof(cb)))
236 return;
237 isopcb = cb;
238 prev = (struct isopcb *)off;
239 if (isopcb.isop_next == (struct isopcb *)off)
240 return;
241 while (isopcb.isop_next != (struct isopcb *)off) {
242 next = isopcb.isop_next;
243 kget(next, isopcb);
244 if (isopcb.isop_prev != prev) {
245 printf("prev 0x%x next 0x%x isop_prev 0x%x isop_next 0x%x???\n",
246 prev, next, isopcb.isop_prev, isopcb.isop_next);
247 break;
249 kget(isopcb.isop_socket, sockb);
250 iso_protopr1((u_long)next, 0);
251 putchar('\n');
252 prev = next;
256 void
257 iso_protopr1(kern_addr, istp)
258 u_long kern_addr;
259 int istp;
261 if (first) {
262 printf("Active ISO net connections");
263 if (aflag)
264 printf(" (including servers)");
265 putchar('\n');
266 if (Aflag)
267 printf("%-8.8s ", "PCB");
268 printf(Aflag ?
269 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
270 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
271 "Proto", "Recv-Q", "Send-Q",
272 "Local Address", "Foreign Address", "(state)");
273 first = 0;
275 if (Aflag)
276 printf("%8x ",
277 (sockb.so_pcb ? (void *)sockb.so_pcb : (void *)kern_addr));
278 printf("%-5.5s %6d %6d ", "tp", sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
279 if (istp && tpcb.tp_lsuffixlen) {
280 hexprint(tpcb.tp_lsuffixlen, tpcb.tp_lsuffix, "()");
281 printf("\t");
282 } else if (isopcb.isop_laddr == 0)
283 printf("*.*\t");
284 else {
285 if ((char *)isopcb.isop_laddr == ((char *)kern_addr) +
286 _offsetof(struct isopcb, isop_sladdr))
287 laddr.siso = isopcb.isop_sladdr;
288 else
289 kget(isopcb.isop_laddr, laddr);
290 isonetprint((struct sockaddr_iso *)&laddr, 1);
292 if (istp && tpcb.tp_fsuffixlen) {
293 hexprint(tpcb.tp_fsuffixlen, tpcb.tp_fsuffix, "()");
294 printf("\t");
295 } else if (isopcb.isop_faddr == 0)
296 printf("*.*\t");
297 else {
298 if ((char *)isopcb.isop_faddr == ((char *)kern_addr) +
299 _offsetof(struct isopcb, isop_sfaddr))
300 faddr.siso = isopcb.isop_sfaddr;
301 else
302 kget(isopcb.isop_faddr, faddr);
303 isonetprint((struct sockaddr_iso *)&faddr, 0);
307 void
308 tp_protopr(off, name)
309 u_long off;
310 char *name;
312 extern char *tp_sstring[];
313 struct tp_ref *tpr, *tpr_base;
314 struct tp_refinfo tpkerninfo;
315 int size;
317 kget(off, tpkerninfo);
318 size = tpkerninfo.tpr_size * sizeof (*tpr);
319 tpr_base = (struct tp_ref *)malloc(size);
320 if (tpr_base == 0)
321 return;
322 kread((u_long)(tpkerninfo.tpr_base), (char *)tpr_base, size);
323 for (tpr = tpr_base; tpr < tpr_base + tpkerninfo.tpr_size; tpr++) {
324 if (tpr->tpr_pcb == 0)
325 continue;
326 kget(tpr->tpr_pcb, tpcb);
327 if (tpcb.tp_state == ST_ERROR)
328 printf("undefined tpcb state: 0x%x\n", tpr->tpr_pcb);
329 if (!aflag &&
330 (tpcb.tp_state == TP_LISTENING ||
331 tpcb.tp_state == TP_CLOSED ||
332 tpcb.tp_state == TP_REFWAIT)) {
333 continue;
335 kget(tpcb.tp_sock, sockb);
336 if (tpcb.tp_npcb) switch(tpcb.tp_netservice) {
337 case IN_CLNS:
338 tp_inproto((u_long)tpkerninfo.tpr_base);
339 break;
340 default:
341 kget(tpcb.tp_npcb, isopcb);
342 iso_protopr1((u_long)tpcb.tp_npcb, 1);
343 break;
345 if (tpcb.tp_state >= tp_NSTATES)
346 printf(" %d", tpcb.tp_state);
347 else
348 printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
349 putchar('\n');
353 void
354 tp_inproto(pcb)
355 u_long pcb;
357 struct inpcb inpcb;
358 kget(tpcb.tp_npcb, inpcb);
359 if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
360 return;
361 if (Aflag)
362 printf("%8x ", pcb);
363 printf("%-5.5s %6d %6d ", "tpip",
364 sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
365 inetprint(&inpcb.inp_laddr, inpcb.inp_lport, "tp");
366 inetprint(&inpcb.inp_faddr, inpcb.inp_fport, "tp");
370 * Pretty print an iso address (net address + port).
371 * If the nflag was specified, use numbers instead of names.
374 #ifdef notdef
375 char *
376 isonetname(iso)
377 register struct iso_addr *iso;
379 struct sockaddr_iso sa;
380 struct iso_hostent *ihe = 0;
381 struct iso_hostent *iso_gethostentrybyaddr();
382 struct iso_hostent *iso_getserventrybytsel();
383 struct iso_hostent Ihe;
384 static char line[80];
386 bzero(line, sizeof(line));
387 if( iso->isoa_afi ) {
388 sa.siso_family = AF_ISO;
389 sa.siso_addr = *iso;
390 sa.siso_tsuffix = 0;
392 if (!nflag )
393 ihe = iso_gethostentrybyaddr( &sa, 0, 0 );
394 if( ihe ) {
395 Ihe = *ihe;
396 ihe = &Ihe;
397 sprintf(line, "%s", ihe->isoh_hname);
398 } else {
399 sprintf(line, "%s", iso_ntoa(iso));
401 } else {
402 sprintf(line, "*");
404 return line;
407 static void
408 isonetprint(iso, sufx, sufxlen, islocal)
409 register struct iso_addr *iso;
410 char *sufx;
411 u_short sufxlen;
412 int islocal;
414 struct iso_hostent *iso_getserventrybytsel(), *ihe;
415 struct iso_hostent Ihe;
416 char *line, *cp;
417 int Alen = Aflag?18:22;
419 line = isonetname(iso);
420 cp = index(line, '\0');
421 ihe = (struct iso_hostent *)0;
423 if( islocal )
424 islocal = 20;
425 else
426 islocal = 22 + Alen;
428 if(Aflag)
429 islocal += 10 ;
431 if(!nflag) {
432 if( (cp -line)>10 ) {
433 cp = line+10;
434 bzero(cp, sizeof(line)-10);
438 *cp++ = '.';
439 if(sufxlen) {
440 if( !Aflag && !nflag && (ihe=iso_getserventrybytsel(sufx, sufxlen))) {
441 Ihe = *ihe;
442 ihe = &Ihe;
444 if( ihe && (strlen(ihe->isoh_aname)>0) ) {
445 sprintf(cp, "%s", ihe->isoh_aname);
446 } else {
447 iso_sprinttsel(cp, sufx, sufxlen);
449 } else
450 sprintf(cp, "*");
452 fprintf(stdout, Aflag?" %-18.18s":" %-22.22s", line);
455 if( strlen(line) > Alen ) {
456 fprintf(stdout, " %s", line);
457 fprintf(stdout, "\n %*.s", islocal+Alen," ");
458 } else {
459 fprintf(stdout, " %-*.*s", Alen, Alen,line);
462 #endif
464 #ifdef notdef
465 static void
466 x25_protopr(off, name)
467 u_long off;
468 char *name;
470 static char *xpcb_states[] = {
471 "CLOSED",
472 "LISTENING",
473 "CLOSING",
474 "CONNECTING",
475 "ACKWAIT",
476 "OPEN",
478 register struct isopcb *prev, *next;
479 struct x25_pcb xpcb;
481 if (off == 0) {
482 printf("%s control block: symbol not in namelist\n", name);
483 return;
485 kread(off, &xpcb, sizeof (struct x25_pcb));
486 prev = (struct isopcb *)off;
487 if (xpcb.x_next == (struct isopcb *)off)
488 return;
489 while (xpcb.x_next != (struct isopcb *)off) {
490 next = isopcb.isop_next;
491 kread((u_long)next, &xpcb, sizeof (struct x25_pcb));
492 if (xpcb.x_prev != prev) {
493 printf("???\n");
494 break;
496 kread((u_long)xpcb.x_socket, &sockb, sizeof (sockb));
498 if (!aflag &&
499 xpcb.x_state == LISTENING ||
500 xpcb.x_state == TP_CLOSED ) {
501 prev = next;
502 continue;
504 if (first) {
505 printf("Active X25 net connections");
506 if (aflag)
507 printf(" (including servers)");
508 putchar('\n');
509 if (Aflag)
510 printf("%-8.8s ", "PCB");
511 printf(Aflag ?
512 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
513 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
514 "Proto", "Recv-Q", "Send-Q",
515 "Local Address", "Foreign Address", "(state)");
516 first = 0;
518 printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
519 sockb.so_snd.sb_cc);
520 isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport,
521 sizeof(xpcb.x_lport), 1);
522 isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport,
523 sizeof(xpcb.x_lport), 0);
524 if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES)
525 printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state);
526 else
527 printf(" %-12.12s", xpcb_states[xpcb.x_state]);
528 putchar('\n');
529 prev = next;
532 #endif
534 struct tp_stat tp_stat;
536 void
537 tp_stats(off, name)
538 caddr_t off, name;
540 if (off == 0) {
541 printf("TP not configured\n\n");
542 return;
544 printf("%s:\n", name);
545 kget(off, tp_stat);
546 tprintstat(&tp_stat, 8);
549 #define OUT stdout
551 static void
552 tprintstat(s, indent)
553 register struct tp_stat *s;
554 int indent;
556 fprintf(OUT,
557 "%*sReceiving:\n",indent," ");
558 fprintf(OUT,
559 "\t%*s%d variable parameter%s ignored\n", indent," ",
560 s->ts_param_ignored ,plural(s->ts_param_ignored));
561 fprintf(OUT,
562 "\t%*s%d invalid parameter code%s\n", indent, " ",
563 s->ts_inv_pcode ,plural(s->ts_inv_pcode));
564 fprintf(OUT,
565 "\t%*s%d invalid parameter value%s\n", indent, " ",
566 s->ts_inv_pval ,plural(s->ts_inv_pval));
567 fprintf(OUT,
568 "\t%*s%d invalid dutype%s\n", indent, " ",
569 s->ts_inv_dutype ,plural(s->ts_inv_dutype));
570 fprintf(OUT,
571 "\t%*s%d negotiation failure%s\n", indent, " ",
572 s->ts_negotfailed ,plural(s->ts_negotfailed));
573 fprintf(OUT,
574 "\t%*s%d invalid destination reference%s\n", indent, " ",
575 s->ts_inv_dref ,plural(s->ts_inv_dref));
576 fprintf(OUT,
577 "\t%*s%d invalid suffix parameter%s\n", indent, " ",
578 s->ts_inv_sufx ,plural(s->ts_inv_sufx));
579 fprintf(OUT,
580 "\t%*s%d invalid length\n",indent, " ", s->ts_inv_length);
581 fprintf(OUT,
582 "\t%*s%d invalid checksum%s\n", indent, " ",
583 s->ts_bad_csum ,plural(s->ts_bad_csum));
584 fprintf(OUT,
585 "\t%*s%d DT%s out of order\n", indent, " ",
586 s->ts_dt_ooo ,plural(s->ts_dt_ooo));
587 fprintf(OUT,
588 "\t%*s%d DT%s not in window\n", indent, " ",
589 s->ts_dt_niw ,plural(s->ts_dt_niw));
590 fprintf(OUT,
591 "\t%*s%d duplicate DT%s\n", indent, " ",
592 s->ts_dt_dup ,plural(s->ts_dt_dup));
593 fprintf(OUT,
594 "\t%*s%d XPD%s not in window\n", indent, " ",
595 s->ts_xpd_niw ,plural(s->ts_xpd_niw));
596 fprintf(OUT,
597 "\t%*s%d XPD%s w/o credit to stash\n", indent, " ",
598 s->ts_xpd_dup ,plural(s->ts_xpd_dup));
599 fprintf(OUT,
600 "\t%*s%d time%s local credit reneged\n", indent, " ",
601 s->ts_lcdt_reduced ,plural(s->ts_lcdt_reduced));
602 fprintf(OUT,
603 "\t%*s%d concatenated TPDU%s\n", indent, " ",
604 s->ts_concat_rcvd ,plural(s->ts_concat_rcvd));
605 fprintf(OUT,
606 "%*sSending:\n", indent, " ");
607 fprintf(OUT,
608 "\t%*s%d XPD mark%s discarded\n", indent, " ",
609 s->ts_xpdmark_del ,plural(s->ts_xpdmark_del));
610 fprintf(OUT,
611 "\t%*sXPD stopped data flow %d time%s\n", indent, " ",
612 s->ts_xpd_intheway ,plural(s->ts_xpd_intheway));
613 fprintf(OUT,
614 "\t%*s%d time%s foreign window closed\n", indent, " ",
615 s->ts_zfcdt ,plural(s->ts_zfcdt));
616 fprintf(OUT,
617 "%*sMiscellaneous:\n", indent, " ");
618 fprintf(OUT,
619 "\t%*s%d small mbuf%s\n", indent, " ",
620 s->ts_mb_small ,plural(s->ts_mb_small));
621 fprintf(OUT,
622 "\t%*s%d cluster%s\n", indent, " ",
623 s->ts_mb_cluster, plural(s->ts_mb_cluster));
624 fprintf(OUT,
625 "\t%*s%d source quench \n",indent, " ",
626 s->ts_quench);
627 fprintf(OUT,
628 "\t%*s%d dec bit%s\n", indent, " ",
629 s->ts_rcvdecbit, plural(s->ts_rcvdecbit));
630 fprintf(OUT,
631 "\t%*sM:L ( M mbuf chains of length L)\n", indent, " ");
633 register int j;
635 fprintf(OUT, "\t%*s%d: over 16\n", indent, " ",
636 s->ts_mb_len_distr[0]);
637 for( j=1; j<=8; j++) {
638 fprintf(OUT,
639 "\t%*s%d: %d\t\t%d: %d\n", indent, " ",
640 s->ts_mb_len_distr[j],j,
641 s->ts_mb_len_distr[j<<1],j<<1
645 fprintf(OUT,
646 "\t%*s%d EOT rcvd\n", indent, " ", s->ts_eot_input);
647 fprintf(OUT,
648 "\t%*s%d EOT sent\n", indent, " ", s->ts_EOT_sent);
649 fprintf(OUT,
650 "\t%*s%d EOT indication%s\n", indent, " ",
651 s->ts_eot_user ,plural(s->ts_eot_user));
653 fprintf(OUT,
654 "%*sConnections:\n", indent, " ");
655 fprintf(OUT,
656 "\t%*s%d connection%s used extended format\n", indent, " ",
657 s->ts_xtd_fmt ,plural(s->ts_xtd_fmt));
658 fprintf(OUT,
659 "\t%*s%d connection%s allowed transport expedited data\n", indent, " ",
660 s->ts_use_txpd ,plural(s->ts_use_txpd));
661 fprintf(OUT,
662 "\t%*s%d connection%s turned off checksumming\n", indent, " ",
663 s->ts_csum_off ,plural(s->ts_csum_off));
664 fprintf(OUT,
665 "\t%*s%d connection%s dropped due to retrans limit\n", indent, " ",
666 s->ts_conn_gaveup ,plural(s->ts_conn_gaveup));
667 fprintf(OUT,
668 "\t%*s%d tp 4 connection%s\n", indent, " ",
669 s->ts_tp4_conn ,plural(s->ts_tp4_conn));
670 fprintf(OUT,
671 "\t%*s%d tp 0 connection%s\n", indent, " ",
672 s->ts_tp0_conn ,plural(s->ts_tp0_conn));
674 register int j;
675 static char *name[]= {
676 "~LOCAL, PDN",
677 "~LOCAL,~PDN",
678 " LOCAL,~PDN",
679 " LOCAL, PDN"
682 fprintf(OUT,
683 "\n%*sRound trip times, listed in ticks:\n", indent, " ");
684 fprintf(OUT,
685 "\t%*s%11.11s %12.12s | %12.12s | %s\n", indent, " ",
686 "Category",
687 "Smoothed avg", "Deviation", "Deviation/Avg");
688 for (j = 0; j <= 3; j++) {
689 fprintf(OUT,
690 "\t%*s%11.11s: %-11d | %-11d | %-11d | %-11d\n", indent, " ",
691 name[j],
692 s->ts_rtt[j],
693 s->ts_rtt[j],
694 s->ts_rtv[j],
695 s->ts_rtv[j]);
698 fprintf(OUT,
699 "\n%*sTpdus RECVD [%d valid, %3.6f %% of total (%d); %d dropped]\n",indent," ",
700 s->ts_tpdu_rcvd ,
701 ((s->ts_pkt_rcvd > 0) ?
702 ((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd)
703 : 0),
704 s->ts_pkt_rcvd,
705 s->ts_recv_drop );
707 fprintf(OUT,
708 "\t%*sDT %6d AK %6d DR %4d CR %4d \n", indent, " ",
709 s->ts_DT_rcvd, s->ts_AK_rcvd, s->ts_DR_rcvd, s->ts_CR_rcvd);
710 fprintf(OUT,
711 "\t%*sXPD %6d XAK %6d DC %4d CC %4d ER %4d\n", indent, " ",
712 s->ts_XPD_rcvd, s->ts_XAK_rcvd, s->ts_DC_rcvd, s->ts_CC_rcvd,
713 s->ts_ER_rcvd);
714 fprintf(OUT,
715 "\n%*sTpdus SENT [%d total, %d dropped]\n", indent, " ",
716 s->ts_tpdu_sent, s->ts_send_drop);
718 fprintf(OUT,
719 "\t%*sDT %6d AK %6d DR %4d CR %4d \n", indent, " ",
720 s->ts_DT_sent, s->ts_AK_sent, s->ts_DR_sent, s->ts_CR_sent);
721 fprintf(OUT,
722 "\t%*sXPD %6d XAK %6d DC %4d CC %4d ER %4d\n", indent, " ",
723 s->ts_XPD_sent, s->ts_XAK_sent, s->ts_DC_sent, s->ts_CC_sent,
724 s->ts_ER_sent);
726 fprintf(OUT,
727 "\n%*sRetransmissions:\n", indent, " ");
728 #define PERCENT(X,Y) (((Y)>0)?((100 *(float)(X)) / (float) (Y)):0)
730 fprintf(OUT,
731 "\t%*sCR %6d CC %6d DR %6d \n", indent, " ",
732 s->ts_retrans_cr, s->ts_retrans_cc, s->ts_retrans_dr);
733 fprintf(OUT,
734 "\t%*sDT %6d (%5.2f%%)\n", indent, " ",
735 s->ts_retrans_dt,
736 PERCENT(s->ts_retrans_dt, s->ts_DT_sent));
737 fprintf(OUT,
738 "\t%*sXPD %6d (%5.2f%%)\n", indent, " ",
739 s->ts_retrans_xpd,
740 PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent));
743 fprintf(OUT,
744 "\n%*sE Timers: [%6d ticks]\n", indent, " ", s->ts_Eticks);
745 fprintf(OUT,
746 "%*s%6d timer%s set \t%6d timer%s expired \t%6d timer%s cancelled\n",indent, " ",
747 s->ts_Eset ,plural(s->ts_Eset),
748 s->ts_Eexpired ,plural(s->ts_Eexpired),
749 s->ts_Ecan_act ,plural(s->ts_Ecan_act));
751 fprintf(OUT,
752 "\n%*sC Timers: [%6d ticks]\n", indent, " ",s->ts_Cticks);
753 fprintf(OUT,
754 "%*s%6d timer%s set \t%6d timer%s expired \t%6d timer%s cancelled\n",
755 indent, " ",
756 s->ts_Cset ,plural(s->ts_Cset),
757 s->ts_Cexpired ,plural(s->ts_Cexpired),
758 s->ts_Ccan_act ,plural(s->ts_Ccan_act));
759 fprintf(OUT,
760 "%*s%6d inactive timer%s cancelled\n", indent, " ",
761 s->ts_Ccan_inact ,plural(s->ts_Ccan_inact));
763 fprintf(OUT,
764 "\n%*sPathological debugging activity:\n", indent, " ");
765 fprintf(OUT,
766 "\t%*s%6d CC%s sent to zero dref\n", indent, " ",
767 s->ts_zdebug ,plural(s->ts_zdebug));
768 /* SAME LINE AS ABOVE */
769 fprintf(OUT,
770 "\t%*s%6d random DT%s dropped\n", indent, " ",
771 s->ts_ydebug ,plural(s->ts_ydebug));
772 fprintf(OUT,
773 "\t%*s%6d illegally large XPD TPDU%s\n", indent, " ",
774 s->ts_vdebug ,plural(s->ts_vdebug));
775 fprintf(OUT,
776 "\t%*s%6d faked reneging of cdt\n", indent, " ",
777 s->ts_ldebug );
779 fprintf(OUT,
780 "\n%*sACK reasons:\n", indent, " ");
781 fprintf(OUT, "\t%*s%6d not acked immediately\n", indent, " ",
782 s->ts_ackreason[_ACK_DONT_] );
783 fprintf(OUT, "\t%*s%6d strategy==each\n", indent, " ",
784 s->ts_ackreason[_ACK_STRAT_EACH_] );
785 fprintf(OUT, "\t%*s%6d strategy==fullwindow\n", indent, " ",
786 s->ts_ackreason[_ACK_STRAT_FULLWIN_] );
787 fprintf(OUT, "\t%*s%6d duplicate DT\n", indent, " ",
788 s->ts_ackreason[_ACK_DUP_] );
789 fprintf(OUT, "\t%*s%6d EOTSDU\n", indent, " ",
790 s->ts_ackreason[_ACK_EOT_] );
791 fprintf(OUT, "\t%*s%6d reordered DT\n", indent, " ",
792 s->ts_ackreason[_ACK_REORDER_] );
793 fprintf(OUT, "\t%*s%6d user rcvd\n", indent, " ",
794 s->ts_ackreason[_ACK_USRRCV_] );
795 fprintf(OUT, "\t%*s%6d fcc reqd\n", indent, " ",
796 s->ts_ackreason[_ACK_FCC_] );
798 #ifndef SSEL
799 #define SSEL(s) ((s)->siso_tlen + TSEL(s))
800 #define PSEL(s) ((s)->siso_slen + SSEL(s))
801 #endif
803 static void
804 isonetprint(siso, islocal)
805 register struct sockaddr_iso *siso;
806 int islocal;
808 hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}");
809 if (siso->siso_tlen || siso->siso_slen || siso->siso_plen)
810 hexprint(siso->siso_tlen, TSEL(siso), "()");
811 if (siso->siso_slen || siso->siso_plen)
812 hexprint(siso->siso_slen, SSEL(siso), "[]");
813 if (siso->siso_plen)
814 hexprint(siso->siso_plen, PSEL(siso), "<>");
815 putchar(' ');
818 static char hexlist[] = "0123456789abcdef", obuf[128];
820 static void
821 hexprint(n, buf, delim)
822 int n;
823 char *buf, *delim;
825 register u_char *in = (u_char *)buf, *top = in + n;
826 register char *out = obuf;
827 register int i;
829 if (n == 0)
830 return;
831 while (in < top) {
832 i = *in++;
833 *out++ = '.';
834 if (i > 0xf) {
835 out[1] = hexlist[i & 0xf];
836 i >>= 4;
837 out[0] = hexlist[i];
838 out += 2;
839 } else
840 *out++ = hexlist[i];
842 *obuf = *delim; *out++ = delim[1]; *out = 0;
843 printf("%s", obuf);
845 #endif