home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / crh / freebsd / rootkit / netstat / iso.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-27  |  23.5 KB  |  844 lines

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