Home | History | Annotate | Line # | Download | only in netstat
inet6.c revision 1.34
      1  1.34    rpaulo /*	$NetBSD: inet6.c,v 1.34 2005/08/04 19:41:28 rpaulo Exp $	*/
      2   1.7    itojun /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
      3   1.7    itojun 
      4   1.7    itojun /*
      5   1.7    itojun  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
      6   1.7    itojun  * All rights reserved.
      7   1.7    itojun  *
      8   1.7    itojun  * Redistribution and use in source and binary forms, with or without
      9   1.7    itojun  * modification, are permitted provided that the following conditions
     10   1.7    itojun  * are met:
     11   1.7    itojun  * 1. Redistributions of source code must retain the above copyright
     12   1.7    itojun  *    notice, this list of conditions and the following disclaimer.
     13   1.7    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.7    itojun  *    notice, this list of conditions and the following disclaimer in the
     15   1.7    itojun  *    documentation and/or other materials provided with the distribution.
     16   1.7    itojun  * 3. Neither the name of the project nor the names of its contributors
     17   1.7    itojun  *    may be used to endorse or promote products derived from this software
     18   1.7    itojun  *    without specific prior written permission.
     19   1.7    itojun  *
     20   1.7    itojun  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     21   1.7    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22   1.7    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23   1.7    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     24   1.7    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25   1.7    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26   1.7    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27   1.7    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28   1.7    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29   1.7    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30   1.7    itojun  * SUCH DAMAGE.
     31   1.7    itojun  */
     32   1.2    itojun 
     33   1.1    itojun /*
     34   1.1    itojun  * Copyright (c) 1983, 1988, 1993
     35   1.1    itojun  *	The Regents of the University of California.  All rights reserved.
     36   1.1    itojun  *
     37   1.1    itojun  * Redistribution and use in source and binary forms, with or without
     38   1.1    itojun  * modification, are permitted provided that the following conditions
     39   1.1    itojun  * are met:
     40   1.1    itojun  * 1. Redistributions of source code must retain the above copyright
     41   1.1    itojun  *    notice, this list of conditions and the following disclaimer.
     42   1.1    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     43   1.1    itojun  *    notice, this list of conditions and the following disclaimer in the
     44   1.1    itojun  *    documentation and/or other materials provided with the distribution.
     45  1.28       agc  * 3. Neither the name of the University nor the names of its contributors
     46   1.1    itojun  *    may be used to endorse or promote products derived from this software
     47   1.1    itojun  *    without specific prior written permission.
     48   1.1    itojun  *
     49   1.1    itojun  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     50   1.1    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51   1.1    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52   1.1    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     53   1.1    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54   1.1    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55   1.1    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56   1.1    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57   1.1    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58   1.1    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59   1.1    itojun  * SUCH DAMAGE.
     60   1.1    itojun  */
     61   1.1    itojun 
     62   1.1    itojun #include <sys/cdefs.h>
     63   1.1    itojun #ifndef lint
     64   1.1    itojun #if 0
     65   1.1    itojun static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
     66   1.1    itojun #else
     67  1.34    rpaulo __RCSID("$NetBSD: inet6.c,v 1.34 2005/08/04 19:41:28 rpaulo Exp $");
     68   1.1    itojun #endif
     69   1.1    itojun #endif /* not lint */
     70   1.1    itojun 
     71   1.1    itojun #include <sys/param.h>
     72   1.1    itojun #include <sys/socket.h>
     73   1.1    itojun #include <sys/socketvar.h>
     74   1.5    itojun #include <sys/ioctl.h>
     75   1.1    itojun #include <sys/mbuf.h>
     76   1.1    itojun #include <sys/protosw.h>
     77   1.1    itojun 
     78   1.1    itojun #include <net/route.h>
     79   1.1    itojun #include <net/if.h>
     80   1.1    itojun #include <netinet/in.h>
     81   1.1    itojun #include <netinet/ip6.h>
     82   1.1    itojun #include <netinet/icmp6.h>
     83   1.1    itojun #include <netinet/in_systm.h>
     84   1.1    itojun #ifndef TCP6
     85   1.1    itojun #include <netinet/ip.h>
     86   1.1    itojun #include <netinet/ip_var.h>
     87   1.1    itojun #endif
     88   1.7    itojun #include <netinet6/ip6_var.h>
     89   1.1    itojun #include <netinet6/in6_pcb.h>
     90   1.5    itojun #include <netinet6/in6_var.h>
     91   1.1    itojun #include <netinet6/ip6_var.h>
     92   1.1    itojun #ifdef TCP6
     93   1.1    itojun #include <netinet6/tcp6.h>
     94   1.1    itojun #include <netinet6/tcp6_seq.h>
     95   1.1    itojun #define TCP6STATES
     96   1.1    itojun #include <netinet6/tcp6_fsm.h>
     97   1.1    itojun #define TCP6TIMERS
     98   1.1    itojun #include <netinet6/tcp6_timer.h>
     99   1.1    itojun #include <netinet6/tcp6_var.h>
    100   1.1    itojun #include <netinet6/tcp6_debug.h>
    101   1.1    itojun #else
    102   1.1    itojun #include <netinet/tcp.h>
    103   1.1    itojun #include <netinet/tcpip.h>
    104   1.1    itojun #include <netinet/tcp_seq.h>
    105   1.1    itojun /*#define TCPSTATES*/
    106   1.1    itojun #include <netinet/tcp_fsm.h>
    107   1.1    itojun extern char *tcpstates[];
    108   1.1    itojun /*#define	TCPTIMERS*/
    109   1.1    itojun #include <netinet/tcp_timer.h>
    110   1.1    itojun #include <netinet/tcp_var.h>
    111   1.1    itojun #include <netinet/tcp_debug.h>
    112   1.1    itojun #endif /*TCP6*/
    113   1.1    itojun #include <netinet6/udp6.h>
    114   1.1    itojun #include <netinet6/udp6_var.h>
    115   1.1    itojun #include <netinet6/pim6_var.h>
    116  1.23    itojun #include <netinet6/raw_ip6.h>
    117   1.1    itojun 
    118   1.1    itojun #include <arpa/inet.h>
    119   1.1    itojun #if 0
    120   1.1    itojun #include "gethostbyname2.h"
    121   1.1    itojun #endif
    122   1.1    itojun #include <netdb.h>
    123   1.1    itojun 
    124  1.34    rpaulo #include <kvm.h>
    125   1.1    itojun #include <stdio.h>
    126   1.1    itojun #include <string.h>
    127   1.1    itojun #include <unistd.h>
    128   1.1    itojun #include "netstat.h"
    129   1.1    itojun 
    130   1.1    itojun #ifdef INET6
    131   1.1    itojun 
    132   1.1    itojun struct	in6pcb in6pcb;
    133   1.1    itojun #ifdef TCP6
    134   1.1    itojun struct	tcp6cb tcp6cb;
    135   1.1    itojun #else
    136   1.1    itojun struct	tcpcb tcpcb;
    137   1.1    itojun #endif
    138   1.1    itojun struct	socket sockb;
    139   1.1    itojun 
    140   1.1    itojun char	*inet6name __P((struct in6_addr *));
    141   1.1    itojun void	inet6print __P((struct in6_addr *, int, char *));
    142   1.1    itojun 
    143   1.1    itojun /*
    144   1.1    itojun  * Print a summary of connections related to an Internet
    145   1.1    itojun  * protocol.  For TCP, also give state of connection.
    146   1.1    itojun  * Listening processes (aflag) are suppressed unless the
    147   1.1    itojun  * -a (all) flag is specified.
    148   1.1    itojun  */
    149   1.1    itojun void
    150   1.1    itojun ip6protopr(off, name)
    151   1.1    itojun 	u_long off;
    152   1.1    itojun 	char *name;
    153   1.1    itojun {
    154  1.29    itojun 	struct inpcbtable table;
    155  1.29    itojun 	struct in6pcb *head, *prev, *next;
    156   1.1    itojun 	int istcp;
    157   1.1    itojun 	static int first = 1;
    158  1.13        is 	int width = 22;
    159  1.29    itojun 
    160   1.1    itojun 	if (off == 0)
    161   1.1    itojun 		return;
    162   1.1    itojun 	istcp = strcmp(name, "tcp6") == 0;
    163  1.29    itojun 	kread(off, (char *)&table, sizeof (table));
    164  1.29    itojun 	head = prev =
    165  1.29    itojun 	    (struct in6pcb *)&((struct inpcbtable *)off)->inpt_queue.cqh_first;
    166  1.29    itojun 	next = (struct in6pcb *)table.inpt_queue.cqh_first;
    167  1.29    itojun 	while (next != head) {
    168  1.29    itojun 		kread((u_long)next, (char *)&in6pcb, sizeof in6pcb);
    169  1.29    itojun 		if ((struct in6pcb *)in6pcb.in6p_queue.cqe_prev != prev) {
    170   1.1    itojun 			printf("???\n");
    171   1.1    itojun 			break;
    172   1.1    itojun 		}
    173  1.29    itojun 		prev = next;
    174  1.29    itojun 		next = (struct in6pcb *)in6pcb.in6p_queue.cqe_next;
    175  1.29    itojun 
    176  1.29    itojun 		if (in6pcb.in6p_af != AF_INET6)
    177  1.29    itojun 			continue;
    178  1.29    itojun 
    179  1.30    itojun 		if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr))
    180   1.1    itojun 			continue;
    181   1.1    itojun 		kread((u_long)in6pcb.in6p_socket, (char *)&sockb, sizeof (sockb));
    182   1.1    itojun 		if (istcp) {
    183   1.1    itojun #ifdef TCP6
    184   1.1    itojun 			kread((u_long)in6pcb.in6p_ppcb,
    185   1.1    itojun 			    (char *)&tcp6cb, sizeof (tcp6cb));
    186   1.1    itojun #else
    187   1.1    itojun 			kread((u_long)in6pcb.in6p_ppcb,
    188   1.1    itojun 			    (char *)&tcpcb, sizeof (tcpcb));
    189   1.1    itojun #endif
    190   1.1    itojun 		}
    191   1.1    itojun 		if (first) {
    192   1.1    itojun 			printf("Active Internet6 connections");
    193   1.1    itojun 			if (aflag)
    194   1.1    itojun 				printf(" (including servers)");
    195   1.1    itojun 			putchar('\n');
    196  1.13        is 			if (Aflag) {
    197   1.1    itojun 				printf("%-8.8s ", "PCB");
    198  1.13        is 				width = 18;
    199  1.13        is 			}
    200  1.13        is 			printf( "%-5.5s %-6.6s %-6.6s  %*.*s %*.*s %s\n",
    201   1.1    itojun 				"Proto", "Recv-Q", "Send-Q",
    202  1.13        is 				-width, width, "Local Address",
    203  1.13        is 				-width, width, "Foreign Address",
    204  1.13        is 				"(state)");
    205   1.1    itojun 			first = 0;
    206   1.1    itojun 		}
    207   1.1    itojun 		if (Aflag) {
    208   1.1    itojun 			if (istcp)
    209  1.22   thorpej 				printf("%8lx ", (u_long) in6pcb.in6p_ppcb);
    210   1.1    itojun 			else
    211  1.33    atatat 				printf("%8lx ", (u_long) prev);
    212   1.1    itojun 		}
    213   1.1    itojun 		printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
    214   1.1    itojun 			sockb.so_snd.sb_cc);
    215   1.1    itojun 		/* xxx */
    216   1.1    itojun 		inet6print(&in6pcb.in6p_laddr, (int)in6pcb.in6p_lport, name);
    217   1.1    itojun 		inet6print(&in6pcb.in6p_faddr, (int)in6pcb.in6p_fport, name);
    218   1.1    itojun 		if (istcp) {
    219   1.1    itojun #ifdef TCP6
    220   1.1    itojun 			if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
    221   1.1    itojun 				printf(" %d", tcp6cb.t_state);
    222   1.1    itojun 			else
    223   1.1    itojun 				printf(" %s", tcp6states[tcp6cb.t_state]);
    224   1.1    itojun #else
    225   1.1    itojun 			if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
    226   1.1    itojun 				printf(" %d", tcpcb.t_state);
    227   1.1    itojun 			else
    228   1.1    itojun 				printf(" %s", tcpstates[tcpcb.t_state]);
    229   1.1    itojun #endif
    230   1.1    itojun 		}
    231   1.1    itojun 		putchar('\n');
    232   1.1    itojun 	}
    233   1.1    itojun }
    234   1.1    itojun 
    235   1.1    itojun #ifdef TCP6
    236   1.1    itojun /*
    237   1.1    itojun  * Dump TCP6 statistics structure.
    238   1.1    itojun  */
    239   1.1    itojun void
    240   1.1    itojun tcp6_stats(off, name)
    241   1.1    itojun 	u_long off;
    242   1.1    itojun 	char *name;
    243   1.1    itojun {
    244   1.1    itojun 	struct tcp6stat tcp6stat;
    245   1.1    itojun 
    246   1.1    itojun 	if (off == 0)
    247   1.1    itojun 		return;
    248   1.1    itojun 	printf ("%s:\n", name);
    249   1.1    itojun 	kread(off, (char *)&tcp6stat, sizeof (tcp6stat));
    250   1.1    itojun 
    251   1.1    itojun #define	p(f, m) if (tcp6stat.f || sflag <= 1) \
    252   1.1    itojun     printf(m, tcp6stat.f, plural(tcp6stat.f))
    253   1.1    itojun #define	p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \
    254   1.1    itojun     printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, plural(tcp6stat.f2))
    255   1.1    itojun #define	p3(f, m) if (tcp6stat.f || sflag <= 1) \
    256   1.1    itojun     printf(m, tcp6stat.f, plurales(tcp6stat.f))
    257   1.1    itojun 
    258   1.1    itojun 	p(tcp6s_sndtotal, "\t%ld packet%s sent\n");
    259   1.1    itojun 	p2(tcp6s_sndpack,tcp6s_sndbyte,
    260   1.1    itojun 		"\t\t%ld data packet%s (%ld byte%s)\n");
    261   1.1    itojun 	p2(tcp6s_sndrexmitpack, tcp6s_sndrexmitbyte,
    262   1.1    itojun 		"\t\t%ld data packet%s (%ld byte%s) retransmitted\n");
    263   1.1    itojun 	p2(tcp6s_sndacks, tcp6s_delack,
    264   1.1    itojun 		"\t\t%ld ack-only packet%s (%ld packet%s delayed)\n");
    265   1.1    itojun 	p(tcp6s_sndurg, "\t\t%ld URG only packet%s\n");
    266   1.1    itojun 	p(tcp6s_sndprobe, "\t\t%ld window probe packet%s\n");
    267   1.1    itojun 	p(tcp6s_sndwinup, "\t\t%ld window update packet%s\n");
    268   1.1    itojun 	p(tcp6s_sndctrl, "\t\t%ld control packet%s\n");
    269   1.1    itojun 	p(tcp6s_rcvtotal, "\t%ld packet%s received\n");
    270   1.1    itojun 	p2(tcp6s_rcvackpack, tcp6s_rcvackbyte, "\t\t%ld ack%s (for %ld byte%s)\n");
    271   1.1    itojun 	p(tcp6s_rcvdupack, "\t\t%ld duplicate ack%s\n");
    272   1.1    itojun 	p(tcp6s_rcvacktoomuch, "\t\t%ld ack%s for unsent data\n");
    273   1.1    itojun 	p2(tcp6s_rcvpack, tcp6s_rcvbyte,
    274   1.1    itojun 		"\t\t%ld packet%s (%ld byte%s) received in-sequence\n");
    275   1.1    itojun 	p2(tcp6s_rcvduppack, tcp6s_rcvdupbyte,
    276   1.1    itojun 		"\t\t%ld completely duplicate packet%s (%ld byte%s)\n");
    277   1.1    itojun 	p(tcp6s_pawsdrop, "\t\t%ld old duplicate packet%s\n");
    278   1.1    itojun 	p2(tcp6s_rcvpartduppack, tcp6s_rcvpartdupbyte,
    279   1.1    itojun 		"\t\t%ld packet%s with some dup. data (%ld byte%s duped)\n");
    280   1.1    itojun 	p2(tcp6s_rcvoopack, tcp6s_rcvoobyte,
    281   1.1    itojun 		"\t\t%ld out-of-order packet%s (%ld byte%s)\n");
    282   1.1    itojun 	p2(tcp6s_rcvpackafterwin, tcp6s_rcvbyteafterwin,
    283   1.1    itojun 		"\t\t%ld packet%s (%ld byte%s) of data after window\n");
    284   1.1    itojun 	p(tcp6s_rcvwinprobe, "\t\t%ld window probe%s\n");
    285   1.1    itojun 	p(tcp6s_rcvwinupd, "\t\t%ld window update packet%s\n");
    286   1.1    itojun 	p(tcp6s_rcvafterclose, "\t\t%ld packet%s received after close\n");
    287   1.1    itojun 	p(tcp6s_rcvbadsum, "\t\t%ld discarded for bad checksum%s\n");
    288   1.1    itojun 	p(tcp6s_rcvbadoff, "\t\t%ld discarded for bad header offset field%s\n");
    289   1.1    itojun 	p(tcp6s_rcvshort, "\t\t%ld discarded because packet%s too short\n");
    290   1.1    itojun 	p(tcp6s_connattempt, "\t%ld connection request%s\n");
    291   1.1    itojun 	p(tcp6s_accepts, "\t%ld connection accept%s\n");
    292   1.1    itojun 	p(tcp6s_badsyn, "\t%ld bad connection attempt%s\n");
    293   1.1    itojun 	p(tcp6s_connects, "\t%ld connection%s established (including accepts)\n");
    294   1.1    itojun 	p2(tcp6s_closed, tcp6s_drops,
    295   1.1    itojun 		"\t%ld connection%s closed (including %ld drop%s)\n");
    296   1.1    itojun 	p(tcp6s_conndrops, "\t%ld embryonic connection%s dropped\n");
    297   1.1    itojun 	p2(tcp6s_rttupdated, tcp6s_segstimed,
    298   1.1    itojun 		"\t%ld segment%s updated rtt (of %ld attempt%s)\n");
    299   1.1    itojun 	p(tcp6s_rexmttimeo, "\t%ld retransmit timeout%s\n");
    300   1.1    itojun 	p(tcp6s_timeoutdrop, "\t\t%ld connection%s dropped by rexmit timeout\n");
    301   1.1    itojun 	p(tcp6s_persisttimeo, "\t%ld persist timeout%s\n");
    302   1.1    itojun 	p(tcp6s_persistdrop, "\t%ld connection%s timed out in persist\n");
    303   1.1    itojun 	p(tcp6s_keeptimeo, "\t%ld keepalive timeout%s\n");
    304   1.1    itojun 	p(tcp6s_keepprobe, "\t\t%ld keepalive probe%s sent\n");
    305   1.1    itojun 	p(tcp6s_keepdrops, "\t\t%ld connection%s dropped by keepalive\n");
    306   1.1    itojun 	p(tcp6s_predack, "\t%ld correct ACK header prediction%s\n");
    307   1.1    itojun 	p(tcp6s_preddat, "\t%ld correct data packet header prediction%s\n");
    308   1.1    itojun 	p3(tcp6s_pcbcachemiss, "\t%ld PCB cache miss%s\n");
    309   1.1    itojun #undef p
    310   1.1    itojun #undef p2
    311   1.1    itojun #undef p3
    312   1.1    itojun }
    313   1.1    itojun #endif
    314   1.1    itojun 
    315   1.1    itojun /*
    316   1.1    itojun  * Dump UDP6 statistics structure.
    317   1.1    itojun  */
    318   1.1    itojun void
    319   1.1    itojun udp6_stats(off, name)
    320   1.1    itojun 	u_long off;
    321   1.1    itojun 	char *name;
    322   1.1    itojun {
    323   1.1    itojun 	struct udp6stat udp6stat;
    324   1.4    bouyer 	u_quad_t delivered;
    325   1.1    itojun 
    326   1.1    itojun 	if (off == 0)
    327   1.1    itojun 		return;
    328   1.1    itojun 	kread(off, (char *)&udp6stat, sizeof (udp6stat));
    329   1.1    itojun 	printf("%s:\n", name);
    330   1.1    itojun #define	p(f, m) if (udp6stat.f || sflag <= 1) \
    331   1.4    bouyer     printf(m, (unsigned long long)udp6stat.f, plural(udp6stat.f))
    332   1.1    itojun #define	p1(f, m) if (udp6stat.f || sflag <= 1) \
    333   1.4    bouyer     printf(m, (unsigned long long)udp6stat.f)
    334   1.4    bouyer 	p(udp6s_ipackets, "\t%llu datagram%s received\n");
    335   1.4    bouyer 	p1(udp6s_hdrops, "\t%llu with incomplete header\n");
    336   1.4    bouyer 	p1(udp6s_badlen, "\t%llu with bad data length field\n");
    337   1.4    bouyer 	p1(udp6s_badsum, "\t%llu with bad checksum\n");
    338   1.4    bouyer 	p1(udp6s_nosum, "\t%llu with no checksum\n");
    339   1.4    bouyer 	p1(udp6s_noport, "\t%llu dropped due to no socket\n");
    340   1.7    itojun 	p(udp6s_noportmcast,
    341   1.7    itojun 	    "\t%llu multicast datagram%s dropped due to no socket\n");
    342   1.4    bouyer 	p1(udp6s_fullsock, "\t%llu dropped due to full socket buffers\n");
    343   1.1    itojun 	delivered = udp6stat.udp6s_ipackets -
    344   1.1    itojun 		    udp6stat.udp6s_hdrops -
    345   1.1    itojun 		    udp6stat.udp6s_badlen -
    346   1.1    itojun 		    udp6stat.udp6s_badsum -
    347   1.1    itojun 		    udp6stat.udp6s_noport -
    348   1.1    itojun 		    udp6stat.udp6s_noportmcast -
    349   1.1    itojun 		    udp6stat.udp6s_fullsock;
    350   1.1    itojun 	if (delivered || sflag <= 1)
    351   1.4    bouyer 		printf("\t%llu delivered\n", (unsigned long long)delivered);
    352   1.4    bouyer 	p(udp6s_opackets, "\t%llu datagram%s output\n");
    353   1.1    itojun #undef p
    354   1.1    itojun #undef p1
    355   1.1    itojun }
    356   1.1    itojun 
    357   1.1    itojun static	char *ip6nh[] = {
    358  1.16    itojun /*0*/	"hop by hop",
    359   1.1    itojun 	"ICMP",
    360   1.1    itojun 	"IGMP",
    361  1.16    itojun 	NULL,
    362   1.1    itojun 	"IP",
    363  1.16    itojun /*5*/	NULL,
    364   1.1    itojun 	"TCP",
    365  1.16    itojun 	NULL,
    366  1.16    itojun 	NULL,
    367  1.16    itojun 	NULL,
    368  1.16    itojun /*10*/	NULL, NULL, NULL, NULL, NULL,
    369  1.16    itojun /*15*/	NULL,
    370  1.16    itojun 	NULL,
    371   1.1    itojun 	"UDP",
    372  1.16    itojun 	NULL,
    373  1.16    itojun 	NULL,
    374  1.16    itojun /*20*/	NULL,
    375  1.16    itojun 	NULL,
    376   1.1    itojun 	"IDP",
    377  1.16    itojun 	NULL,
    378  1.16    itojun 	NULL,
    379  1.16    itojun /*25*/	NULL,
    380  1.16    itojun 	NULL,
    381  1.16    itojun 	NULL,
    382  1.16    itojun 	NULL,
    383  1.16    itojun 	"TP",
    384  1.16    itojun /*30*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    385  1.16    itojun /*40*/	NULL,
    386   1.1    itojun 	"IP6",
    387  1.16    itojun 	NULL,
    388   1.1    itojun 	"routing",
    389   1.1    itojun 	"fragment",
    390  1.16    itojun /*45*/	NULL, NULL, NULL, NULL, NULL,
    391  1.16    itojun /*50*/	"ESP",
    392   1.1    itojun 	"AH",
    393  1.16    itojun 	NULL,
    394  1.16    itojun 	NULL,
    395  1.16    itojun 	NULL,
    396  1.16    itojun /*55*/	NULL,
    397  1.16    itojun 	NULL,
    398  1.16    itojun 	NULL,
    399   1.1    itojun 	"ICMP6",
    400  1.16    itojun 	"no next header",
    401  1.16    itojun /*60*/	"destination option",
    402  1.16    itojun 	NULL,
    403  1.16    itojun 	NULL,
    404  1.16    itojun 	NULL,
    405  1.16    itojun 	NULL,
    406  1.16    itojun /*65*/	NULL, NULL, NULL, NULL, NULL,
    407  1.16    itojun /*70*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    408  1.16    itojun /*80*/	"ISOIP",
    409  1.16    itojun 	NULL,
    410  1.16    itojun 	NULL,
    411  1.16    itojun 	NULL,
    412  1.16    itojun 	NULL,
    413  1.16    itojun 	NULL,
    414  1.16    itojun 	NULL,
    415  1.16    itojun 	NULL,
    416  1.16    itojun 	NULL,
    417  1.16    itojun 	"OSPF",
    418  1.16    itojun /*90*/	NULL, NULL, NULL, NULL, NULL,
    419  1.16    itojun /*95*/	NULL,
    420  1.16    itojun 	NULL,
    421   1.1    itojun 	"Ethernet",
    422  1.16    itojun 	NULL,
    423  1.16    itojun 	NULL,
    424  1.16    itojun /*100*/	NULL,
    425  1.16    itojun 	NULL,
    426  1.16    itojun 	NULL,
    427   1.1    itojun 	"PIM",
    428  1.16    itojun 	NULL,
    429  1.16    itojun /*105*/	NULL, NULL, NULL, NULL, NULL,
    430  1.16    itojun /*110*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    431  1.16    itojun /*120*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    432  1.18    itojun /*130*/	NULL,
    433  1.18    itojun 	NULL,
    434  1.18    itojun 	"SCTP",
    435  1.18    itojun 	NULL,
    436  1.18    itojun 	NULL,
    437  1.18    itojun /*135*/	NULL, NULL, NULL, NULL, NULL,
    438  1.16    itojun /*140*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    439  1.16    itojun 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    440  1.16    itojun /*160*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    441  1.16    itojun 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    442  1.16    itojun /*180*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    443  1.16    itojun 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    444  1.16    itojun /*200*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    445  1.16    itojun 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    446  1.16    itojun /*220*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    447  1.16    itojun 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    448  1.16    itojun /*240*/	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    449  1.16    itojun 	NULL, NULL, NULL, NULL, NULL, NULL,
    450   1.1    itojun };
    451   1.1    itojun 
    452   1.1    itojun /*
    453   1.1    itojun  * Dump IP6 statistics structure.
    454   1.1    itojun  */
    455   1.1    itojun void
    456   1.1    itojun ip6_stats(off, name)
    457   1.1    itojun 	u_long off;
    458   1.1    itojun 	char *name;
    459   1.1    itojun {
    460   1.1    itojun 	struct ip6stat ip6stat;
    461   1.1    itojun 	int first, i;
    462  1.16    itojun 	struct protoent *ep;
    463  1.16    itojun 	const char *n;
    464   1.1    itojun 
    465   1.1    itojun 	if (off == 0)
    466   1.1    itojun 		return;
    467   1.1    itojun 
    468   1.1    itojun 	kread(off, (char *)&ip6stat, sizeof (ip6stat));
    469   1.1    itojun 	printf("%s:\n", name);
    470   1.1    itojun 
    471   1.1    itojun #define	p(f, m) if (ip6stat.f || sflag <= 1) \
    472   1.4    bouyer     printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f))
    473   1.1    itojun #define	p1(f, m) if (ip6stat.f || sflag <= 1) \
    474   1.4    bouyer     printf(m, (unsigned long long)ip6stat.f)
    475   1.1    itojun 
    476   1.4    bouyer 	p(ip6s_total, "\t%llu total packet%s received\n");
    477   1.4    bouyer 	p1(ip6s_toosmall, "\t%llu with size smaller than minimum\n");
    478   1.4    bouyer 	p1(ip6s_tooshort, "\t%llu with data size < data length\n");
    479   1.4    bouyer 	p1(ip6s_badoptions, "\t%llu with bad options\n");
    480   1.4    bouyer 	p1(ip6s_badvers, "\t%llu with incorrect version number\n");
    481   1.4    bouyer 	p(ip6s_fragments, "\t%llu fragment%s received\n");
    482   1.4    bouyer 	p(ip6s_fragdropped,
    483   1.7    itojun 	    "\t%llu fragment%s dropped (dup or out of space)\n");
    484   1.4    bouyer 	p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n");
    485   1.4    bouyer 	p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n");
    486   1.4    bouyer 	p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n");
    487   1.4    bouyer 	p(ip6s_delivered, "\t%llu packet%s for this host\n");
    488   1.4    bouyer 	p(ip6s_forward, "\t%llu packet%s forwarded\n");
    489   1.4    bouyer 	p(ip6s_cantforward, "\t%llu packet%s not forwardable\n");
    490   1.4    bouyer 	p(ip6s_redirectsent, "\t%llu redirect%s sent\n");
    491   1.4    bouyer 	p(ip6s_localout, "\t%llu packet%s sent from this host\n");
    492   1.4    bouyer 	p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n");
    493   1.4    bouyer 	p(ip6s_odropped,
    494   1.7    itojun 	    "\t%llu output packet%s dropped due to no bufs, etc.\n");
    495   1.4    bouyer 	p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n");
    496   1.4    bouyer 	p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n");
    497   1.4    bouyer 	p(ip6s_ofragments, "\t%llu fragment%s created\n");
    498   1.4    bouyer 	p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n");
    499   1.4    bouyer 	p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n");
    500   1.4    bouyer 	p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n");
    501   1.1    itojun 	for (first = 1, i = 0; i < 256; i++)
    502   1.1    itojun 		if (ip6stat.ip6s_nxthist[i] != 0) {
    503   1.1    itojun 			if (first) {
    504  1.17    itojun 				printf("\tInput packet histogram:\n");
    505   1.1    itojun 				first = 0;
    506   1.1    itojun 			}
    507  1.16    itojun 			n = NULL;
    508  1.16    itojun 			if (ip6nh[i])
    509  1.16    itojun 				n = ip6nh[i];
    510  1.16    itojun 			else if ((ep = getprotobynumber(i)) != NULL)
    511  1.16    itojun 				n = ep->p_name;
    512  1.16    itojun 			if (n)
    513  1.16    itojun 				printf("\t\t%s: %llu\n", n,
    514  1.16    itojun 				    (unsigned long long)ip6stat.ip6s_nxthist[i]);
    515  1.16    itojun 			else
    516  1.16    itojun 				printf("\t\t#%d: %llu\n", i,
    517  1.16    itojun 				    (unsigned long long)ip6stat.ip6s_nxthist[i]);
    518   1.1    itojun 		}
    519  1.12     jhawk 	printf("\tMbuf statistics:\n");
    520  1.12     jhawk 	p(ip6s_m1, "\t\t%llu one mbuf%s\n");
    521   1.1    itojun 	for (first = 1, i = 0; i < 32; i++) {
    522   1.1    itojun 		char ifbuf[IFNAMSIZ];
    523   1.1    itojun 		if (ip6stat.ip6s_m2m[i] != 0) {
    524   1.1    itojun 			if (first) {
    525   1.1    itojun 				printf("\t\ttwo or more mbuf:\n");
    526   1.1    itojun 				first = 0;
    527   1.1    itojun 			}
    528   1.4    bouyer 			printf("\t\t\t%s = %llu\n",
    529   1.1    itojun 			       if_indextoname(i, ifbuf),
    530   1.4    bouyer 			       (unsigned long long)ip6stat.ip6s_m2m[i]);
    531   1.1    itojun 		}
    532   1.1    itojun 	}
    533  1.16    itojun 	p(ip6s_mext1, "\t\t%llu one ext mbuf%s\n");
    534  1.12     jhawk 	p(ip6s_mext2m, "\t\t%llu two or more ext mbuf%s\n");
    535   1.4    bouyer 	p(ip6s_exthdrtoolong,
    536   1.7    itojun 	    "\t%llu packet%s whose headers are not continuous\n");
    537   1.4    bouyer 	p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n");
    538   1.7    itojun 	p(ip6s_toomanyhdr,
    539   1.7    itojun 	    "\t%llu packet%s discarded due to too many headers\n");
    540   1.7    itojun 
    541   1.7    itojun 	/* for debugging source address selection */
    542   1.7    itojun #define PRINT_SCOPESTAT(s,i) do {\
    543   1.7    itojun 		switch(i) { /* XXX hardcoding in each case */\
    544   1.7    itojun 		case 1:\
    545   1.7    itojun 			p(s, "\t\t%llu node-local%s\n");\
    546   1.7    itojun 			break;\
    547   1.7    itojun 		case 2:\
    548   1.7    itojun 			p(s, "\t\t%llu link-local%s\n");\
    549   1.7    itojun 			break;\
    550   1.7    itojun 		case 5:\
    551   1.7    itojun 			p(s, "\t\t%llu site-local%s\n");\
    552   1.7    itojun 			break;\
    553   1.7    itojun 		case 14:\
    554   1.7    itojun 			p(s, "\t\t%llu global%s\n");\
    555   1.7    itojun 			break;\
    556   1.7    itojun 		default:\
    557   1.7    itojun 			printf("\t\t%llu addresses scope=%x\n",\
    558   1.7    itojun 			       (unsigned long long)ip6stat.s, i);\
    559   1.7    itojun 		}\
    560   1.7    itojun 	} while(0);
    561   1.7    itojun 
    562   1.7    itojun 	p(ip6s_sources_none,
    563   1.7    itojun 	  "\t%llu failure%s of source address selection\n");
    564   1.7    itojun 	for (first = 1, i = 0; i < 16; i++) {
    565   1.7    itojun 		if (ip6stat.ip6s_sources_sameif[i]) {
    566   1.7    itojun 			if (first) {
    567   1.7    itojun 				printf("\tsource addresses on an outgoing I/F\n");
    568   1.7    itojun 				first = 0;
    569   1.7    itojun 			}
    570   1.7    itojun 			PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
    571   1.7    itojun 		}
    572   1.7    itojun 	}
    573   1.7    itojun 	for (first = 1, i = 0; i < 16; i++) {
    574   1.7    itojun 		if (ip6stat.ip6s_sources_otherif[i]) {
    575   1.7    itojun 			if (first) {
    576   1.7    itojun 				printf("\tsource addresses on a non-outgoing I/F\n");
    577   1.7    itojun 				first = 0;
    578   1.7    itojun 			}
    579   1.7    itojun 			PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
    580   1.7    itojun 		}
    581   1.7    itojun 	}
    582   1.7    itojun 	for (first = 1, i = 0; i < 16; i++) {
    583   1.7    itojun 		if (ip6stat.ip6s_sources_samescope[i]) {
    584   1.7    itojun 			if (first) {
    585   1.7    itojun 				printf("\tsource addresses of same scope\n");
    586   1.7    itojun 				first = 0;
    587   1.7    itojun 			}
    588   1.7    itojun 			PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
    589   1.7    itojun 		}
    590   1.7    itojun 	}
    591   1.7    itojun 	for (first = 1, i = 0; i < 16; i++) {
    592   1.7    itojun 		if (ip6stat.ip6s_sources_otherscope[i]) {
    593   1.7    itojun 			if (first) {
    594   1.7    itojun 				printf("\tsource addresses of a different scope\n");
    595   1.7    itojun 				first = 0;
    596   1.7    itojun 			}
    597   1.7    itojun 			PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
    598   1.7    itojun 		}
    599   1.7    itojun 	}
    600   1.7    itojun 	for (first = 1, i = 0; i < 16; i++) {
    601   1.7    itojun 		if (ip6stat.ip6s_sources_deprecated[i]) {
    602   1.7    itojun 			if (first) {
    603   1.7    itojun 				printf("\tdeprecated source addresses\n");
    604   1.7    itojun 				first = 0;
    605   1.7    itojun 			}
    606   1.7    itojun 			PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
    607   1.7    itojun 		}
    608   1.5    itojun 	}
    609  1.10    itojun 
    610  1.10    itojun 	p1(ip6s_forward_cachehit, "\t%llu forward cache hit\n");
    611  1.10    itojun 	p1(ip6s_forward_cachemiss, "\t%llu forward cache miss\n");
    612   1.1    itojun #undef p
    613   1.1    itojun #undef p1
    614   1.1    itojun }
    615   1.1    itojun 
    616   1.5    itojun /*
    617   1.5    itojun  * Dump IPv6 per-interface statistics based on RFC 2465.
    618   1.5    itojun  */
    619   1.5    itojun void
    620   1.5    itojun ip6_ifstats(ifname)
    621   1.5    itojun 	char *ifname;
    622   1.5    itojun {
    623   1.5    itojun 	struct in6_ifreq ifr;
    624   1.5    itojun 	int s;
    625   1.5    itojun #define	p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
    626   1.6   thorpej     printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, \
    627   1.7    itojun 	plural(ifr.ifr_ifru.ifru_stat.f))
    628   1.5    itojun #define	p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
    629  1.10    itojun     printf(m, (unsigned long long)ip6stat.f)
    630   1.5    itojun 
    631   1.5    itojun 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
    632   1.5    itojun 		perror("Warning: socket(AF_INET6)");
    633   1.5    itojun 		return;
    634   1.5    itojun 	}
    635   1.5    itojun 
    636  1.19    itojun 	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
    637  1.19    itojun 	printf("ip6 on %s:\n", ifname);
    638   1.5    itojun 
    639   1.5    itojun 	if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
    640   1.5    itojun 		perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
    641   1.5    itojun 		goto end;
    642   1.5    itojun 	}
    643   1.5    itojun 
    644   1.5    itojun 	p(ifs6_in_receive, "\t%llu total input datagram%s\n");
    645   1.5    itojun 	p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n");
    646   1.5    itojun 	p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n");
    647   1.5    itojun 	p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n");
    648   1.5    itojun 	p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n");
    649   1.5    itojun 	p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
    650   1.5    itojun 	p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n");
    651   1.5    itojun 	p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
    652   1.5    itojun 	p(ifs6_in_deliver,
    653   1.5    itojun 	  "\t%llu datagram%s delivered to an upper layer protocol\n");
    654   1.5    itojun 	p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n");
    655   1.5    itojun 	p(ifs6_out_request,
    656   1.5    itojun 	  "\t%llu datagram%s sent from an upper layer protocol\n");
    657   1.5    itojun 	p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n");
    658   1.5    itojun 	p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n");
    659   1.5    itojun 	p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n");
    660   1.5    itojun 	p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n");
    661   1.5    itojun 	p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n");
    662   1.5    itojun 	p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n");
    663   1.5    itojun 	p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n");
    664   1.5    itojun 	p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n");
    665   1.5    itojun 	p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n");
    666   1.5    itojun 
    667   1.5    itojun   end:
    668   1.5    itojun 	close(s);
    669   1.5    itojun 
    670   1.5    itojun #undef p
    671   1.5    itojun #undef p_5
    672   1.5    itojun }
    673   1.5    itojun 
    674   1.1    itojun static	char *icmp6names[] = {
    675   1.1    itojun 	"#0",
    676   1.1    itojun 	"unreach",
    677   1.1    itojun 	"packet too big",
    678   1.1    itojun 	"time exceed",
    679   1.1    itojun 	"parameter problem",
    680   1.1    itojun 	"#5",
    681   1.1    itojun 	"#6",
    682   1.1    itojun 	"#7",
    683   1.1    itojun 	"#8",
    684   1.1    itojun 	"#9",
    685   1.1    itojun 	"#10",
    686   1.1    itojun 	"#11",
    687   1.1    itojun 	"#12",
    688   1.1    itojun 	"#13",
    689   1.1    itojun 	"#14",
    690   1.1    itojun 	"#15",
    691   1.1    itojun 	"#16",
    692   1.1    itojun 	"#17",
    693   1.1    itojun 	"#18",
    694   1.1    itojun 	"#19",
    695   1.1    itojun 	"#20",
    696   1.1    itojun 	"#21",
    697   1.1    itojun 	"#22",
    698   1.1    itojun 	"#23",
    699   1.1    itojun 	"#24",
    700   1.1    itojun 	"#25",
    701   1.1    itojun 	"#26",
    702   1.1    itojun 	"#27",
    703   1.1    itojun 	"#28",
    704   1.1    itojun 	"#29",
    705   1.1    itojun 	"#30",
    706   1.1    itojun 	"#31",
    707   1.1    itojun 	"#32",
    708   1.1    itojun 	"#33",
    709   1.1    itojun 	"#34",
    710   1.1    itojun 	"#35",
    711   1.1    itojun 	"#36",
    712   1.1    itojun 	"#37",
    713   1.1    itojun 	"#38",
    714   1.1    itojun 	"#39",
    715   1.1    itojun 	"#40",
    716   1.1    itojun 	"#41",
    717   1.1    itojun 	"#42",
    718   1.1    itojun 	"#43",
    719   1.1    itojun 	"#44",
    720   1.1    itojun 	"#45",
    721   1.1    itojun 	"#46",
    722   1.1    itojun 	"#47",
    723   1.1    itojun 	"#48",
    724   1.1    itojun 	"#49",
    725   1.1    itojun 	"#50",
    726   1.1    itojun 	"#51",
    727   1.1    itojun 	"#52",
    728   1.1    itojun 	"#53",
    729   1.1    itojun 	"#54",
    730   1.1    itojun 	"#55",
    731   1.1    itojun 	"#56",
    732   1.1    itojun 	"#57",
    733   1.1    itojun 	"#58",
    734   1.1    itojun 	"#59",
    735   1.1    itojun 	"#60",
    736   1.1    itojun 	"#61",
    737   1.1    itojun 	"#62",
    738   1.1    itojun 	"#63",
    739   1.1    itojun 	"#64",
    740   1.1    itojun 	"#65",
    741   1.1    itojun 	"#66",
    742   1.1    itojun 	"#67",
    743   1.1    itojun 	"#68",
    744   1.1    itojun 	"#69",
    745   1.1    itojun 	"#70",
    746   1.1    itojun 	"#71",
    747   1.1    itojun 	"#72",
    748   1.1    itojun 	"#73",
    749   1.1    itojun 	"#74",
    750   1.1    itojun 	"#75",
    751   1.1    itojun 	"#76",
    752   1.1    itojun 	"#77",
    753   1.1    itojun 	"#78",
    754   1.1    itojun 	"#79",
    755   1.1    itojun 	"#80",
    756   1.1    itojun 	"#81",
    757   1.1    itojun 	"#82",
    758   1.1    itojun 	"#83",
    759   1.1    itojun 	"#84",
    760   1.1    itojun 	"#85",
    761   1.1    itojun 	"#86",
    762   1.1    itojun 	"#87",
    763   1.1    itojun 	"#88",
    764   1.1    itojun 	"#89",
    765   1.1    itojun 	"#80",
    766   1.1    itojun 	"#91",
    767   1.1    itojun 	"#92",
    768   1.1    itojun 	"#93",
    769   1.1    itojun 	"#94",
    770   1.1    itojun 	"#95",
    771   1.1    itojun 	"#96",
    772   1.1    itojun 	"#97",
    773   1.1    itojun 	"#98",
    774   1.1    itojun 	"#99",
    775   1.1    itojun 	"#100",
    776   1.1    itojun 	"#101",
    777   1.1    itojun 	"#102",
    778   1.1    itojun 	"#103",
    779   1.1    itojun 	"#104",
    780   1.1    itojun 	"#105",
    781   1.1    itojun 	"#106",
    782   1.1    itojun 	"#107",
    783   1.1    itojun 	"#108",
    784   1.1    itojun 	"#109",
    785   1.1    itojun 	"#110",
    786   1.1    itojun 	"#111",
    787   1.1    itojun 	"#112",
    788   1.1    itojun 	"#113",
    789   1.1    itojun 	"#114",
    790   1.1    itojun 	"#115",
    791   1.1    itojun 	"#116",
    792   1.1    itojun 	"#117",
    793   1.1    itojun 	"#118",
    794   1.1    itojun 	"#119",
    795   1.1    itojun 	"#120",
    796   1.1    itojun 	"#121",
    797   1.1    itojun 	"#122",
    798   1.1    itojun 	"#123",
    799   1.1    itojun 	"#124",
    800   1.1    itojun 	"#125",
    801   1.1    itojun 	"#126",
    802   1.1    itojun 	"#127",
    803   1.1    itojun 	"echo",
    804   1.1    itojun 	"echo reply",
    805   1.5    itojun 	"multicast listener query",
    806   1.5    itojun 	"multicast listener report",
    807   1.5    itojun 	"multicast listener done",
    808   1.1    itojun 	"router solicitation",
    809  1.21    itojun 	"router advertisement",
    810   1.1    itojun 	"neighbor solicitation",
    811  1.21    itojun 	"neighbor advertisement",
    812   1.1    itojun 	"redirect",
    813   1.1    itojun 	"router renumbering",
    814   1.1    itojun 	"node information request",
    815   1.1    itojun 	"node information reply",
    816   1.1    itojun 	"#141",
    817   1.1    itojun 	"#142",
    818   1.1    itojun 	"#143",
    819   1.1    itojun 	"#144",
    820   1.1    itojun 	"#145",
    821   1.1    itojun 	"#146",
    822   1.1    itojun 	"#147",
    823   1.1    itojun 	"#148",
    824   1.1    itojun 	"#149",
    825   1.1    itojun 	"#150",
    826   1.1    itojun 	"#151",
    827   1.1    itojun 	"#152",
    828   1.1    itojun 	"#153",
    829   1.1    itojun 	"#154",
    830   1.1    itojun 	"#155",
    831   1.1    itojun 	"#156",
    832   1.1    itojun 	"#157",
    833   1.1    itojun 	"#158",
    834   1.1    itojun 	"#159",
    835   1.1    itojun 	"#160",
    836   1.1    itojun 	"#161",
    837   1.1    itojun 	"#162",
    838   1.1    itojun 	"#163",
    839   1.1    itojun 	"#164",
    840   1.1    itojun 	"#165",
    841   1.1    itojun 	"#166",
    842   1.1    itojun 	"#167",
    843   1.1    itojun 	"#168",
    844   1.1    itojun 	"#169",
    845   1.1    itojun 	"#170",
    846   1.1    itojun 	"#171",
    847   1.1    itojun 	"#172",
    848   1.1    itojun 	"#173",
    849   1.1    itojun 	"#174",
    850   1.1    itojun 	"#175",
    851   1.1    itojun 	"#176",
    852   1.1    itojun 	"#177",
    853   1.1    itojun 	"#178",
    854   1.1    itojun 	"#179",
    855   1.1    itojun 	"#180",
    856   1.1    itojun 	"#181",
    857   1.1    itojun 	"#182",
    858   1.1    itojun 	"#183",
    859   1.1    itojun 	"#184",
    860   1.1    itojun 	"#185",
    861   1.1    itojun 	"#186",
    862   1.1    itojun 	"#187",
    863   1.1    itojun 	"#188",
    864   1.1    itojun 	"#189",
    865   1.1    itojun 	"#180",
    866   1.1    itojun 	"#191",
    867   1.1    itojun 	"#192",
    868   1.1    itojun 	"#193",
    869   1.1    itojun 	"#194",
    870   1.1    itojun 	"#195",
    871   1.1    itojun 	"#196",
    872   1.1    itojun 	"#197",
    873   1.1    itojun 	"#198",
    874   1.1    itojun 	"#199",
    875   1.1    itojun 	"#200",
    876   1.1    itojun 	"#201",
    877   1.1    itojun 	"#202",
    878   1.1    itojun 	"#203",
    879   1.1    itojun 	"#204",
    880   1.1    itojun 	"#205",
    881   1.1    itojun 	"#206",
    882   1.1    itojun 	"#207",
    883   1.1    itojun 	"#208",
    884   1.1    itojun 	"#209",
    885   1.1    itojun 	"#210",
    886   1.1    itojun 	"#211",
    887   1.1    itojun 	"#212",
    888   1.1    itojun 	"#213",
    889   1.1    itojun 	"#214",
    890   1.1    itojun 	"#215",
    891   1.1    itojun 	"#216",
    892   1.1    itojun 	"#217",
    893   1.1    itojun 	"#218",
    894   1.1    itojun 	"#219",
    895   1.1    itojun 	"#220",
    896   1.1    itojun 	"#221",
    897   1.1    itojun 	"#222",
    898   1.1    itojun 	"#223",
    899   1.1    itojun 	"#224",
    900   1.1    itojun 	"#225",
    901   1.1    itojun 	"#226",
    902   1.1    itojun 	"#227",
    903   1.1    itojun 	"#228",
    904   1.1    itojun 	"#229",
    905   1.1    itojun 	"#230",
    906   1.1    itojun 	"#231",
    907   1.1    itojun 	"#232",
    908   1.1    itojun 	"#233",
    909   1.1    itojun 	"#234",
    910   1.1    itojun 	"#235",
    911   1.1    itojun 	"#236",
    912   1.1    itojun 	"#237",
    913   1.1    itojun 	"#238",
    914   1.1    itojun 	"#239",
    915   1.1    itojun 	"#240",
    916   1.1    itojun 	"#241",
    917   1.1    itojun 	"#242",
    918   1.1    itojun 	"#243",
    919   1.1    itojun 	"#244",
    920   1.1    itojun 	"#245",
    921   1.1    itojun 	"#246",
    922   1.1    itojun 	"#247",
    923   1.1    itojun 	"#248",
    924   1.1    itojun 	"#249",
    925   1.1    itojun 	"#250",
    926   1.1    itojun 	"#251",
    927   1.1    itojun 	"#252",
    928   1.1    itojun 	"#253",
    929   1.1    itojun 	"#254",
    930   1.1    itojun 	"#255",
    931   1.1    itojun };
    932   1.1    itojun 
    933   1.1    itojun /*
    934   1.5    itojun  * Dump ICMPv6 statistics.
    935   1.1    itojun  */
    936   1.1    itojun void
    937   1.1    itojun icmp6_stats(off, name)
    938   1.1    itojun 	u_long off;
    939   1.1    itojun 	char *name;
    940   1.1    itojun {
    941   1.1    itojun 	struct icmp6stat icmp6stat;
    942   1.1    itojun 	register int i, first;
    943   1.1    itojun 
    944   1.1    itojun 	if (off == 0)
    945   1.1    itojun 		return;
    946   1.1    itojun 	kread(off, (char *)&icmp6stat, sizeof (icmp6stat));
    947   1.1    itojun 	printf("%s:\n", name);
    948   1.1    itojun 
    949   1.1    itojun #define	p(f, m) if (icmp6stat.f || sflag <= 1) \
    950   1.4    bouyer     printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f))
    951  1.10    itojun #define p_5(f, m) if (icmp6stat.f || sflag <= 1) \
    952  1.10    itojun     printf(m, (unsigned long long)icmp6stat.f)
    953   1.1    itojun 
    954   1.8    itojun 	p(icp6s_error, "\t%llu call%s to icmp6_error\n");
    955   1.7    itojun 	p(icp6s_canterror,
    956   1.8    itojun 	    "\t%llu error%s not generated because old message was icmp6 or so\n");
    957   1.9    itojun 	p(icp6s_toofreq,
    958  1.15    itojun 	    "\t%llu error%s not generated because of rate limitation\n");
    959   1.1    itojun 	for (first = 1, i = 0; i < 256; i++)
    960   1.1    itojun 		if (icmp6stat.icp6s_outhist[i] != 0) {
    961   1.1    itojun 			if (first) {
    962  1.17    itojun 				printf("\tOutput packet histogram:\n");
    963   1.1    itojun 				first = 0;
    964   1.1    itojun 			}
    965   1.4    bouyer 			printf("\t\t%s: %llu\n", icmp6names[i],
    966   1.4    bouyer 				(unsigned long long)icmp6stat.icp6s_outhist[i]);
    967   1.1    itojun 		}
    968   1.4    bouyer 	p(icp6s_badcode, "\t%llu message%s with bad code fields\n");
    969   1.4    bouyer 	p(icp6s_tooshort, "\t%llu message%s < minimum length\n");
    970   1.4    bouyer 	p(icp6s_checksum, "\t%llu bad checksum%s\n");
    971   1.4    bouyer 	p(icp6s_badlen, "\t%llu message%s with bad length\n");
    972   1.1    itojun 	for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
    973   1.1    itojun 		if (icmp6stat.icp6s_inhist[i] != 0) {
    974   1.1    itojun 			if (first) {
    975  1.17    itojun 				printf("\tInput packet histogram:\n");
    976   1.1    itojun 				first = 0;
    977   1.1    itojun 			}
    978   1.4    bouyer 			printf("\t\t%s: %llu\n", icmp6names[i],
    979   1.4    bouyer 				(unsigned long long)icmp6stat.icp6s_inhist[i]);
    980   1.1    itojun 		}
    981  1.10    itojun 	printf("\tHistogram of error messages to be generated:\n");
    982  1.10    itojun 	p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n");
    983  1.10    itojun 	p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n");
    984  1.10    itojun 	p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n");
    985  1.10    itojun 	p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n");
    986  1.10    itojun 	p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n");
    987  1.10    itojun 	p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n");
    988  1.10    itojun 	p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n");
    989  1.10    itojun 	p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n");
    990  1.10    itojun 	p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n");
    991  1.10    itojun 	p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n");
    992  1.10    itojun 	p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n");
    993  1.10    itojun 	p_5(icp6s_oredirect, "\t\t%llu redirect\n");
    994  1.10    itojun 	p_5(icp6s_ounknown, "\t\t%llu unknown\n");
    995  1.10    itojun 
    996   1.4    bouyer 	p(icp6s_reflect, "\t%llu message response%s generated\n");
    997   1.5    itojun 	p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n");
    998  1.17    itojun 	p(icp6s_nd_badopt, "\t%llu message%s with bad ND options\n");
    999  1.17    itojun 	p(icp6s_badns, "\t%llu bad neighbor solicitation message%s\n");
   1000  1.17    itojun 	p(icp6s_badna, "\t%llu bad neighbor advertisement message%s\n");
   1001  1.17    itojun 	p(icp6s_badrs, "\t%llu bad router solicitation message%s\n");
   1002  1.17    itojun 	p(icp6s_badra, "\t%llu bad router advertisement message%s\n");
   1003  1.17    itojun 	p(icp6s_badredirect, "\t%llu bad redirect message%s\n");
   1004  1.14    itojun 	p(icp6s_pmtuchg, "\t%llu path MTU change%s\n");
   1005   1.5    itojun #undef p
   1006  1.10    itojun #undef p_5
   1007   1.5    itojun }
   1008   1.5    itojun 
   1009   1.5    itojun /*
   1010   1.5    itojun  * Dump ICMPv6 per-interface statistics based on RFC 2466.
   1011   1.5    itojun  */
   1012   1.5    itojun void
   1013   1.5    itojun icmp6_ifstats(ifname)
   1014   1.5    itojun 	char *ifname;
   1015   1.5    itojun {
   1016   1.5    itojun 	struct in6_ifreq ifr;
   1017   1.5    itojun 	int s;
   1018   1.5    itojun #define	p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
   1019   1.6   thorpej     printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, \
   1020   1.7    itojun 	plural(ifr.ifr_ifru.ifru_icmp6stat.f))
   1021   1.5    itojun 
   1022   1.5    itojun 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
   1023   1.5    itojun 		perror("Warning: socket(AF_INET6)");
   1024   1.5    itojun 		return;
   1025   1.5    itojun 	}
   1026   1.5    itojun 
   1027  1.19    itojun 	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
   1028  1.19    itojun 	printf("icmp6 on %s:\n", ifname);
   1029   1.5    itojun 
   1030   1.5    itojun 	if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
   1031   1.5    itojun 		perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
   1032   1.5    itojun 		goto end;
   1033   1.5    itojun 	}
   1034   1.5    itojun 
   1035   1.5    itojun 	p(ifs6_in_msg, "\t%llu total input message%s\n");
   1036   1.5    itojun 	p(ifs6_in_error, "\t%llu total input error message%s\n");
   1037   1.5    itojun 	p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n");
   1038   1.5    itojun 	p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n");
   1039   1.5    itojun 	p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n");
   1040   1.5    itojun 	p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n");
   1041   1.5    itojun 	p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n");
   1042   1.5    itojun 	p(ifs6_in_echo, "\t%llu input echo request%s\n");
   1043   1.5    itojun 	p(ifs6_in_echoreply, "\t%llu input echo reply%s\n");
   1044   1.5    itojun 	p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n");
   1045   1.5    itojun 	p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n");
   1046   1.5    itojun 	p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n");
   1047   1.5    itojun 	p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n");
   1048   1.5    itojun 	p(ifs6_in_redirect, "\t%llu input redirect%s\n");
   1049   1.5    itojun 	p(ifs6_in_mldquery, "\t%llu input MLD query%s\n");
   1050   1.5    itojun 	p(ifs6_in_mldreport, "\t%llu input MLD report%s\n");
   1051   1.5    itojun 	p(ifs6_in_mlddone, "\t%llu input MLD done%s\n");
   1052   1.5    itojun 
   1053   1.5    itojun 	p(ifs6_out_msg, "\t%llu total output message%s\n");
   1054   1.5    itojun 	p(ifs6_out_error, "\t%llu total output error message%s\n");
   1055   1.5    itojun 	p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n");
   1056   1.5    itojun 	p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n");
   1057   1.5    itojun 	p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n");
   1058   1.5    itojun 	p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n");
   1059   1.5    itojun 	p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n");
   1060   1.5    itojun 	p(ifs6_out_echo, "\t%llu output echo request%s\n");
   1061   1.5    itojun 	p(ifs6_out_echoreply, "\t%llu output echo reply%s\n");
   1062   1.5    itojun 	p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n");
   1063   1.5    itojun 	p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n");
   1064   1.5    itojun 	p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n");
   1065   1.5    itojun 	p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n");
   1066   1.5    itojun 	p(ifs6_out_redirect, "\t%llu output redirect%s\n");
   1067   1.5    itojun 	p(ifs6_out_mldquery, "\t%llu output MLD query%s\n");
   1068   1.5    itojun 	p(ifs6_out_mldreport, "\t%llu output MLD report%s\n");
   1069   1.5    itojun 	p(ifs6_out_mlddone, "\t%llu output MLD done%s\n");
   1070   1.5    itojun 
   1071   1.5    itojun   end:
   1072   1.5    itojun 	close(s);
   1073   1.1    itojun #undef p
   1074   1.1    itojun }
   1075   1.1    itojun 
   1076   1.1    itojun /*
   1077   1.1    itojun  * Dump PIM statistics structure.
   1078   1.1    itojun  */
   1079   1.1    itojun void
   1080   1.1    itojun pim6_stats(off, name)
   1081   1.1    itojun 	u_long off;
   1082   1.1    itojun 	char *name;
   1083   1.1    itojun {
   1084   1.1    itojun 	struct pim6stat pim6stat;
   1085   1.1    itojun 
   1086   1.1    itojun 	if (off == 0)
   1087   1.1    itojun 		return;
   1088   1.1    itojun 	kread(off, (char *)&pim6stat, sizeof(pim6stat));
   1089   1.1    itojun 	printf("%s:\n", name);
   1090   1.1    itojun 
   1091   1.1    itojun #define	p(f, m) if (pim6stat.f || sflag <= 1) \
   1092   1.4    bouyer     printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f))
   1093   1.4    bouyer 	p(pim6s_rcv_total, "\t%llu message%s received\n");
   1094   1.4    bouyer 	p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n");
   1095   1.4    bouyer 	p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n");
   1096   1.4    bouyer 	p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n");
   1097   1.4    bouyer 	p(pim6s_rcv_registers, "\t%llu register%s received\n");
   1098   1.4    bouyer 	p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n");
   1099   1.4    bouyer 	p(pim6s_snd_registers, "\t%llu register%s sent\n");
   1100  1.23    itojun #undef p
   1101  1.23    itojun }
   1102  1.23    itojun 
   1103  1.23    itojun /*
   1104  1.23    itojun  * Dump raw ip6 statistics structure.
   1105  1.23    itojun  */
   1106  1.23    itojun void
   1107  1.23    itojun rip6_stats(off, name)
   1108  1.23    itojun 	u_long off;
   1109  1.23    itojun 	char *name;
   1110  1.23    itojun {
   1111  1.23    itojun 	struct rip6stat rip6stat;
   1112  1.23    itojun 	u_quad_t delivered;
   1113  1.23    itojun 
   1114  1.23    itojun 	if (off == 0)
   1115  1.23    itojun 		return;
   1116  1.23    itojun 	kread(off, (char *)&rip6stat, sizeof(rip6stat));
   1117  1.23    itojun 	printf("%s:\n", name);
   1118  1.23    itojun 
   1119  1.23    itojun #define	p(f, m) if (rip6stat.f || sflag <= 1) \
   1120  1.23    itojun     printf(m, (unsigned long long)rip6stat.f, plural(rip6stat.f))
   1121  1.23    itojun 	p(rip6s_ipackets, "\t%llu message%s received\n");
   1122  1.25     grant 	p(rip6s_isum, "\t%llu checksum calculation%s on inbound\n");
   1123  1.23    itojun 	p(rip6s_badsum, "\t%llu message%s with bad checksum\n");
   1124  1.23    itojun 	p(rip6s_nosock, "\t%llu message%s dropped due to no socket\n");
   1125  1.23    itojun 	p(rip6s_nosockmcast,
   1126  1.23    itojun 	    "\t%llu multicast message%s dropped due to no socket\n");
   1127  1.23    itojun 	p(rip6s_fullsock,
   1128  1.23    itojun 	    "\t%llu message%s dropped due to full socket buffers\n");
   1129  1.23    itojun 	delivered = rip6stat.rip6s_ipackets -
   1130  1.23    itojun 		    rip6stat.rip6s_badsum -
   1131  1.23    itojun 		    rip6stat.rip6s_nosock -
   1132  1.23    itojun 		    rip6stat.rip6s_nosockmcast -
   1133  1.23    itojun 		    rip6stat.rip6s_fullsock;
   1134  1.23    itojun 	if (delivered || sflag <= 1)
   1135  1.23    itojun 		printf("\t%llu delivered\n", (unsigned long long)delivered);
   1136  1.23    itojun 	p(rip6s_opackets, "\t%llu datagram%s output\n");
   1137   1.1    itojun #undef p
   1138   1.1    itojun }
   1139   1.1    itojun 
   1140   1.1    itojun /*
   1141   1.1    itojun  * Pretty print an Internet address (net address + port).
   1142  1.20     assar  * Take numeric_addr and numeric_port into consideration.
   1143   1.1    itojun  */
   1144   1.1    itojun void
   1145   1.1    itojun inet6print(in6, port, proto)
   1146   1.1    itojun 	register struct in6_addr *in6;
   1147   1.1    itojun 	int port;
   1148   1.1    itojun 	char *proto;
   1149   1.1    itojun {
   1150   1.1    itojun #define GETSERVBYPORT6(port, proto, ret)\
   1151   1.5    itojun do {\
   1152   1.1    itojun 	if (strcmp((proto), "tcp6") == 0)\
   1153   1.1    itojun 		(ret) = getservbyport((int)(port), "tcp");\
   1154   1.1    itojun 	else if (strcmp((proto), "udp6") == 0)\
   1155   1.1    itojun 		(ret) = getservbyport((int)(port), "udp");\
   1156   1.1    itojun 	else\
   1157   1.1    itojun 		(ret) = getservbyport((int)(port), (proto));\
   1158   1.5    itojun } while (0)
   1159   1.1    itojun 	struct servent *sp = 0;
   1160   1.1    itojun 	char line[80], *cp;
   1161   1.1    itojun 	int width;
   1162   1.1    itojun 
   1163   1.5    itojun 	width = Aflag ? 12 : 16;
   1164   1.5    itojun 	if (vflag && width < strlen(inet6name(in6)))
   1165   1.5    itojun 		width = strlen(inet6name(in6));
   1166  1.19    itojun 	snprintf(line, sizeof(line), "%.*s.", width, inet6name(in6));
   1167  1.24    itojun 	cp = strchr(line, '\0');
   1168  1.20     assar 	if (!numeric_port && port)
   1169   1.1    itojun 		GETSERVBYPORT6(port, proto, sp);
   1170   1.1    itojun 	if (sp || port == 0)
   1171  1.19    itojun 		snprintf(cp, sizeof(line) - (cp - line),
   1172  1.26  jdolecek 		    "%s", sp ? sp->s_name : "*");
   1173   1.1    itojun 	else
   1174  1.19    itojun 		snprintf(cp, sizeof(line) - (cp - line),
   1175  1.19    itojun 		    "%d", ntohs((u_short)port));
   1176   1.1    itojun 	width = Aflag ? 18 : 22;
   1177   1.5    itojun 	if (vflag && width < strlen(line))
   1178   1.5    itojun 		width = strlen(line);
   1179   1.1    itojun 	printf(" %-*.*s", width, width, line);
   1180   1.1    itojun }
   1181   1.1    itojun 
   1182   1.1    itojun /*
   1183   1.1    itojun  * Construct an Internet address representation.
   1184  1.20     assar  * If the numeric_addr has been supplied, give
   1185   1.1    itojun  * numeric value, otherwise try for symbolic name.
   1186   1.1    itojun  */
   1187   1.1    itojun 
   1188   1.1    itojun char *
   1189   1.1    itojun inet6name(in6p)
   1190   1.1    itojun 	struct in6_addr *in6p;
   1191   1.1    itojun {
   1192   1.1    itojun 	register char *cp;
   1193  1.17    itojun 	static char line[NI_MAXHOST];
   1194   1.1    itojun 	struct hostent *hp;
   1195   1.1    itojun 	static char domain[MAXHOSTNAMELEN + 1];
   1196   1.1    itojun 	static int first = 1;
   1197   1.5    itojun 	char hbuf[NI_MAXHOST];
   1198   1.5    itojun 	struct sockaddr_in6 sin6;
   1199   1.5    itojun 	const int niflag = NI_NUMERICHOST;
   1200   1.1    itojun 
   1201  1.20     assar 	if (first && !numeric_addr) {
   1202   1.1    itojun 		first = 0;
   1203   1.1    itojun 		if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
   1204  1.24    itojun 		    (cp = strchr(domain, '.')))
   1205  1.19    itojun 			(void) strlcpy(domain, cp + 1, sizeof(domain));
   1206   1.1    itojun 		else
   1207   1.1    itojun 			domain[0] = 0;
   1208   1.1    itojun 	}
   1209   1.1    itojun 	cp = 0;
   1210  1.20     assar 	if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
   1211   1.1    itojun 		hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
   1212   1.1    itojun 		if (hp) {
   1213  1.24    itojun 			if ((cp = strchr(hp->h_name, '.')) &&
   1214   1.1    itojun 			    !strcmp(cp + 1, domain))
   1215   1.1    itojun 				*cp = 0;
   1216   1.1    itojun 			cp = hp->h_name;
   1217   1.1    itojun 		}
   1218   1.1    itojun 	}
   1219   1.1    itojun 	if (IN6_IS_ADDR_UNSPECIFIED(in6p))
   1220  1.17    itojun 		strlcpy(line, "*", sizeof(line));
   1221   1.1    itojun 	else if (cp)
   1222  1.17    itojun 		strlcpy(line, cp, sizeof(line));
   1223  1.17    itojun 	else {
   1224   1.5    itojun 		memset(&sin6, 0, sizeof(sin6));
   1225   1.5    itojun 		sin6.sin6_len = sizeof(sin6);
   1226   1.5    itojun 		sin6.sin6_family = AF_INET6;
   1227   1.5    itojun 		sin6.sin6_addr = *in6p;
   1228  1.27    itojun #ifdef __KAME__
   1229  1.31    itojun 		if (IN6_IS_ADDR_LINKLOCAL(in6p) ||
   1230  1.31    itojun 		    IN6_IS_ADDR_MC_LINKLOCAL(in6p)) {
   1231   1.5    itojun 			sin6.sin6_scope_id =
   1232  1.31    itojun 			    ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
   1233   1.5    itojun 			sin6.sin6_addr.s6_addr[2] = 0;
   1234   1.5    itojun 			sin6.sin6_addr.s6_addr[3] = 0;
   1235   1.5    itojun 		}
   1236   1.5    itojun #endif
   1237   1.5    itojun 		if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
   1238  1.17    itojun 				hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
   1239  1.19    itojun 			strlcpy(hbuf, "?", sizeof(hbuf));
   1240  1.17    itojun 		strlcpy(line, hbuf, sizeof(line));
   1241   1.5    itojun 	}
   1242   1.1    itojun 	return (line);
   1243   1.1    itojun }
   1244   1.1    itojun 
   1245   1.1    itojun #ifdef TCP6
   1246   1.1    itojun /*
   1247   1.1    itojun  * Dump the contents of a TCP6 PCB.
   1248   1.1    itojun  */
   1249   1.1    itojun void
   1250   1.1    itojun tcp6_dump(pcbaddr)
   1251   1.1    itojun 	u_long pcbaddr;
   1252   1.1    itojun {
   1253   1.1    itojun 	struct tcp6cb tcp6cb;
   1254   1.1    itojun 	int i;
   1255   1.1    itojun 
   1256   1.1    itojun 	kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
   1257   1.1    itojun 
   1258   1.1    itojun 	printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
   1259   1.1    itojun 
   1260   1.1    itojun 	printf("Timers:\n");
   1261   1.1    itojun 	for (i = 0; i < TCP6T_NTIMERS; i++)
   1262   1.1    itojun 		printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
   1263   1.1    itojun 	printf("\n\n");
   1264   1.1    itojun 
   1265   1.1    itojun 	if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
   1266   1.1    itojun 		printf("State: %d", tcp6cb.t_state);
   1267   1.1    itojun 	else
   1268   1.1    itojun 		printf("State: %s", tcp6states[tcp6cb.t_state]);
   1269   1.1    itojun 	printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
   1270   1.1    itojun 	    (u_long)tcp6cb.t_in6pcb);
   1271   1.1    itojun 
   1272   1.1    itojun 	printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
   1273   1.1    itojun 	    tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
   1274   1.1    itojun 	printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
   1275   1.1    itojun 	    tcp6cb.t_maxseg, tcp6cb.t_force);
   1276   1.1    itojun 
   1277   1.1    itojun 	printf("snd_una %u, snd_nxt %u, snd_up %u\n",
   1278   1.1    itojun 	    tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
   1279   1.4    bouyer 	printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %llu\n\n",
   1280   1.4    bouyer 	    tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss,
   1281   1.4    bouyer 	    (unsigned long long)tcp6cb.snd_wnd);
   1282   1.4    bouyer 
   1283   1.4    bouyer 	printf("rcv_wnd %llu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
   1284   1.4    bouyer 	    (unsigned long long)cp6cb.rcv_wnd, tcp6cb.rcv_nxt,
   1285   1.4    bouyer 	    tcp6cb.rcv_up, tcp6cb.irs);
   1286   1.4    bouyer 
   1287   1.4    bouyer 	printf("rcv_adv %u, snd_max %u, snd_cwnd %llu, snd_ssthresh %llu\n",
   1288   1.4    bouyer 	    tcp6cb.rcv_adv, tcp6cb.snd_max, (unsigned long long)tcp6cb.snd_cwnd,
   1289   1.4    bouyer 	    (unsigned long long)tcp6cb.snd_ssthresh);
   1290   1.1    itojun 
   1291   1.1    itojun 	printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
   1292   1.4    bouyer 	    "max_sndwnd %llu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
   1293   1.4    bouyer 	    tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin,
   1294   1.4    bouyer 	    (unsigned long long)tcp6cb.max_sndwnd);
   1295   1.1    itojun 
   1296   1.1    itojun 	printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
   1297   1.1    itojun 	    tcp6cb.t_iobc, tcp6cb.t_softerror);
   1298   1.1    itojun 
   1299   1.1    itojun 	printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
   1300   1.1    itojun 	    tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
   1301   1.1    itojun 	    tcp6cb.requested_s_scale);
   1302   1.1    itojun 	printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
   1303   1.1    itojun 	    tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
   1304   1.1    itojun }
   1305   1.1    itojun #endif
   1306   1.1    itojun 
   1307   1.1    itojun #endif /*INET6*/
   1308