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

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

1.3     ! itojun      1: /*     $OpenBSD: inet6.c,v 1.2 1999/12/30 20:31:31 deraadt Exp $       */
1.1       itojun      2: /*     BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp   */
                      3: /*
                      4:  * Copyright (c) 1983, 1988, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      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.
                     22:  *
                     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.
                     34:  */
                     35:
                     36: #include <sys/cdefs.h>
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "@(#)inet.c     8.4 (Berkeley) 4/20/94";
                     40: #else
1.3     ! itojun     41: /*__RCSID("$OpenBSD: inet6.c,v 1.2 1999/12/30 20:31:31 deraadt Exp $");*/
1.1       itojun     42: /*__RCSID("KAME Id: inet6.c,v 1.4 1999/12/02 04:47:27 itojun Exp");*/
                     43: #endif
                     44: #endif /* not lint */
                     45:
                     46: #include <sys/param.h>
                     47: #include <sys/socket.h>
                     48: #include <sys/socketvar.h>
                     49: #include <sys/ioctl.h>
                     50: #include <sys/mbuf.h>
                     51: #include <sys/protosw.h>
                     52:
                     53: #include <net/route.h>
                     54: #include <net/if.h>
                     55: #include <netinet/in.h>
                     56: #include <netinet/ip6.h>
                     57: #include <netinet/icmp6.h>
                     58: #include <netinet/in_systm.h>
                     59: #ifndef TCP6
                     60: #include <netinet/ip.h>
                     61: #include <netinet/ip_var.h>
                     62: #endif
                     63: #include <netinet6/in6_pcb.h>
                     64: #include <netinet6/in6_var.h>
                     65: #include <netinet6/ip6_var.h>
                     66: #include <netinet6/pim6_var.h>
                     67:
                     68: #include <arpa/inet.h>
                     69: #if 0
                     70: #include "gethostbyname2.h"
                     71: #endif
                     72: #include <netdb.h>
                     73:
                     74: #include <stdio.h>
                     75: #include <string.h>
                     76: #include <unistd.h>
                     77: #include "netstat.h"
                     78:
                     79: #ifdef INET6
                     80:
                     81: struct in6pcb in6pcb;
                     82: struct socket sockb;
                     83:
                     84: char   *inet6name __P((struct in6_addr *));
                     85: void   inet6print __P((struct in6_addr *, int, char *));
                     86:
                     87: #if 0
                     88: /*
                     89:  * Print a summary of connections related to an Internet
                     90:  * protocol.  For TCP, also give state of connection.
                     91:  * Listening processes (aflag) are suppressed unless the
                     92:  * -a (all) flag is specified.
                     93:  */
                     94: void
                     95: ip6protopr(off, name)
                     96:        u_long off;
                     97:        char *name;
                     98: {
                     99:        struct in6pcb cb;
                    100:        register struct in6pcb *prev, *next;
                    101:        int istcp;
                    102:        static int first = 1;
                    103:
                    104:        if (off == 0)
                    105:                return;
                    106:        istcp = strcmp(name, "tcp6") == 0;
                    107:        kread(off, (char *)&cb, sizeof (struct in6pcb));
                    108:        in6pcb = cb;
                    109:        prev = (struct in6pcb *)off;
                    110:        if (in6pcb.in6p_next == (struct in6pcb *)off)
                    111:                return;
                    112:        while (in6pcb.in6p_next != (struct in6pcb *)off) {
                    113:                next = in6pcb.in6p_next;
                    114:                kread((u_long)next, (char *)&in6pcb, sizeof (in6pcb));
                    115:                if (in6pcb.in6p_prev != prev) {
                    116:                        printf("???\n");
                    117:                        break;
                    118:                }
                    119:                if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr)) {
                    120:                        prev = next;
                    121:                        continue;
                    122:                }
                    123:                kread((u_long)in6pcb.in6p_socket, (char *)&sockb, sizeof (sockb));
                    124:                if (istcp) {
                    125: #ifdef TCP6
                    126:                        kread((u_long)in6pcb.in6p_ppcb,
                    127:                            (char *)&tcp6cb, sizeof (tcp6cb));
                    128: #else
                    129:                        kread((u_long)in6pcb.in6p_ppcb,
                    130:                            (char *)&tcpcb, sizeof (tcpcb));
                    131: #endif
                    132:                }
                    133:                if (first) {
                    134:                        printf("Active Internet6 connections");
                    135:                        if (aflag)
                    136:                                printf(" (including servers)");
                    137:                        putchar('\n');
                    138:                        if (Aflag)
                    139:                                printf("%-8.8s ", "PCB");
                    140:                        printf(Aflag ?
                    141:                                "%-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n" :
                    142:                                "%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
                    143:                                "Proto", "Recv-Q", "Send-Q",
                    144:                                "Local Address", "Foreign Address", "(state)");
                    145:                        first = 0;
                    146:                }
                    147:                if (Aflag) {
                    148:                        if (istcp)
                    149:                                printf("%8p ", in6pcb.in6p_ppcb);
                    150:                        else
                    151:                                printf("%8p ", next);
                    152:                }
                    153:                printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
                    154:                        sockb.so_snd.sb_cc);
                    155:                /* xxx */
                    156:                inet6print(&in6pcb.in6p_laddr, (int)in6pcb.in6p_lport, name);
                    157:                inet6print(&in6pcb.in6p_faddr, (int)in6pcb.in6p_fport, name);
                    158:                if (istcp) {
                    159: #ifdef TCP6
                    160:                        if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
                    161:                                printf(" %d", tcp6cb.t_state);
                    162:                        else
                    163:                                printf(" %s", tcp6states[tcp6cb.t_state]);
                    164: #else
                    165:                        if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
                    166:                                printf(" %d", tcpcb.t_state);
                    167:                        else
                    168:                                printf(" %s", tcpstates[tcpcb.t_state]);
                    169: #endif
                    170:                }
                    171:                putchar('\n');
                    172:                prev = next;
                    173:        }
                    174: }
                    175: #endif
                    176:
                    177: static char *ip6nh[] = {
                    178:        "hop by hop",
                    179:        "ICMP",
                    180:        "IGMP",
                    181:        "#3",
                    182:        "IP",
                    183:        "#5",
                    184:        "TCP",
                    185:        "#7",
                    186:        "#8",
                    187:        "#9",
                    188:        "#10",
                    189:        "#11",
                    190:        "#12",
                    191:        "#13",
                    192:        "#14",
                    193:        "#15",
                    194:        "#16",
                    195:        "UDP",
                    196:        "#18",
                    197:        "#19",
                    198:        "#20",
                    199:        "#21",
                    200:        "IDP",
                    201:        "#23",
                    202:        "#24",
                    203:        "#25",
                    204:        "#26",
                    205:        "#27",
                    206:        "#28",
                    207:        "TP",
                    208:        "#30",
                    209:        "#31",
                    210:        "#32",
                    211:        "#33",
                    212:        "#34",
                    213:        "#35",
                    214:        "#36",
                    215:        "#37",
                    216:        "#38",
                    217:        "#39",
                    218:        "#40",
                    219:        "IP6",
                    220:        "#42",
                    221:        "routing",
                    222:        "fragment",
                    223:        "#45",
                    224:        "#46",
                    225:        "#47",
                    226:        "#48",
                    227:        "#49",
                    228:        "ESP",
                    229:        "AH",
                    230:        "#52",
                    231:        "#53",
                    232:        "#54",
                    233:        "#55",
                    234:        "#56",
                    235:        "#57",
                    236:        "ICMP6",
                    237:        "no next header",
                    238:        "destination option",
                    239:        "#61",
                    240:        "#62",
                    241:        "#63",
                    242:        "#64",
                    243:        "#65",
                    244:        "#66",
                    245:        "#67",
                    246:        "#68",
                    247:        "#69",
                    248:        "#70",
                    249:        "#71",
                    250:        "#72",
                    251:        "#73",
                    252:        "#74",
                    253:        "#75",
                    254:        "#76",
                    255:        "#77",
                    256:        "#78",
                    257:        "#79",
                    258:        "ISOIP",
                    259:        "#81",
                    260:        "#82",
                    261:        "#83",
                    262:        "#84",
                    263:        "#85",
                    264:        "#86",
                    265:        "#87",
                    266:        "#88",
                    267:        "#89",
                    268:        "#80",
                    269:        "#91",
                    270:        "#92",
                    271:        "#93",
                    272:        "#94",
                    273:        "#95",
                    274:        "#96",
                    275:        "Ethernet",
                    276:        "#98",
                    277:        "#99",
                    278:        "#100",
                    279:        "#101",
                    280:        "#102",
                    281:        "PIM",
                    282:        "#104",
                    283:        "#105",
                    284:        "#106",
                    285:        "#107",
                    286:        "#108",
                    287:        "#109",
                    288:        "#110",
                    289:        "#111",
                    290:        "#112",
                    291:        "#113",
                    292:        "#114",
                    293:        "#115",
                    294:        "#116",
                    295:        "#117",
                    296:        "#118",
                    297:        "#119",
                    298:        "#120",
                    299:        "#121",
                    300:        "#122",
                    301:        "#123",
                    302:        "#124",
                    303:        "#125",
                    304:        "#126",
                    305:        "#127",
                    306:        "#128",
                    307:        "#129",
                    308:        "#130",
                    309:        "#131",
                    310:        "#132",
                    311:        "#133",
                    312:        "#134",
                    313:        "#135",
                    314:        "#136",
                    315:        "#137",
                    316:        "#138",
                    317:        "#139",
                    318:        "#140",
                    319:        "#141",
                    320:        "#142",
                    321:        "#143",
                    322:        "#144",
                    323:        "#145",
                    324:        "#146",
                    325:        "#147",
                    326:        "#148",
                    327:        "#149",
                    328:        "#150",
                    329:        "#151",
                    330:        "#152",
                    331:        "#153",
                    332:        "#154",
                    333:        "#155",
                    334:        "#156",
                    335:        "#157",
                    336:        "#158",
                    337:        "#159",
                    338:        "#160",
                    339:        "#161",
                    340:        "#162",
                    341:        "#163",
                    342:        "#164",
                    343:        "#165",
                    344:        "#166",
                    345:        "#167",
                    346:        "#168",
                    347:        "#169",
                    348:        "#170",
                    349:        "#171",
                    350:        "#172",
                    351:        "#173",
                    352:        "#174",
                    353:        "#175",
                    354:        "#176",
                    355:        "#177",
                    356:        "#178",
                    357:        "#179",
                    358:        "#180",
                    359:        "#181",
                    360:        "#182",
                    361:        "#183",
                    362:        "#184",
                    363:        "#185",
                    364:        "#186",
                    365:        "#187",
                    366:        "#188",
                    367:        "#189",
                    368:        "#180",
                    369:        "#191",
                    370:        "#192",
                    371:        "#193",
                    372:        "#194",
                    373:        "#195",
                    374:        "#196",
                    375:        "#197",
                    376:        "#198",
                    377:        "#199",
                    378:        "#200",
                    379:        "#201",
                    380:        "#202",
                    381:        "#203",
                    382:        "#204",
                    383:        "#205",
                    384:        "#206",
                    385:        "#207",
                    386:        "#208",
                    387:        "#209",
                    388:        "#210",
                    389:        "#211",
                    390:        "#212",
                    391:        "#213",
                    392:        "#214",
                    393:        "#215",
                    394:        "#216",
                    395:        "#217",
                    396:        "#218",
                    397:        "#219",
                    398:        "#220",
                    399:        "#221",
                    400:        "#222",
                    401:        "#223",
                    402:        "#224",
                    403:        "#225",
                    404:        "#226",
                    405:        "#227",
                    406:        "#228",
                    407:        "#229",
                    408:        "#230",
                    409:        "#231",
                    410:        "#232",
                    411:        "#233",
                    412:        "#234",
                    413:        "#235",
                    414:        "#236",
                    415:        "#237",
                    416:        "#238",
                    417:        "#239",
                    418:        "#240",
                    419:        "#241",
                    420:        "#242",
                    421:        "#243",
                    422:        "#244",
                    423:        "#245",
                    424:        "#246",
                    425:        "#247",
                    426:        "#248",
                    427:        "#249",
                    428:        "#250",
                    429:        "#251",
                    430:        "#252",
                    431:        "#253",
                    432:        "#254",
                    433:        "#255",
                    434: };
                    435:
                    436: /*
                    437:  * Dump IP6 statistics structure.
                    438:  */
                    439: void
                    440: ip6_stats(off, name)
                    441:        u_long off;
                    442:        char *name;
                    443: {
                    444:        struct ip6stat ip6stat;
                    445:        int first, i;
                    446:
                    447:        if (off == 0)
                    448:                return;
                    449:
                    450:        kread(off, (char *)&ip6stat, sizeof (ip6stat));
                    451:        printf("%s:\n", name);
                    452:
                    453: #define        p(f, m) if (ip6stat.f || sflag <= 1) \
                    454:     printf(m, ip6stat.f, plural(ip6stat.f))
                    455: #define        p1(f, m) if (ip6stat.f || sflag <= 1) \
                    456:     printf(m, ip6stat.f)
                    457:
                    458:        p(ip6s_total, "\t%qu total packet%s received\n");
                    459:        p1(ip6s_toosmall, "\t%qu with size smaller than minimum\n");
                    460:        p1(ip6s_tooshort, "\t%qu with data size < data length\n");
                    461:        p1(ip6s_badoptions, "\t%qu with bad options\n");
                    462:        p1(ip6s_badvers, "\t%qu with incorrect version number\n");
                    463:        p(ip6s_fragments, "\t%qu fragment%s received\n");
                    464:        p(ip6s_fragdropped, "\t%qu fragment%s dropped (dup or out of space)\n");
                    465:        p(ip6s_fragtimeout, "\t%qu fragment%s dropped after timeout\n");
                    466:        p(ip6s_fragoverflow, "\t%qu fragment%s that exceeded limit\n");
                    467:        p(ip6s_reassembled, "\t%qu packet%s reassembled ok\n");
                    468:        p(ip6s_delivered, "\t%qu packet%s for this host\n");
                    469:        p(ip6s_forward, "\t%qu packet%s forwarded\n");
                    470:        p(ip6s_cantforward, "\t%qu packet%s not forwardable\n");
                    471:        p(ip6s_redirectsent, "\t%qu redirect%s sent\n");
                    472:        p(ip6s_localout, "\t%qu packet%s sent from this host\n");
                    473:        p(ip6s_rawout, "\t%qu packet%s sent with fabricated ip header\n");
                    474:        p(ip6s_odropped, "\t%qu output packet%s dropped due to no bufs, etc.\n");
                    475:        p(ip6s_noroute, "\t%qu output packet%s discarded due to no route\n");
                    476:        p(ip6s_fragmented, "\t%qu output datagram%s fragmented\n");
                    477:        p(ip6s_ofragments, "\t%qu fragment%s created\n");
                    478:        p(ip6s_cantfrag, "\t%qu datagram%s that can't be fragmented\n");
                    479:        p(ip6s_badscope, "\t%qu packet%s that violated scope rules\n");
                    480:        p(ip6s_notmember, "\t%qu multicast packet%s which we don't join\n");
                    481:        for (first = 1, i = 0; i < 256; i++)
                    482:                if (ip6stat.ip6s_nxthist[i] != 0) {
                    483:                        if (first) {
1.3     ! itojun    484:                                printf("\tInput packet histogram:\n");
1.1       itojun    485:                                first = 0;
                    486:                        }
                    487:                        printf("\t\t%s: %qu\n", ip6nh[i],
                    488:                               ip6stat.ip6s_nxthist[i]);
                    489:                }
1.2       deraadt   490:        if (ip6stat.ip6s_m1 || sflag <= 1)
                    491:                printf("\tMbuf statics:\n");
                    492:        p(ip6s_m1, "\t\t%qu one mbuf\n");
1.1       itojun    493:        for (first = 1, i = 0; i < 32; i++) {
                    494:                char ifbuf[IFNAMSIZ];
                    495:                if (ip6stat.ip6s_m2m[i] != 0) {
                    496:                        if (first) {
                    497:                                printf("\t\ttwo or more mbuf:\n");
                    498:                                first = 0;
                    499:                        }
                    500:                        printf("\t\t\t%s = %qu\n",
                    501:                               if_indextoname(i, ifbuf),
                    502:                               ip6stat.ip6s_m2m[i]);
                    503:                }
                    504:        }
1.2       deraadt   505:        p(ip6s_mext1, "\t\t%qu one ext mbuf\n");
                    506:        p(ip6s_mext2m, "\t\t%qu two or more ext mbuf\n");
1.1       itojun    507:        p(ip6s_exthdrtoolong, "\t%qu packet%s whose headers are not continuous\n");
                    508:        p(ip6s_nogif, "\t%qu tunneling packet%s that can't find gif\n");
                    509: #undef p
                    510: #undef p1
                    511: }
                    512:
                    513: /*
                    514:  * Dump IPv6 per-interface statistics based on RFC 2465.
                    515:  */
                    516: void
                    517: ip6_ifstats(ifname)
                    518:        char *ifname;
                    519: {
                    520:        struct in6_ifreq ifr;
                    521:        int s;
                    522: #define        p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
                    523:     printf(m, ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f))
                    524: #define        p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
                    525:     printf(m, ip6stat.f)
                    526:
                    527:        if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
                    528:                perror("Warning: socket(AF_INET6)");
                    529:                return;
                    530:        }
                    531:
                    532:        strcpy(ifr.ifr_name, ifname);
                    533:        printf("ip6 on %s:\n", ifr.ifr_name);
                    534:
                    535:        if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
                    536:                perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
                    537:                goto end;
                    538:        }
                    539:
                    540:        p(ifs6_in_receive, "\t%qu total input datagram%s\n");
                    541:        p(ifs6_in_hdrerr, "\t%qu datagram%s with invalid header received\n");
                    542:        p(ifs6_in_toobig, "\t%qu datagram%s exceeded MTU received\n");
                    543:        p(ifs6_in_noroute, "\t%qu datagram%s with no route received\n");
                    544:        p(ifs6_in_addrerr, "\t%qu datagram%s with invalid dst received\n");
                    545:        p(ifs6_in_protounknown, "\t%qu datagram%s with unknown proto received\n");
                    546:        p(ifs6_in_discard, "\t%qu input datagram%s discarded\n");
                    547:        p(ifs6_in_deliver,
                    548:          "\t%qu datagram%s delivered to an upper layer protocol\n");
                    549:        p(ifs6_out_forward, "\t%qu datagram%s forwarded to this interface\n");
                    550:        p(ifs6_out_request,
                    551:          "\t%qu datagram%s sent from an upper layer protocol\n");
                    552:        p(ifs6_out_discard, "\t%qu total discarded output datagram%s\n");
                    553:        p(ifs6_out_fragok, "\t%qu output datagram%s fragmented\n");
                    554:        p(ifs6_out_fragfail, "\t%qu output datagram%s failed on fragment\n");
                    555:        p(ifs6_out_fragcreat, "\t%qu output datagram%s succeeded on fragment\n");
                    556:        p(ifs6_reass_reqd, "\t%qu incoming datagram%s fragmented\n");
                    557:        p(ifs6_reass_ok, "\t%qu datagram%s reassembled\n");
                    558:        p(ifs6_reass_fail, "\t%qu datagram%s failed on reassembling\n");
                    559:        p(ifs6_in_mcast, "\t%qu multicast datagram%s received\n");
                    560:        p(ifs6_out_mcast, "\t%qu multicast datagram%s sent\n");
                    561:
                    562:   end:
                    563:        close(s);
                    564:
                    565: #undef p
                    566: #undef p_5
                    567: }
                    568:
                    569: static char *icmp6names[] = {
                    570:        "#0",
                    571:        "unreach",
                    572:        "packet too big",
                    573:        "time exceed",
                    574:        "parameter problem",
                    575:        "#5",
                    576:        "#6",
                    577:        "#7",
                    578:        "#8",
                    579:        "#9",
                    580:        "#10",
                    581:        "#11",
                    582:        "#12",
                    583:        "#13",
                    584:        "#14",
                    585:        "#15",
                    586:        "#16",
                    587:        "#17",
                    588:        "#18",
                    589:        "#19",
                    590:        "#20",
                    591:        "#21",
                    592:        "#22",
                    593:        "#23",
                    594:        "#24",
                    595:        "#25",
                    596:        "#26",
                    597:        "#27",
                    598:        "#28",
                    599:        "#29",
                    600:        "#30",
                    601:        "#31",
                    602:        "#32",
                    603:        "#33",
                    604:        "#34",
                    605:        "#35",
                    606:        "#36",
                    607:        "#37",
                    608:        "#38",
                    609:        "#39",
                    610:        "#40",
                    611:        "#41",
                    612:        "#42",
                    613:        "#43",
                    614:        "#44",
                    615:        "#45",
                    616:        "#46",
                    617:        "#47",
                    618:        "#48",
                    619:        "#49",
                    620:        "#50",
                    621:        "#51",
                    622:        "#52",
                    623:        "#53",
                    624:        "#54",
                    625:        "#55",
                    626:        "#56",
                    627:        "#57",
                    628:        "#58",
                    629:        "#59",
                    630:        "#60",
                    631:        "#61",
                    632:        "#62",
                    633:        "#63",
                    634:        "#64",
                    635:        "#65",
                    636:        "#66",
                    637:        "#67",
                    638:        "#68",
                    639:        "#69",
                    640:        "#70",
                    641:        "#71",
                    642:        "#72",
                    643:        "#73",
                    644:        "#74",
                    645:        "#75",
                    646:        "#76",
                    647:        "#77",
                    648:        "#78",
                    649:        "#79",
                    650:        "#80",
                    651:        "#81",
                    652:        "#82",
                    653:        "#83",
                    654:        "#84",
                    655:        "#85",
                    656:        "#86",
                    657:        "#87",
                    658:        "#88",
                    659:        "#89",
                    660:        "#80",
                    661:        "#91",
                    662:        "#92",
                    663:        "#93",
                    664:        "#94",
                    665:        "#95",
                    666:        "#96",
                    667:        "#97",
                    668:        "#98",
                    669:        "#99",
                    670:        "#100",
                    671:        "#101",
                    672:        "#102",
                    673:        "#103",
                    674:        "#104",
                    675:        "#105",
                    676:        "#106",
                    677:        "#107",
                    678:        "#108",
                    679:        "#109",
                    680:        "#110",
                    681:        "#111",
                    682:        "#112",
                    683:        "#113",
                    684:        "#114",
                    685:        "#115",
                    686:        "#116",
                    687:        "#117",
                    688:        "#118",
                    689:        "#119",
                    690:        "#120",
                    691:        "#121",
                    692:        "#122",
                    693:        "#123",
                    694:        "#124",
                    695:        "#125",
                    696:        "#126",
                    697:        "#127",
                    698:        "echo",
                    699:        "echo reply",
                    700:        "multicast listener query",
                    701:        "multicast listener report",
                    702:        "multicast listener done",
                    703:        "router solicitation",
                    704:        "router advertisment",
                    705:        "neighbor solicitation",
                    706:        "neighbor advertisment",
                    707:        "redirect",
                    708:        "router renumbering",
                    709:        "node information request",
                    710:        "node information reply",
                    711:        "#141",
                    712:        "#142",
                    713:        "#143",
                    714:        "#144",
                    715:        "#145",
                    716:        "#146",
                    717:        "#147",
                    718:        "#148",
                    719:        "#149",
                    720:        "#150",
                    721:        "#151",
                    722:        "#152",
                    723:        "#153",
                    724:        "#154",
                    725:        "#155",
                    726:        "#156",
                    727:        "#157",
                    728:        "#158",
                    729:        "#159",
                    730:        "#160",
                    731:        "#161",
                    732:        "#162",
                    733:        "#163",
                    734:        "#164",
                    735:        "#165",
                    736:        "#166",
                    737:        "#167",
                    738:        "#168",
                    739:        "#169",
                    740:        "#170",
                    741:        "#171",
                    742:        "#172",
                    743:        "#173",
                    744:        "#174",
                    745:        "#175",
                    746:        "#176",
                    747:        "#177",
                    748:        "#178",
                    749:        "#179",
                    750:        "#180",
                    751:        "#181",
                    752:        "#182",
                    753:        "#183",
                    754:        "#184",
                    755:        "#185",
                    756:        "#186",
                    757:        "#187",
                    758:        "#188",
                    759:        "#189",
                    760:        "#180",
                    761:        "#191",
                    762:        "#192",
                    763:        "#193",
                    764:        "#194",
                    765:        "#195",
                    766:        "#196",
                    767:        "#197",
                    768:        "#198",
                    769:        "#199",
                    770:        "#200",
                    771:        "#201",
                    772:        "#202",
                    773:        "#203",
                    774:        "#204",
                    775:        "#205",
                    776:        "#206",
                    777:        "#207",
                    778:        "#208",
                    779:        "#209",
                    780:        "#210",
                    781:        "#211",
                    782:        "#212",
                    783:        "#213",
                    784:        "#214",
                    785:        "#215",
                    786:        "#216",
                    787:        "#217",
                    788:        "#218",
                    789:        "#219",
                    790:        "#220",
                    791:        "#221",
                    792:        "#222",
                    793:        "#223",
                    794:        "#224",
                    795:        "#225",
                    796:        "#226",
                    797:        "#227",
                    798:        "#228",
                    799:        "#229",
                    800:        "#230",
                    801:        "#231",
                    802:        "#232",
                    803:        "#233",
                    804:        "#234",
                    805:        "#235",
                    806:        "#236",
                    807:        "#237",
                    808:        "#238",
                    809:        "#239",
                    810:        "#240",
                    811:        "#241",
                    812:        "#242",
                    813:        "#243",
                    814:        "#244",
                    815:        "#245",
                    816:        "#246",
                    817:        "#247",
                    818:        "#248",
                    819:        "#249",
                    820:        "#250",
                    821:        "#251",
                    822:        "#252",
                    823:        "#253",
                    824:        "#254",
                    825:        "#255",
                    826: };
                    827:
                    828: /*
                    829:  * Dump ICMPv6 statistics.
                    830:  */
                    831: void
                    832: icmp6_stats(off, name)
                    833:        u_long off;
                    834:        char *name;
                    835: {
                    836:        struct icmp6stat icmp6stat;
                    837:        register int i, first;
                    838:
                    839:        if (off == 0)
                    840:                return;
                    841:        kread(off, (char *)&icmp6stat, sizeof (icmp6stat));
                    842:        printf("%s:\n", name);
                    843:
                    844: #define        p(f, m) if (icmp6stat.f || sflag <= 1) \
                    845:     printf(m, icmp6stat.f, plural(icmp6stat.f))
                    846:
                    847:        p(icp6s_error, "\t%qu call%s to icmp_error\n");
                    848:        p(icp6s_canterror,
                    849:            "\t%qu error%s not generated because old message was icmp or so\n");
                    850:        for (first = 1, i = 0; i < 256; i++)
                    851:                if (icmp6stat.icp6s_outhist[i] != 0) {
                    852:                        if (first) {
1.3     ! itojun    853:                                printf("\tOutput packet histogram:\n");
1.1       itojun    854:                                first = 0;
                    855:                        }
                    856:                        printf("\t\t%s: %qu\n", icmp6names[i],
                    857:                                icmp6stat.icp6s_outhist[i]);
                    858:                }
                    859:        p(icp6s_badcode, "\t%qu message%s with bad code fields\n");
                    860:        p(icp6s_tooshort, "\t%qu message%s < minimum length\n");
                    861:        p(icp6s_checksum, "\t%qu bad checksum%s\n");
                    862:        p(icp6s_badlen, "\t%qu message%s with bad length\n");
                    863:        for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
                    864:                if (icmp6stat.icp6s_inhist[i] != 0) {
                    865:                        if (first) {
1.3     ! itojun    866:                                printf("\tInput packet histogram:\n");
1.1       itojun    867:                                first = 0;
                    868:                        }
                    869:                        printf("\t\t%s: %qu\n", icmp6names[i],
                    870:                                icmp6stat.icp6s_inhist[i]);
                    871:                }
                    872:        p(icp6s_reflect, "\t%qu message response%s generated\n");
                    873: #undef p
                    874: }
                    875:
                    876: /*
                    877:  * Dump ICMPv6 per-interface statistics based on RFC 2466.
                    878:  */
                    879: void
                    880: icmp6_ifstats(ifname)
                    881:        char *ifname;
                    882: {
                    883:        struct in6_ifreq ifr;
                    884:        int s;
                    885: #define        p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
                    886:     printf(m, (u_quad_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f))
                    887:
                    888:        if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
                    889:                perror("Warning: socket(AF_INET6)");
                    890:                return;
                    891:        }
                    892:
                    893:        strcpy(ifr.ifr_name, ifname);
                    894:        printf("icmp6 on %s:\n", ifr.ifr_name);
                    895:
                    896:        if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
                    897:                perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
                    898:                goto end;
                    899:        }
                    900:
                    901:        p(ifs6_in_msg, "\t%qu total input message%s\n");
                    902:        p(ifs6_in_error, "\t%qu total input error message%s\n");
                    903:        p(ifs6_in_dstunreach, "\t%qu input destination unreachable error%s\n");
                    904:        p(ifs6_in_adminprohib, "\t%qu input administratively prohibited error%s\n");
                    905:        p(ifs6_in_timeexceed, "\t%qu input time exceeded error%s\n");
                    906:        p(ifs6_in_paramprob, "\t%qu input parameter problem error%s\n");
                    907:        p(ifs6_in_pkttoobig, "\t%qu input packet too big error%s\n");
                    908:        p(ifs6_in_echo, "\t%qu input echo request%s\n");
                    909:        p(ifs6_in_echoreply, "\t%qu input echo reply%s\n");
                    910:        p(ifs6_in_routersolicit, "\t%qu input router solicitation%s\n");
                    911:        p(ifs6_in_routeradvert, "\t%qu input router advertisement%s\n");
                    912:        p(ifs6_in_neighborsolicit, "\t%qu input neighbor solicitation%s\n");
                    913:        p(ifs6_in_neighboradvert, "\t%qu input neighbor advertisement%s\n");
                    914:        p(ifs6_in_redirect, "\t%qu input redirect%s\n");
                    915:        p(ifs6_in_mldquery, "\t%qu input MLD query%s\n");
                    916:        p(ifs6_in_mldreport, "\t%qu input MLD report%s\n");
                    917:        p(ifs6_in_mlddone, "\t%qu input MLD done%s\n");
                    918:
                    919:        p(ifs6_out_msg, "\t%qu total output message%s\n");
                    920:        p(ifs6_out_error, "\t%qu total output error message%s\n");
                    921:        p(ifs6_out_dstunreach, "\t%qu output destination unreachable error%s\n");
                    922:        p(ifs6_out_adminprohib, "\t%qu output administratively prohibited error%s\n");
                    923:        p(ifs6_out_timeexceed, "\t%qu output time exceeded error%s\n");
                    924:        p(ifs6_out_paramprob, "\t%qu output parameter problem error%s\n");
                    925:        p(ifs6_out_pkttoobig, "\t%qu output packet too big error%s\n");
                    926:        p(ifs6_out_echo, "\t%qu output echo request%s\n");
                    927:        p(ifs6_out_echoreply, "\t%qu output echo reply%s\n");
                    928:        p(ifs6_out_routersolicit, "\t%qu output router solicitation%s\n");
                    929:        p(ifs6_out_routeradvert, "\t%qu output router advertisement%s\n");
                    930:        p(ifs6_out_neighborsolicit, "\t%qu output neighbor solicitation%s\n");
                    931:        p(ifs6_out_neighboradvert, "\t%qu output neighbor advertisement%s\n");
                    932:        p(ifs6_out_redirect, "\t%qu output redirect%s\n");
                    933:        p(ifs6_out_mldquery, "\t%qu output MLD query%s\n");
                    934:        p(ifs6_out_mldreport, "\t%qu output MLD report%s\n");
                    935:        p(ifs6_out_mlddone, "\t%qu output MLD done%s\n");
                    936:
                    937:   end:
                    938:        close(s);
                    939: #undef p
                    940: }
                    941:
                    942: /*
                    943:  * Dump PIM statistics structure.
                    944:  */
                    945: void
                    946: pim6_stats(off, name)
                    947:        u_long off;
                    948:        char *name;
                    949: {
                    950:        struct pim6stat pim6stat;
                    951:
                    952:        if (off == 0)
                    953:                return;
                    954:        kread(off, (char *)&pim6stat, sizeof(pim6stat));
                    955:        printf("%s:\n", name);
                    956:
                    957: #define        p(f, m) if (pim6stat.f || sflag <= 1) \
                    958:     printf(m, pim6stat.f, plural(pim6stat.f))
                    959:        p(pim6s_rcv_total, "\t%qu message%s received\n");
                    960:        p(pim6s_rcv_tooshort, "\t%qu message%s received with too few bytes\n");
                    961:        p(pim6s_rcv_badsum, "\t%qu message%s received with bad checksum\n");
                    962:        p(pim6s_rcv_badversion, "\t%qu message%s received with bad version\n");
                    963:        p(pim6s_rcv_registers, "\t%qu register%s received\n");
                    964:        p(pim6s_rcv_badregisters, "\t%qu bad register%s received\n");
                    965:        p(pim6s_snd_registers, "\t%qu register%s sent\n");
                    966: #undef p
                    967: }
                    968:
                    969: /*
                    970:  * Pretty print an Internet address (net address + port).
                    971:  * If the nflag was specified, use numbers instead of names.
                    972:  */
                    973:
                    974: void
                    975: inet6print(in6, port, proto)
                    976:        register struct in6_addr *in6;
                    977:        int port;
                    978:        char *proto;
                    979: {
                    980: #define GETSERVBYPORT6(port, proto, ret)\
                    981: {\
                    982:        if (strcmp((proto), "tcp6") == 0)\
                    983:                (ret) = getservbyport((int)(port), "tcp");\
                    984:        else if (strcmp((proto), "udp6") == 0)\
                    985:                (ret) = getservbyport((int)(port), "udp");\
                    986:        else\
                    987:                (ret) = getservbyport((int)(port), (proto));\
                    988: };
                    989:        struct servent *sp = 0;
                    990:        char line[80], *cp;
                    991:        int width;
                    992:
                    993:        sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inet6name(in6));
                    994:        cp = index(line, '\0');
                    995:        if (!nflag && port)
                    996:                GETSERVBYPORT6(port, proto, sp);
                    997:        if (sp || port == 0)
                    998:                sprintf(cp, "%.8s", sp ? sp->s_name : "*");
                    999:        else
                   1000:                sprintf(cp, "%d", ntohs((u_short)port));
                   1001:        width = Aflag ? 18 : 22;
                   1002:        printf(" %-*.*s", width, width, line);
                   1003: }
                   1004:
                   1005: /*
                   1006:  * Construct an Internet address representation.
                   1007:  * If the nflag has been supplied, give
                   1008:  * numeric value, otherwise try for symbolic name.
                   1009:  */
                   1010:
                   1011: char *
                   1012: inet6name(in6p)
                   1013:        struct in6_addr *in6p;
                   1014: {
                   1015:        register char *cp;
                   1016:        static char line[50];
                   1017:        struct hostent *hp;
                   1018:        static char domain[MAXHOSTNAMELEN + 1];
                   1019:        static int first = 1;
                   1020:        static char hbuf[NI_MAXHOST];
                   1021:        struct sockaddr_in6 sin6;
                   1022: #ifdef NI_WITHSCOPEID
                   1023:        const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
                   1024: #else
                   1025:        const int niflag = NI_NUMERICHOST;
                   1026: #endif
                   1027:
                   1028:        if (first && !nflag) {
                   1029:                first = 0;
                   1030:                if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
                   1031:                    (cp = index(domain, '.')))
                   1032:                        (void) strcpy(domain, cp + 1);
                   1033:                else
                   1034:                        domain[0] = 0;
                   1035:        }
                   1036:        cp = 0;
                   1037:        if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
                   1038:                hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
                   1039:                if (hp) {
                   1040:                        if ((cp = index(hp->h_name, '.')) &&
                   1041:                            !strcmp(cp + 1, domain))
                   1042:                                *cp = 0;
                   1043:                        cp = hp->h_name;
                   1044:                }
                   1045:        }
                   1046:        if (IN6_IS_ADDR_UNSPECIFIED(in6p))
                   1047:                strcpy(line, "*");
                   1048:        else if (cp)
                   1049:                strcpy(line, cp);
                   1050:        else {
                   1051:                memset(&sin6, 0, sizeof(sin6));
                   1052:                sin6.sin6_len = sizeof(sin6);
                   1053:                sin6.sin6_family = AF_INET6;
                   1054:                sin6.sin6_addr = *in6p;
                   1055: #ifdef KAME_SCOPEID
                   1056:                if (IN6_IS_ADDR_LINKLOCAL(in6p)) {
                   1057:                        sin6.sin6_scope_id =
                   1058:                                ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
                   1059:                        sin6.sin6_addr.s6_addr[2] = 0;
                   1060:                        sin6.sin6_addr.s6_addr[3] = 0;
                   1061:                }
                   1062: #endif
                   1063:                if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
                   1064:                                hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
                   1065:                        strcpy(hbuf, "?");
                   1066:                strncpy(line, hbuf, sizeof(line));
                   1067:        }
                   1068:        return (line);
                   1069: }
                   1070:
                   1071: #ifdef TCP6
                   1072: /*
                   1073:  * Dump the contents of a TCP6 PCB.
                   1074:  */
                   1075: void
                   1076: tcp6_dump(pcbaddr)
                   1077:        u_long pcbaddr;
                   1078: {
                   1079:        struct tcp6cb tcp6cb;
                   1080:        int i;
                   1081:
                   1082:        kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
                   1083:
                   1084:        printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
                   1085:
                   1086:        printf("Timers:\n");
                   1087:        for (i = 0; i < TCP6T_NTIMERS; i++)
                   1088:                printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
                   1089:        printf("\n\n");
                   1090:
                   1091:        if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
                   1092:                printf("State: %d", tcp6cb.t_state);
                   1093:        else
                   1094:                printf("State: %s", tcp6states[tcp6cb.t_state]);
                   1095:        printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
                   1096:            (u_long)tcp6cb.t_in6pcb);
                   1097:
                   1098:        printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
                   1099:            tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
                   1100:        printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
                   1101:            tcp6cb.t_maxseg, tcp6cb.t_force);
                   1102:
                   1103:        printf("snd_una %u, snd_nxt %u, snd_up %u\n",
                   1104:            tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
                   1105:        printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %lu\n\n",
                   1106:            tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss, tcp6cb.snd_wnd);
                   1107:
                   1108:        printf("rcv_wnd %lu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
                   1109:            tcp6cb.rcv_wnd, tcp6cb.rcv_nxt, tcp6cb.rcv_up, tcp6cb.irs);
                   1110:
                   1111:        printf("rcv_adv %u, snd_max %u, snd_cwnd %lu, snd_ssthresh %lu\n",
                   1112:            tcp6cb.rcv_adv, tcp6cb.snd_max, tcp6cb.snd_cwnd, tcp6cb.snd_ssthresh);
                   1113:
                   1114:        printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
                   1115:            "max_sndwnd %lu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
                   1116:            tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin, tcp6cb.max_sndwnd);
                   1117:
                   1118:        printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
                   1119:            tcp6cb.t_iobc, tcp6cb.t_softerror);
                   1120:
                   1121:        printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
                   1122:            tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
                   1123:            tcp6cb.requested_s_scale);
                   1124:        printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
                   1125:            tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
                   1126: }
                   1127: #endif
                   1128:
                   1129: #endif /*INET6*/