[BACK]Return to iso.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / netstat

Annotation of src/usr.bin/netstat/iso.c, Revision 1.3

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