Home | History | Annotate | Line # | Download | only in netstat
inet.c revision 1.100.2.2
      1  1.100.2.2      yamt /*	$NetBSD: inet.c,v 1.100.2.2 2014/05/22 11:42:46 yamt Exp $	*/
      2       1.14   thorpej 
      3        1.1       cgd /*
      4        1.9   mycroft  * Copyright (c) 1983, 1988, 1993
      5        1.9   mycroft  *	The Regents of the University of California.  All rights reserved.
      6        1.1       cgd  *
      7        1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8        1.1       cgd  * modification, are permitted provided that the following conditions
      9        1.1       cgd  * are met:
     10        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15       1.58       agc  * 3. Neither the name of the University nor the names of its contributors
     16        1.1       cgd  *    may be used to endorse or promote products derived from this software
     17        1.1       cgd  *    without specific prior written permission.
     18        1.1       cgd  *
     19        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29        1.1       cgd  * SUCH DAMAGE.
     30        1.1       cgd  */
     31        1.1       cgd 
     32       1.23     lukem #include <sys/cdefs.h>
     33        1.1       cgd #ifndef lint
     34       1.14   thorpej #if 0
     35       1.14   thorpej static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
     36       1.14   thorpej #else
     37  1.100.2.2      yamt __RCSID("$NetBSD: inet.c,v 1.100.2.2 2014/05/22 11:42:46 yamt Exp $");
     38       1.14   thorpej #endif
     39        1.1       cgd #endif /* not lint */
     40        1.1       cgd 
     41       1.78        ad #define	_CALLOUT_PRIVATE	/* for defs in sys/callout.h */
     42       1.78        ad 
     43        1.1       cgd #include <sys/param.h>
     44       1.10       cgd #include <sys/queue.h>
     45        1.1       cgd #include <sys/socket.h>
     46        1.1       cgd #include <sys/socketvar.h>
     47        1.1       cgd #include <sys/mbuf.h>
     48        1.1       cgd #include <sys/protosw.h>
     49       1.65      elad #include <sys/sysctl.h>
     50        1.1       cgd 
     51       1.41     jhawk #include <net/if_arp.h>
     52        1.1       cgd #include <net/route.h>
     53        1.1       cgd #include <netinet/in.h>
     54        1.1       cgd #include <netinet/in_systm.h>
     55        1.1       cgd #include <netinet/ip.h>
     56        1.1       cgd #include <netinet/in_pcb.h>
     57  1.100.2.1      yamt #define ICMP_STRINGS
     58        1.1       cgd #include <netinet/ip_icmp.h>
     59       1.37    itojun 
     60       1.37    itojun #ifdef INET6
     61       1.37    itojun #include <netinet/ip6.h>
     62       1.37    itojun #endif
     63       1.37    itojun 
     64        1.1       cgd #include <netinet/icmp_var.h>
     65        1.6    brezak #include <netinet/igmp_var.h>
     66        1.1       cgd #include <netinet/ip_var.h>
     67       1.62      manu #include <netinet/pim_var.h>
     68        1.1       cgd #include <netinet/tcp.h>
     69        1.1       cgd #include <netinet/tcpip.h>
     70        1.1       cgd #include <netinet/tcp_seq.h>
     71        1.1       cgd #define TCPSTATES
     72        1.1       cgd #include <netinet/tcp_fsm.h>
     73       1.30   thorpej #define	TCPTIMERS
     74        1.1       cgd #include <netinet/tcp_timer.h>
     75        1.1       cgd #include <netinet/tcp_var.h>
     76        1.1       cgd #include <netinet/tcp_debug.h>
     77        1.1       cgd #include <netinet/udp.h>
     78       1.69  liamjfoy #include <netinet/ip_carp.h>
     79        1.1       cgd #include <netinet/udp_var.h>
     80       1.96    dyoung #include <netinet/tcp_vtw.h>
     81        1.1       cgd 
     82        1.9   mycroft #include <arpa/inet.h>
     83       1.64    rpaulo #include <kvm.h>
     84        1.1       cgd #include <netdb.h>
     85        1.1       cgd #include <stdio.h>
     86        1.1       cgd #include <string.h>
     87        1.9   mycroft #include <unistd.h>
     88       1.66      elad #include <stdlib.h>
     89       1.65      elad #include <err.h>
     90        1.9   mycroft #include "netstat.h"
     91       1.96    dyoung #include "vtw.h"
     92       1.93     pooka #include "prog_ops.h"
     93        1.1       cgd 
     94       1.84   thorpej char	*inetname(struct in_addr *);
     95       1.84   thorpej void	inetprint(struct in_addr *, u_int16_t, const char *, int);
     96        1.1       cgd 
     97       1.96    dyoung void	print_vtw_v4(const vtw_t *);
     98       1.96    dyoung 
     99        1.1       cgd /*
    100        1.1       cgd  * Print a summary of connections related to an Internet
    101        1.1       cgd  * protocol.  For TCP, also give state of connection.
    102        1.1       cgd  * Listening processes (aflag) are suppressed unless the
    103        1.1       cgd  * -a (all) flag is specified.
    104        1.1       cgd  */
    105       1.35     lukem static int width;
    106       1.66      elad static int compact;
    107       1.66      elad 
    108       1.96    dyoung /* VTW-related variables. */
    109       1.96    dyoung static struct timeval now;
    110       1.96    dyoung 
    111       1.66      elad static void
    112       1.66      elad protoprhdr(void)
    113       1.66      elad {
    114       1.66      elad 	printf("Active Internet connections");
    115       1.66      elad 	if (aflag)
    116       1.66      elad 		printf(" (including servers)");
    117       1.66      elad 	putchar('\n');
    118       1.66      elad 	if (Aflag)
    119       1.66      elad 		printf("%-8.8s ", "PCB");
    120       1.99    dyoung 	printf(
    121       1.99    dyoung 	    Vflag ? "%-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %-13.13s Expires\n"
    122       1.99    dyoung 	          : "%-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %s\n",
    123       1.66      elad 		"Proto", "Recv-Q", "Send-Q", compact ? "" : " ",
    124       1.66      elad 		width, width, "Local Address",
    125       1.66      elad 		width, width, "Foreign Address",
    126       1.99    dyoung 		"State");
    127       1.66      elad }
    128       1.66      elad 
    129       1.66      elad static void
    130       1.67        he protopr0(intptr_t ppcb, u_long rcv_sb_cc, u_long snd_sb_cc,
    131       1.66      elad 	 struct in_addr *laddr, u_int16_t lport,
    132       1.66      elad 	 struct in_addr *faddr, u_int16_t fport,
    133       1.96    dyoung 	 short t_state, const char *name, int inp_flags,
    134       1.96    dyoung 	 const struct timeval *expires)
    135       1.66      elad {
    136       1.83   thorpej 	static const char *shorttcpstates[] = {
    137       1.66      elad 		"CLOSED",	"LISTEN",	"SYNSEN",	"SYSRCV",
    138       1.66      elad 		"ESTABL",	"CLWAIT",	"FWAIT1",	"CLOSNG",
    139       1.66      elad 		"LASTAK",	"FWAIT2",	"TMWAIT",
    140       1.66      elad 	};
    141       1.66      elad 	int istcp;
    142       1.66      elad 
    143       1.66      elad 	istcp = strcmp(name, "tcp") == 0;
    144       1.66      elad 
    145       1.66      elad 	if (Aflag) {
    146       1.68      elad 		printf("%8" PRIxPTR " ", ppcb);
    147       1.66      elad 	}
    148       1.66      elad 	printf("%-5.5s %6ld %6ld%s", name, rcv_sb_cc, snd_sb_cc,
    149       1.66      elad 	       compact ? "" : " ");
    150       1.66      elad 	if (numeric_port) {
    151       1.66      elad 		inetprint(laddr, lport, name, 1);
    152       1.66      elad 		inetprint(faddr, fport, name, 1);
    153       1.90     lukem 	} else if (inp_flags & INP_ANONPORT) {
    154       1.66      elad 		inetprint(laddr, lport, name, 1);
    155       1.66      elad 		inetprint(faddr, fport, name, 0);
    156       1.66      elad 	} else {
    157       1.66      elad 		inetprint(laddr, lport, name, 0);
    158       1.66      elad 		inetprint(faddr, fport, name, 0);
    159       1.66      elad 	}
    160       1.66      elad 	if (istcp) {
    161       1.66      elad 		if (t_state < 0 || t_state >= TCP_NSTATES)
    162       1.66      elad 			printf(" %d", t_state);
    163       1.66      elad 		else
    164       1.66      elad 			printf(" %s", compact ? shorttcpstates[t_state] :
    165       1.66      elad 			       tcpstates[t_state]);
    166       1.66      elad 	}
    167       1.96    dyoung 	if (Vflag && expires != NULL) {
    168       1.97    dyoung 		if (expires->tv_sec == 0 && expires->tv_usec == -1)
    169       1.97    dyoung 			printf(" reclaimed");
    170       1.97    dyoung 		else {
    171       1.96    dyoung 			struct timeval delta;
    172       1.96    dyoung 
    173       1.96    dyoung 			timersub(expires, &now, &delta);
    174       1.96    dyoung 			printf(" %.3fms",
    175       1.96    dyoung 			    delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
    176       1.97    dyoung 		}
    177       1.96    dyoung 	}
    178       1.66      elad 	putchar('\n');
    179       1.66      elad }
    180       1.35     lukem 
    181       1.96    dyoung static void
    182       1.96    dyoung dbg_printf(const char *fmt, ...)
    183       1.96    dyoung {
    184       1.96    dyoung 	return;
    185       1.96    dyoung }
    186       1.96    dyoung 
    187       1.96    dyoung void
    188       1.96    dyoung print_vtw_v4(const vtw_t *vtw)
    189       1.96    dyoung {
    190       1.96    dyoung 	const vtw_v4_t *v4 = (const vtw_v4_t *)vtw;
    191       1.96    dyoung 	struct timeval delta;
    192       1.96    dyoung 	struct in_addr la, fa;
    193       1.96    dyoung 	char buf[2][32];
    194       1.97    dyoung 	static const struct timeval zero = {.tv_sec = 0, .tv_usec = 0};
    195       1.96    dyoung 
    196       1.96    dyoung 	la.s_addr = v4->laddr;
    197       1.96    dyoung 	fa.s_addr = v4->faddr;
    198       1.96    dyoung 
    199       1.96    dyoung 	snprintf(&buf[0][0], 32, "%s", inet_ntoa(la));
    200       1.96    dyoung 	snprintf(&buf[1][0], 32, "%s", inet_ntoa(fa));
    201       1.96    dyoung 
    202       1.96    dyoung 	timersub(&vtw->expire, &now, &delta);
    203       1.96    dyoung 
    204       1.96    dyoung 	if (vtw->expire.tv_sec == 0 && vtw->expire.tv_usec == -1) {
    205       1.97    dyoung 		dbg_printf("%15.15s:%d %15.15s:%d reclaimed\n"
    206       1.96    dyoung 		    ,buf[0], ntohs(v4->lport)
    207       1.96    dyoung 		    ,buf[1], ntohs(v4->fport));
    208       1.96    dyoung 		if (!(Vflag && vflag))
    209       1.96    dyoung 			return;
    210       1.96    dyoung 	} else if (vtw->expire.tv_sec == 0)
    211       1.96    dyoung 		return;
    212       1.97    dyoung 	else if (timercmp(&delta, &zero, <) && !(Vflag && vflag)) {
    213       1.97    dyoung 		dbg_printf("%15.15s:%d %15.15s:%d expired\n"
    214       1.97    dyoung 		    ,buf[0], ntohs(v4->lport)
    215       1.97    dyoung 		    ,buf[1], ntohs(v4->fport));
    216       1.97    dyoung 		return;
    217       1.97    dyoung 	} else {
    218       1.96    dyoung 		dbg_printf("%15.15s:%d %15.15s:%d expires in %.3fms\n"
    219       1.96    dyoung 		    ,buf[0], ntohs(v4->lport)
    220       1.96    dyoung 		    ,buf[1], ntohs(v4->fport)
    221       1.96    dyoung 		    ,delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
    222       1.96    dyoung 	}
    223       1.96    dyoung 	protopr0(0, 0, 0,
    224       1.96    dyoung 		 &la, v4->lport,
    225       1.96    dyoung 		 &fa, v4->fport,
    226       1.96    dyoung 		 TCPS_TIME_WAIT, "tcp", 0, &vtw->expire);
    227       1.96    dyoung }
    228       1.96    dyoung 
    229  1.100.2.2      yamt struct kinfo_pcb *
    230  1.100.2.2      yamt getpcblist_sysctl(const char *name, size_t *len) {
    231  1.100.2.2      yamt 	int mib[8];
    232  1.100.2.2      yamt 	size_t namelen = 0, size = 0;
    233  1.100.2.2      yamt 	char *mibname = NULL;
    234  1.100.2.2      yamt 	struct kinfo_pcb *pcblist;
    235       1.66      elad 
    236  1.100.2.2      yamt 	memset(mib, 0, sizeof(mib));
    237       1.66      elad 
    238  1.100.2.2      yamt 	if (asprintf(&mibname, "net.inet%s.%s.pcblist", name + 3, name) == -1)
    239  1.100.2.2      yamt 		err(1, "asprintf");
    240       1.66      elad 
    241  1.100.2.2      yamt 	/* get dynamic pcblist node */
    242  1.100.2.2      yamt 	if (sysctlnametomib(mibname, mib, &namelen) == -1)
    243  1.100.2.2      yamt 		err(1, "sysctlnametomib: %s", mibname);
    244       1.66      elad 
    245  1.100.2.2      yamt 	free(mibname);
    246       1.66      elad 
    247  1.100.2.2      yamt 	if (prog_sysctl(mib, __arraycount(mib), NULL, &size, NULL, 0) == -1)
    248  1.100.2.2      yamt 		err(1, "sysctl (query)");
    249       1.66      elad 
    250  1.100.2.2      yamt 	if ((pcblist = malloc(size)) == NULL)
    251  1.100.2.2      yamt 		err(1, "malloc");
    252  1.100.2.2      yamt 	memset(pcblist, 0, size);
    253       1.66      elad 
    254  1.100.2.2      yamt 	mib[6] = sizeof(*pcblist);
    255  1.100.2.2      yamt 	mib[7] = size / sizeof(*pcblist);
    256       1.66      elad 
    257  1.100.2.2      yamt 	if (prog_sysctl(mib, __arraycount(mib), pcblist, &size, NULL, 0) == -1)
    258  1.100.2.2      yamt 		err(1, "sysctl (copy)");
    259       1.89  dholland 
    260  1.100.2.2      yamt 	*len = size / sizeof(*pcblist);
    261  1.100.2.2      yamt 	return pcblist;
    262       1.66      elad 
    263  1.100.2.2      yamt }
    264       1.66      elad 
    265  1.100.2.2      yamt static struct kinfo_pcb *
    266  1.100.2.2      yamt getpcblist_kmem(u_long off, const char *name, size_t *len) {
    267  1.100.2.2      yamt 	struct inpcbtable table;
    268  1.100.2.2      yamt 	struct inpcb_hdr *next, *prev;
    269  1.100.2.2      yamt 	struct inpcb inpcb;
    270  1.100.2.2      yamt 	struct tcpcb tcpcb;
    271  1.100.2.2      yamt 	struct socket sockb;
    272  1.100.2.2      yamt 	int istcp = strcmp(name, "tcp") == 0;
    273  1.100.2.2      yamt 	struct kinfo_pcb *pcblist;
    274  1.100.2.2      yamt 	size_t size = 100, i;
    275  1.100.2.2      yamt 	struct sockaddr_in sin;
    276  1.100.2.2      yamt 	struct inpcbqueue *head;
    277  1.100.2.2      yamt 
    278  1.100.2.2      yamt 	if (off == 0) {
    279  1.100.2.2      yamt 		*len = 0;
    280  1.100.2.2      yamt 		return NULL;
    281       1.66      elad 	}
    282       1.66      elad 
    283       1.72      elad 	kread(off, (char *)&table, sizeof table);
    284  1.100.2.2      yamt 	head = &table.inpt_queue;
    285  1.100.2.2      yamt 	next = TAILQ_FIRST(head);
    286  1.100.2.2      yamt 	prev = TAILQ_END(head);
    287       1.72      elad 
    288  1.100.2.2      yamt 	if ((pcblist = malloc(size)) == NULL)
    289  1.100.2.2      yamt 		err(1, "malloc");
    290  1.100.2.2      yamt 
    291  1.100.2.2      yamt 	i = 0;
    292  1.100.2.2      yamt 	while (next != TAILQ_END(head)) {
    293       1.12   mycroft 		kread((u_long)next, (char *)&inpcb, sizeof inpcb);
    294       1.13       cgd 		prev = next;
    295  1.100.2.2      yamt 		next = TAILQ_NEXT(&inpcb, inp_queue);
    296       1.59    itojun 
    297       1.59    itojun 		if (inpcb.inp_af != AF_INET)
    298       1.59    itojun 			continue;
    299       1.13       cgd 
    300  1.100.2.2      yamt 		kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof(sockb));
    301        1.1       cgd 		if (istcp) {
    302        1.9   mycroft 			kread((u_long)inpcb.inp_ppcb,
    303        1.9   mycroft 			    (char *)&tcpcb, sizeof (tcpcb));
    304        1.1       cgd 		}
    305  1.100.2.2      yamt 		pcblist[i].ki_ppcbaddr =
    306  1.100.2.2      yamt 		    istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev;
    307  1.100.2.2      yamt 		pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
    308  1.100.2.2      yamt 		pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;
    309  1.100.2.2      yamt 
    310  1.100.2.2      yamt 		sin.sin_addr = inpcb.inp_laddr;
    311  1.100.2.2      yamt 		sin.sin_port = inpcb.inp_lport;
    312  1.100.2.2      yamt 		memcpy(&pcblist[i].ki_s, &sin, sizeof(sin));
    313  1.100.2.2      yamt 		sin.sin_addr = inpcb.inp_faddr;
    314  1.100.2.2      yamt 		sin.sin_port = inpcb.inp_fport;
    315  1.100.2.2      yamt 		memcpy(&pcblist[i].ki_d, &sin, sizeof(sin));
    316  1.100.2.2      yamt 		pcblist[i].ki_tstate = tcpcb.t_state;
    317  1.100.2.2      yamt 		pcblist[i].ki_pflags = inpcb.inp_flags;
    318  1.100.2.2      yamt 		if (i++ == size) {
    319  1.100.2.2      yamt 			struct kinfo_pcb *n = realloc(pcblist, size += 100);
    320  1.100.2.2      yamt 			if (n == NULL)
    321  1.100.2.2      yamt 				err(1, "realloc");
    322  1.100.2.2      yamt 			pcblist = n;
    323  1.100.2.2      yamt 		}
    324  1.100.2.2      yamt 	}
    325  1.100.2.2      yamt 	*len = i;
    326  1.100.2.2      yamt 	return pcblist;
    327  1.100.2.2      yamt }
    328  1.100.2.2      yamt 
    329  1.100.2.2      yamt void
    330  1.100.2.2      yamt protopr(u_long off, const char *name)
    331  1.100.2.2      yamt {
    332  1.100.2.2      yamt 	static int first = 1;
    333  1.100.2.2      yamt 	struct kinfo_pcb *pcblist;
    334  1.100.2.2      yamt 	size_t i, len;
    335  1.100.2.2      yamt 
    336  1.100.2.2      yamt 	compact = 0;
    337  1.100.2.2      yamt 	if (Aflag) {
    338  1.100.2.2      yamt 		if (!numeric_addr)
    339  1.100.2.2      yamt 			width = 18;
    340  1.100.2.2      yamt 		else {
    341  1.100.2.2      yamt 			width = 21;
    342  1.100.2.2      yamt 			compact = 1;
    343  1.100.2.2      yamt 		}
    344  1.100.2.2      yamt 	} else
    345  1.100.2.2      yamt 		width = 22;
    346  1.100.2.2      yamt 
    347  1.100.2.2      yamt 	if (use_sysctl)
    348  1.100.2.2      yamt 		pcblist = getpcblist_sysctl(name, &len);
    349  1.100.2.2      yamt 	else
    350  1.100.2.2      yamt 		pcblist = getpcblist_kmem(off, name, &len);
    351  1.100.2.2      yamt 
    352  1.100.2.2      yamt 	for (i = 0; i < len; i++) {
    353  1.100.2.2      yamt 		struct sockaddr_in src, dst;
    354  1.100.2.2      yamt 
    355  1.100.2.2      yamt 		memcpy(&src, &pcblist[i].ki_s, sizeof(src));
    356  1.100.2.2      yamt 		memcpy(&dst, &pcblist[i].ki_d, sizeof(dst));
    357  1.100.2.2      yamt 
    358  1.100.2.2      yamt 		if (!aflag &&
    359  1.100.2.2      yamt 		    inet_lnaof(dst.sin_addr) == INADDR_ANY)
    360  1.100.2.2      yamt 			continue;
    361       1.66      elad 
    362        1.1       cgd 		if (first) {
    363       1.66      elad 			protoprhdr();
    364        1.1       cgd 			first = 0;
    365        1.1       cgd 		}
    366  1.100.2.2      yamt 		protopr0((intptr_t) pcblist[i].ki_ppcbaddr,
    367  1.100.2.2      yamt 			 pcblist[i].ki_rcvq, pcblist[i].ki_sndq,
    368  1.100.2.2      yamt 			 &src.sin_addr, src.sin_port,
    369  1.100.2.2      yamt 			 &dst.sin_addr, dst.sin_port,
    370  1.100.2.2      yamt 			 pcblist[i].ki_tstate, name,
    371  1.100.2.2      yamt 			 pcblist[i].ki_pflags, NULL);
    372       1.96    dyoung 	}
    373  1.100.2.2      yamt 
    374  1.100.2.2      yamt 	free(pcblist);
    375  1.100.2.2      yamt 
    376  1.100.2.2      yamt 	if (strcmp(name, "tcp") == 0) {
    377       1.98  drochner 		struct timeval t;
    378       1.98  drochner 		timebase(&t);
    379       1.96    dyoung 		gettimeofday(&now, NULL);
    380       1.98  drochner 		timersub(&now, &t, &now);
    381       1.96    dyoung 		show_vtw_v4(print_vtw_v4);
    382        1.1       cgd 	}
    383        1.1       cgd }
    384        1.1       cgd 
    385        1.1       cgd /*
    386        1.1       cgd  * Dump TCP statistics structure.
    387        1.1       cgd  */
    388        1.9   mycroft void
    389       1.90     lukem tcp_stats(u_long off, const char *name)
    390        1.1       cgd {
    391       1.83   thorpej 	uint64_t tcpstat[TCP_NSTATS];
    392        1.1       cgd 
    393       1.65      elad 	if (use_sysctl) {
    394       1.65      elad 		size_t size = sizeof(tcpstat);
    395       1.65      elad 
    396       1.83   thorpej 		if (sysctlbyname("net.inet.tcp.stats", tcpstat, &size,
    397       1.65      elad 				 NULL, 0) == -1)
    398       1.88   thorpej 			return;
    399       1.65      elad 	} else {
    400       1.88   thorpej 		warnx("%s stats not available via KVM.", name);
    401       1.88   thorpej 		return;
    402       1.65      elad 	}
    403       1.65      elad 
    404        1.1       cgd 	printf ("%s:\n", name);
    405        1.9   mycroft 
    406       1.83   thorpej #define	ps(f, m) if (tcpstat[f] || sflag <= 1) \
    407       1.95    dyoung     printf(m, tcpstat[f])
    408       1.83   thorpej #define	p(f, m) if (tcpstat[f] || sflag <= 1) \
    409       1.95    dyoung     printf(m, tcpstat[f], plural(tcpstat[f]))
    410       1.83   thorpej #define	p2(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \
    411       1.95    dyoung     printf(m, tcpstat[f1], plural(tcpstat[f1]), \
    412       1.95    dyoung     tcpstat[f2], plural(tcpstat[f2]))
    413       1.83   thorpej #define	p2s(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \
    414       1.95    dyoung     printf(m, tcpstat[f1], plural(tcpstat[f1]), \
    415       1.95    dyoung     tcpstat[f2])
    416       1.83   thorpej #define	p3(f, m) if (tcpstat[f] || sflag <= 1) \
    417       1.95    dyoung     printf(m, tcpstat[f], plurales(tcpstat[f]))
    418        1.1       cgd 
    419       1.95    dyoung 	p(TCP_STAT_SNDTOTAL, "\t%" PRIu64 " packet%s sent\n");
    420       1.83   thorpej 	p2(TCP_STAT_SNDPACK,TCP_STAT_SNDBYTE,
    421       1.95    dyoung 		"\t\t%" PRIu64 " data packet%s (%" PRIu64 " byte%s)\n");
    422       1.83   thorpej 	p2(TCP_STAT_SNDREXMITPACK, TCP_STAT_SNDREXMITBYTE,
    423       1.95    dyoung 		"\t\t%" PRIu64 " data packet%s (%" PRIu64 " byte%s) retransmitted\n");
    424       1.83   thorpej 	p2s(TCP_STAT_SNDACKS, TCP_STAT_DELACK,
    425       1.95    dyoung 		"\t\t%" PRIu64 " ack-only packet%s (%" PRIu64 " delayed)\n");
    426       1.95    dyoung 	p(TCP_STAT_SNDURG, "\t\t%" PRIu64 " URG only packet%s\n");
    427       1.95    dyoung 	p(TCP_STAT_SNDPROBE, "\t\t%" PRIu64 " window probe packet%s\n");
    428       1.95    dyoung 	p(TCP_STAT_SNDWINUP, "\t\t%" PRIu64 " window update packet%s\n");
    429       1.95    dyoung 	p(TCP_STAT_SNDCTRL, "\t\t%" PRIu64 " control packet%s\n");
    430       1.83   thorpej 	p(TCP_STAT_SELFQUENCH,
    431       1.95    dyoung 	    "\t\t%" PRIu64 " send attempt%s resulted in self-quench\n");
    432       1.95    dyoung 	p(TCP_STAT_RCVTOTAL, "\t%" PRIu64 " packet%s received\n");
    433       1.83   thorpej 	p2(TCP_STAT_RCVACKPACK, TCP_STAT_RCVACKBYTE,
    434       1.95    dyoung 		"\t\t%" PRIu64 " ack%s (for %" PRIu64 " byte%s)\n");
    435       1.95    dyoung 	p(TCP_STAT_RCVDUPACK, "\t\t%" PRIu64 " duplicate ack%s\n");
    436       1.95    dyoung 	p(TCP_STAT_RCVACKTOOMUCH, "\t\t%" PRIu64 " ack%s for unsent data\n");
    437       1.83   thorpej 	p2(TCP_STAT_RCVPACK, TCP_STAT_RCVBYTE,
    438       1.95    dyoung 		"\t\t%" PRIu64 " packet%s (%" PRIu64 " byte%s) received in-sequence\n");
    439       1.83   thorpej 	p2(TCP_STAT_RCVDUPPACK, TCP_STAT_RCVDUPBYTE,
    440       1.95    dyoung 		"\t\t%" PRIu64 " completely duplicate packet%s (%" PRIu64 " byte%s)\n");
    441       1.95    dyoung 	p(TCP_STAT_PAWSDROP, "\t\t%" PRIu64 " old duplicate packet%s\n");
    442       1.83   thorpej 	p2(TCP_STAT_RCVPARTDUPPACK, TCP_STAT_RCVPARTDUPBYTE,
    443       1.95    dyoung 		"\t\t%" PRIu64 " packet%s with some dup. data (%" PRIu64 " byte%s duped)\n");
    444       1.83   thorpej 	p2(TCP_STAT_RCVOOPACK, TCP_STAT_RCVOOBYTE,
    445       1.95    dyoung 		"\t\t%" PRIu64 " out-of-order packet%s (%" PRIu64 " byte%s)\n");
    446       1.83   thorpej 	p2(TCP_STAT_RCVPACKAFTERWIN, TCP_STAT_RCVBYTEAFTERWIN,
    447       1.95    dyoung 		"\t\t%" PRIu64 " packet%s (%" PRIu64 " byte%s) of data after window\n");
    448       1.95    dyoung 	p(TCP_STAT_RCVWINPROBE, "\t\t%" PRIu64 " window probe%s\n");
    449       1.95    dyoung 	p(TCP_STAT_RCVWINUPD, "\t\t%" PRIu64 " window update packet%s\n");
    450       1.95    dyoung 	p(TCP_STAT_RCVAFTERCLOSE, "\t\t%" PRIu64 " packet%s received after close\n");
    451       1.95    dyoung 	p(TCP_STAT_RCVBADSUM, "\t\t%" PRIu64 " discarded for bad checksum%s\n");
    452       1.95    dyoung 	p(TCP_STAT_RCVBADOFF, "\t\t%" PRIu64 " discarded for bad header offset field%s\n");
    453       1.95    dyoung 	ps(TCP_STAT_RCVSHORT, "\t\t%" PRIu64 " discarded because packet too short\n");
    454       1.95    dyoung 	p(TCP_STAT_CONNATTEMPT, "\t%" PRIu64 " connection request%s\n");
    455       1.95    dyoung 	p(TCP_STAT_ACCEPTS, "\t%" PRIu64 " connection accept%s\n");
    456       1.83   thorpej 	p(TCP_STAT_CONNECTS,
    457       1.95    dyoung 		"\t%" PRIu64 " connection%s established (including accepts)\n");
    458       1.83   thorpej 	p2(TCP_STAT_CLOSED, TCP_STAT_DROPS,
    459       1.95    dyoung 		"\t%" PRIu64 " connection%s closed (including %" PRIu64 " drop%s)\n");
    460       1.95    dyoung 	p(TCP_STAT_CONNDROPS, "\t%" PRIu64 " embryonic connection%s dropped\n");
    461       1.95    dyoung 	p(TCP_STAT_DELAYED_FREE, "\t%" PRIu64 " delayed free%s of tcpcb\n");
    462       1.83   thorpej 	p2(TCP_STAT_RTTUPDATED, TCP_STAT_SEGSTIMED,
    463       1.95    dyoung 		"\t%" PRIu64 " segment%s updated rtt (of %" PRIu64 " attempt%s)\n");
    464       1.95    dyoung 	p(TCP_STAT_REXMTTIMEO, "\t%" PRIu64 " retransmit timeout%s\n");
    465       1.83   thorpej 	p(TCP_STAT_TIMEOUTDROP,
    466       1.95    dyoung 		"\t\t%" PRIu64 " connection%s dropped by rexmit timeout\n");
    467       1.83   thorpej 	p2(TCP_STAT_PERSISTTIMEO, TCP_STAT_PERSISTDROPS,
    468       1.95    dyoung 	   "\t%" PRIu64 " persist timeout%s (resulting in %" PRIu64 " dropped "
    469       1.38    bouyer 		"connection%s)\n");
    470       1.95    dyoung 	p(TCP_STAT_KEEPTIMEO, "\t%" PRIu64 " keepalive timeout%s\n");
    471       1.95    dyoung 	p(TCP_STAT_KEEPPROBE, "\t\t%" PRIu64 " keepalive probe%s sent\n");
    472       1.95    dyoung 	p(TCP_STAT_KEEPDROPS, "\t\t%" PRIu64 " connection%s dropped by keepalive\n");
    473       1.95    dyoung 	p(TCP_STAT_PREDACK, "\t%" PRIu64 " correct ACK header prediction%s\n");
    474       1.95    dyoung 	p(TCP_STAT_PREDDAT, "\t%" PRIu64 " correct data packet header prediction%s\n");
    475       1.95    dyoung 	p3(TCP_STAT_PCBHASHMISS, "\t%" PRIu64 " PCB hash miss%s\n");
    476       1.95    dyoung 	ps(TCP_STAT_NOPORT, "\t%" PRIu64 " dropped due to no socket\n");
    477       1.95    dyoung 	p(TCP_STAT_CONNSDRAINED, "\t%" PRIu64 " connection%s drained due to memory "
    478       1.38    bouyer 		"shortage\n");
    479       1.95    dyoung 	p(TCP_STAT_PMTUBLACKHOLE, "\t%" PRIu64 " PMTUD blackhole%s detected\n");
    480       1.38    bouyer 
    481       1.95    dyoung 	p(TCP_STAT_BADSYN, "\t%" PRIu64 " bad connection attempt%s\n");
    482       1.95    dyoung 	ps(TCP_STAT_SC_ADDED, "\t%" PRIu64 " SYN cache entries added\n");
    483       1.95    dyoung 	p(TCP_STAT_SC_COLLISIONS, "\t\t%" PRIu64 " hash collision%s\n");
    484       1.95    dyoung 	ps(TCP_STAT_SC_COMPLETED, "\t\t%" PRIu64 " completed\n");
    485       1.95    dyoung 	ps(TCP_STAT_SC_ABORTED, "\t\t%" PRIu64 " aborted (no space to build PCB)\n");
    486       1.95    dyoung 	ps(TCP_STAT_SC_TIMED_OUT, "\t\t%" PRIu64 " timed out\n");
    487       1.95    dyoung 	ps(TCP_STAT_SC_OVERFLOWED, "\t\t%" PRIu64 " dropped due to overflow\n");
    488       1.95    dyoung 	ps(TCP_STAT_SC_BUCKETOVERFLOW, "\t\t%" PRIu64 " dropped due to bucket overflow\n");
    489       1.95    dyoung 	ps(TCP_STAT_SC_RESET, "\t\t%" PRIu64 " dropped due to RST\n");
    490       1.95    dyoung 	ps(TCP_STAT_SC_UNREACH, "\t\t%" PRIu64 " dropped due to ICMP unreachable\n");
    491       1.95    dyoung 	ps(TCP_STAT_SC_DELAYED_FREE, "\t\t%" PRIu64 " delayed free of SYN cache "
    492       1.57        he 		"entries\n");
    493       1.95    dyoung 	p(TCP_STAT_SC_RETRANSMITTED, "\t%" PRIu64 " SYN,ACK%s retransmitted\n");
    494       1.95    dyoung 	p(TCP_STAT_SC_DUPESYN, "\t%" PRIu64 " duplicate SYN%s received for entries "
    495       1.38    bouyer 		"already in the cache\n");
    496       1.95    dyoung 	p(TCP_STAT_SC_DROPPED, "\t%" PRIu64 " SYN%s dropped (no route or no space)\n");
    497       1.95    dyoung 	p(TCP_STAT_BADSIG, "\t%" PRIu64 " packet%s with bad signature\n");
    498       1.95    dyoung 	p(TCP_STAT_GOODSIG, "\t%" PRIu64 " packet%s with good signature\n");
    499       1.95    dyoung 
    500       1.95    dyoung 	p(TCP_STAT_ECN_SHS, "\t%" PRIu64 " successful ECN handshake%s\n");
    501       1.95    dyoung 	p(TCP_STAT_ECN_CE, "\t%" PRIu64 " packet%s with ECN CE bit\n");
    502       1.95    dyoung 	p(TCP_STAT_ECN_ECT, "\t%" PRIu64 " packet%s ECN ECT(0) bit\n");
    503        1.1       cgd #undef p
    504       1.20  christos #undef ps
    505        1.1       cgd #undef p2
    506       1.20  christos #undef p2s
    507        1.9   mycroft #undef p3
    508       1.96    dyoung 	show_vtw_stats();
    509        1.1       cgd }
    510        1.1       cgd 
    511        1.1       cgd /*
    512        1.1       cgd  * Dump UDP statistics structure.
    513        1.1       cgd  */
    514        1.9   mycroft void
    515       1.90     lukem udp_stats(u_long off, const char *name)
    516        1.1       cgd {
    517       1.80   thorpej 	uint64_t udpstat[UDP_NSTATS];
    518       1.38    bouyer 	u_quad_t delivered;
    519        1.1       cgd 
    520       1.65      elad 	if (use_sysctl) {
    521       1.65      elad 		size_t size = sizeof(udpstat);
    522       1.65      elad 
    523       1.80   thorpej 		if (sysctlbyname("net.inet.udp.stats", udpstat, &size,
    524       1.65      elad 				 NULL, 0) == -1)
    525       1.88   thorpej 			return;
    526       1.65      elad 	} else {
    527       1.88   thorpej 		warnx("%s stats not available via KVM.", name);
    528       1.88   thorpej 		return;
    529       1.65      elad 	}
    530       1.65      elad 
    531       1.65      elad 	printf ("%s:\n", name);
    532       1.15   mycroft 
    533       1.80   thorpej #define	ps(f, m) if (udpstat[f] || sflag <= 1) \
    534       1.95    dyoung     printf(m, udpstat[f])
    535       1.80   thorpej #define	p(f, m) if (udpstat[f] || sflag <= 1) \
    536       1.95    dyoung     printf(m, udpstat[f], plural(udpstat[f]))
    537       1.80   thorpej #define	p3(f, m) if (udpstat[f] || sflag <= 1) \
    538       1.95    dyoung     printf(m, udpstat[f], plurales(udpstat[f]))
    539       1.80   thorpej 
    540       1.95    dyoung 	p(UDP_STAT_IPACKETS, "\t%" PRIu64 " datagram%s received\n");
    541       1.95    dyoung 	ps(UDP_STAT_HDROPS, "\t%" PRIu64 " with incomplete header\n");
    542       1.95    dyoung 	ps(UDP_STAT_BADLEN, "\t%" PRIu64 " with bad data length field\n");
    543       1.95    dyoung 	ps(UDP_STAT_BADSUM, "\t%" PRIu64 " with bad checksum\n");
    544       1.95    dyoung 	ps(UDP_STAT_NOPORT, "\t%" PRIu64 " dropped due to no socket\n");
    545       1.80   thorpej 	p(UDP_STAT_NOPORTBCAST,
    546       1.95    dyoung 	  "\t%" PRIu64 " broadcast/multicast datagram%s dropped due to no socket\n");
    547       1.95    dyoung 	ps(UDP_STAT_FULLSOCK, "\t%" PRIu64 " dropped due to full socket buffers\n");
    548       1.80   thorpej 	delivered = udpstat[UDP_STAT_IPACKETS] -
    549       1.80   thorpej 		    udpstat[UDP_STAT_HDROPS] -
    550       1.80   thorpej 		    udpstat[UDP_STAT_BADLEN] -
    551       1.80   thorpej 		    udpstat[UDP_STAT_BADSUM] -
    552       1.80   thorpej 		    udpstat[UDP_STAT_NOPORT] -
    553       1.80   thorpej 		    udpstat[UDP_STAT_NOPORTBCAST] -
    554       1.80   thorpej 		    udpstat[UDP_STAT_FULLSOCK];
    555        1.9   mycroft 	if (delivered || sflag <= 1)
    556       1.95    dyoung 		printf("\t%" PRIu64 " delivered\n", delivered);
    557       1.95    dyoung 	p3(UDP_STAT_PCBHASHMISS, "\t%" PRIu64 " PCB hash miss%s\n");
    558       1.95    dyoung 	p(UDP_STAT_OPACKETS, "\t%" PRIu64 " datagram%s output\n");
    559       1.15   mycroft 
    560       1.20  christos #undef ps
    561        1.9   mycroft #undef p
    562       1.15   mycroft #undef p3
    563        1.1       cgd }
    564        1.1       cgd 
    565        1.1       cgd /*
    566        1.1       cgd  * Dump IP statistics structure.
    567        1.1       cgd  */
    568        1.9   mycroft void
    569       1.90     lukem ip_stats(u_long off, const char *name)
    570        1.1       cgd {
    571       1.82   thorpej 	uint64_t ipstat[IP_NSTATS];
    572        1.1       cgd 
    573       1.65      elad 	if (use_sysctl) {
    574       1.65      elad 		size_t size = sizeof(ipstat);
    575       1.65      elad 
    576       1.82   thorpej 		if (sysctlbyname("net.inet.ip.stats", ipstat, &size,
    577       1.65      elad 				 NULL, 0) == -1)
    578       1.88   thorpej 			return;
    579       1.65      elad 	} else {
    580       1.88   thorpej 		warnx("%s stats not available via KVM.", name);
    581       1.88   thorpej 		return;
    582       1.65      elad 	}
    583       1.65      elad 
    584        1.9   mycroft 	printf("%s:\n", name);
    585        1.9   mycroft 
    586       1.82   thorpej #define	ps(f, m) if (ipstat[f] || sflag <= 1) \
    587       1.95    dyoung     printf(m, ipstat[f])
    588       1.82   thorpej #define	p(f, m) if (ipstat[f] || sflag <= 1) \
    589       1.95    dyoung     printf(m, ipstat[f], plural(ipstat[f]))
    590       1.82   thorpej 
    591       1.95    dyoung 	p(IP_STAT_TOTAL, "\t%" PRIu64 " total packet%s received\n");
    592       1.95    dyoung 	p(IP_STAT_BADSUM, "\t%" PRIu64 " bad header checksum%s\n");
    593       1.95    dyoung 	ps(IP_STAT_TOOSMALL, "\t%" PRIu64 " with size smaller than minimum\n");
    594       1.95    dyoung 	ps(IP_STAT_TOOSHORT, "\t%" PRIu64 " with data size < data length\n");
    595       1.95    dyoung 	ps(IP_STAT_TOOLONG, "\t%" PRIu64 " with length > max ip packet size\n");
    596       1.95    dyoung 	ps(IP_STAT_BADHLEN, "\t%" PRIu64 " with header length < data size\n");
    597       1.95    dyoung 	ps(IP_STAT_BADLEN, "\t%" PRIu64 " with data length < header length\n");
    598       1.95    dyoung 	ps(IP_STAT_BADOPTIONS, "\t%" PRIu64 " with bad options\n");
    599       1.95    dyoung 	ps(IP_STAT_BADVERS, "\t%" PRIu64 " with incorrect version number\n");
    600       1.95    dyoung 	p(IP_STAT_FRAGMENTS, "\t%" PRIu64 " fragment%s received\n");
    601       1.95    dyoung 	p(IP_STAT_FRAGDROPPED, "\t%" PRIu64 " fragment%s dropped (dup or out of space)\n");
    602       1.95    dyoung 	p(IP_STAT_RCVMEMDROP, "\t%" PRIu64 " fragment%s dropped (out of ipqent)\n");
    603       1.95    dyoung 	p(IP_STAT_BADFRAGS, "\t%" PRIu64 " malformed fragment%s dropped\n");
    604       1.95    dyoung 	p(IP_STAT_FRAGTIMEOUT, "\t%" PRIu64 " fragment%s dropped after timeout\n");
    605       1.95    dyoung 	p(IP_STAT_REASSEMBLED, "\t%" PRIu64 " packet%s reassembled ok\n");
    606       1.95    dyoung 	p(IP_STAT_DELIVERED, "\t%" PRIu64 " packet%s for this host\n");
    607       1.95    dyoung 	p(IP_STAT_NOPROTO, "\t%" PRIu64 " packet%s for unknown/unsupported protocol\n");
    608       1.95    dyoung 	p(IP_STAT_FORWARD, "\t%" PRIu64 " packet%s forwarded");
    609       1.95    dyoung 	p(IP_STAT_FASTFORWARD, " (%" PRIu64 " packet%s fast forwarded)");
    610       1.82   thorpej 	if (ipstat[IP_STAT_FORWARD] || sflag <= 1)
    611       1.29      matt 		putchar('\n');
    612       1.95    dyoung 	p(IP_STAT_CANTFORWARD, "\t%" PRIu64 " packet%s not forwardable\n");
    613       1.95    dyoung 	p(IP_STAT_REDIRECTSENT, "\t%" PRIu64 " redirect%s sent\n");
    614       1.95    dyoung 	p(IP_STAT_NOGIF, "\t%" PRIu64 " packet%s no matching gif found\n");
    615       1.95    dyoung 	p(IP_STAT_LOCALOUT, "\t%" PRIu64 " packet%s sent from this host\n");
    616       1.95    dyoung 	p(IP_STAT_RAWOUT, "\t%" PRIu64 " packet%s sent with fabricated ip header\n");
    617       1.95    dyoung 	p(IP_STAT_ODROPPED, "\t%" PRIu64 " output packet%s dropped due to no bufs, etc.\n");
    618       1.95    dyoung 	p(IP_STAT_NOROUTE, "\t%" PRIu64 " output packet%s discarded due to no route\n");
    619       1.95    dyoung 	p(IP_STAT_FRAGMENTED, "\t%" PRIu64 " output datagram%s fragmented\n");
    620       1.95    dyoung 	p(IP_STAT_OFRAGMENTS, "\t%" PRIu64 " fragment%s created\n");
    621       1.95    dyoung 	p(IP_STAT_CANTFRAG, "\t%" PRIu64 " datagram%s that can't be fragmented\n");
    622       1.95    dyoung 	p(IP_STAT_BADADDR, "\t%" PRIu64 " datagram%s with bad address in header\n");
    623       1.20  christos #undef ps
    624        1.9   mycroft #undef p
    625        1.1       cgd }
    626        1.1       cgd 
    627        1.1       cgd /*
    628        1.1       cgd  * Dump ICMP statistics.
    629        1.1       cgd  */
    630        1.9   mycroft void
    631       1.90     lukem icmp_stats(u_long off, const char *name)
    632        1.1       cgd {
    633       1.79   thorpej 	uint64_t icmpstat[ICMP_NSTATS];
    634       1.23     lukem 	int i, first;
    635        1.1       cgd 
    636       1.65      elad 	if (use_sysctl) {
    637       1.65      elad 		size_t size = sizeof(icmpstat);
    638       1.65      elad 
    639       1.79   thorpej 		if (sysctlbyname("net.inet.icmp.stats", icmpstat, &size,
    640       1.65      elad 				 NULL, 0) == -1)
    641       1.88   thorpej 			return;
    642       1.65      elad 	} else {
    643       1.88   thorpej 		warnx("%s stats not available via KVM.", name);
    644       1.88   thorpej 		return;
    645       1.65      elad 	}
    646       1.65      elad 
    647        1.9   mycroft 	printf("%s:\n", name);
    648        1.9   mycroft 
    649       1.79   thorpej #define	p(f, m) if (icmpstat[f] || sflag <= 1) \
    650       1.95    dyoung     printf(m, icmpstat[f], plural(icmpstat[f]))
    651        1.9   mycroft 
    652       1.95    dyoung 	p(ICMP_STAT_ERROR, "\t%" PRIu64 " call%s to icmp_error\n");
    653       1.79   thorpej 	p(ICMP_STAT_OLDICMP,
    654       1.95    dyoung 	    "\t%" PRIu64 " error%s not generated because old message was icmp\n");
    655        1.1       cgd 	for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
    656       1.79   thorpej 		if (icmpstat[ICMP_STAT_OUTHIST + i] != 0) {
    657        1.1       cgd 			if (first) {
    658        1.1       cgd 				printf("\tOutput histogram:\n");
    659        1.1       cgd 				first = 0;
    660        1.1       cgd 			}
    661  1.100.2.1      yamt 			printf("\t\t%s: %" PRIu64 "\n", icmp_type[i],
    662       1.95    dyoung 			   icmpstat[ICMP_STAT_OUTHIST + i]);
    663        1.1       cgd 		}
    664       1.95    dyoung 	p(ICMP_STAT_BADCODE, "\t%" PRIu64 " message%s with bad code fields\n");
    665       1.95    dyoung 	p(ICMP_STAT_TOOSHORT, "\t%" PRIu64 " message%s < minimum length\n");
    666       1.95    dyoung 	p(ICMP_STAT_CHECKSUM, "\t%" PRIu64 " bad checksum%s\n");
    667       1.95    dyoung 	p(ICMP_STAT_BADLEN, "\t%" PRIu64 " message%s with bad length\n");
    668       1.95    dyoung 	p(ICMP_STAT_BMCASTECHO, "\t%" PRIu64 " multicast echo request%s ignored\n");
    669       1.95    dyoung 	p(ICMP_STAT_BMCASTTSTAMP, "\t%" PRIu64 " multicast timestamp request%s ignored\n");
    670        1.1       cgd 	for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
    671       1.79   thorpej 		if (icmpstat[ICMP_STAT_INHIST + i] != 0) {
    672        1.1       cgd 			if (first) {
    673        1.1       cgd 				printf("\tInput histogram:\n");
    674        1.1       cgd 				first = 0;
    675        1.1       cgd 			}
    676  1.100.2.1      yamt 			printf("\t\t%s: %" PRIu64 "\n", icmp_type[i],
    677       1.95    dyoung 			    icmpstat[ICMP_STAT_INHIST + i]);
    678        1.1       cgd 		}
    679       1.95    dyoung 	p(ICMP_STAT_REFLECT, "\t%" PRIu64 " message response%s generated\n");
    680       1.95    dyoung 	p(ICMP_STAT_PMTUCHG, "\t%" PRIu64 " path MTU change%s\n");
    681        1.9   mycroft #undef p
    682        1.6    brezak }
    683        1.6    brezak 
    684        1.6    brezak /*
    685        1.9   mycroft  * Dump IGMP statistics structure.
    686        1.6    brezak  */
    687        1.6    brezak void
    688       1.90     lukem igmp_stats(u_long off, const char *name)
    689        1.6    brezak {
    690       1.87   thorpej 	uint64_t igmpstat[IGMP_NSTATS];
    691       1.87   thorpej 
    692       1.87   thorpej 	if (use_sysctl) {
    693       1.87   thorpej 		size_t size = sizeof(igmpstat);
    694       1.87   thorpej 
    695       1.87   thorpej 		if (sysctlbyname("net.inet.igmp.stats", igmpstat, &size,
    696       1.87   thorpej 				 NULL, 0) == -1)
    697       1.88   thorpej 			return;
    698       1.87   thorpej 	} else {
    699       1.88   thorpej 		warnx("%s stats not available via KVM.", name);
    700       1.88   thorpej 		return;
    701       1.87   thorpej 	}
    702        1.6    brezak 
    703        1.9   mycroft 	printf("%s:\n", name);
    704        1.9   mycroft 
    705       1.87   thorpej #define	p(f, m) if (igmpstat[f] || sflag <= 1) \
    706       1.95    dyoung     printf(m, igmpstat[f], plural(igmpstat[f]))
    707       1.87   thorpej #define	py(f, m) if (igmpstat[f] || sflag <= 1) \
    708       1.95    dyoung     printf(m, igmpstat[f], igmpstat[f] != 1 ? "ies" : "y")
    709       1.95    dyoung 	p(IGMP_STAT_RCV_TOTAL, "\t%" PRIu64 " message%s received\n");
    710       1.95    dyoung         p(IGMP_STAT_RCV_TOOSHORT, "\t%" PRIu64 " message%s received with too few bytes\n");
    711       1.95    dyoung         p(IGMP_STAT_RCV_BADSUM, "\t%" PRIu64 " message%s received with bad checksum\n");
    712       1.95    dyoung         py(IGMP_STAT_RCV_QUERIES, "\t%" PRIu64 " membership quer%s received\n");
    713       1.95    dyoung         py(IGMP_STAT_RCV_BADQUERIES, "\t%" PRIu64 " membership quer%s received with invalid field(s)\n");
    714       1.95    dyoung         p(IGMP_STAT_RCV_REPORTS, "\t%" PRIu64 " membership report%s received\n");
    715       1.95    dyoung         p(IGMP_STAT_RCV_BADREPORTS, "\t%" PRIu64 " membership report%s received with invalid field(s)\n");
    716       1.95    dyoung         p(IGMP_STAT_RCV_OURREPORTS, "\t%" PRIu64 " membership report%s received for groups to which we belong\n");
    717       1.95    dyoung         p(IGMP_STAT_SND_REPORTS, "\t%" PRIu64 " membership report%s sent\n");
    718        1.9   mycroft #undef p
    719        1.9   mycroft #undef py
    720       1.41     jhawk }
    721       1.41     jhawk 
    722       1.41     jhawk /*
    723       1.69  liamjfoy  * Dump CARP statistics structure.
    724       1.69  liamjfoy  */
    725       1.69  liamjfoy void
    726       1.90     lukem carp_stats(u_long off, const char *name)
    727       1.69  liamjfoy {
    728       1.85   thorpej 	uint64_t carpstat[CARP_NSTATS];
    729       1.69  liamjfoy 
    730       1.69  liamjfoy 	if (use_sysctl) {
    731       1.69  liamjfoy 		size_t size = sizeof(carpstat);
    732       1.69  liamjfoy 
    733       1.85   thorpej 		if (sysctlbyname("net.inet.carp.stats", carpstat, &size,
    734       1.88   thorpej 				 NULL, 0) == -1)
    735       1.73    rpaulo 			return;
    736       1.69  liamjfoy 	} else {
    737       1.88   thorpej 		warnx("%s stats not available via KVM.", name);
    738       1.88   thorpej 		return;
    739       1.69  liamjfoy 	}
    740       1.69  liamjfoy 
    741       1.69  liamjfoy 	printf("%s:\n", name);
    742       1.69  liamjfoy 
    743       1.85   thorpej #define p(f, m) if (carpstat[f] || sflag <= 1) \
    744       1.85   thorpej 	printf(m, carpstat[f], plural(carpstat[f]))
    745       1.85   thorpej #define p2(f, m) if (carpstat[f] || sflag <= 1) \
    746       1.85   thorpej 	printf(m, carpstat[f])
    747       1.85   thorpej 
    748       1.85   thorpej 	p(CARP_STAT_IPACKETS, "\t%" PRIu64 " packet%s received (IPv4)\n");
    749       1.85   thorpej 	p(CARP_STAT_IPACKETS6, "\t%" PRIu64 " packet%s received (IPv6)\n");
    750       1.85   thorpej 	p(CARP_STAT_BADIF,
    751       1.70       riz 	    "\t\t%" PRIu64 " packet%s discarded for bad interface\n");
    752       1.85   thorpej 	p(CARP_STAT_BADTTL,
    753       1.70       riz 	    "\t\t%" PRIu64 " packet%s discarded for wrong TTL\n");
    754       1.85   thorpej 	p(CARP_STAT_HDROPS, "\t\t%" PRIu64 " packet%s shorter than header\n");
    755       1.85   thorpej 	p(CARP_STAT_BADSUM, "\t\t%" PRIu64
    756       1.70       riz 		" packet%s discarded for bad checksum\n");
    757       1.85   thorpej 	p(CARP_STAT_BADVER,
    758       1.70       riz 	    "\t\t%" PRIu64 " packet%s discarded with a bad version\n");
    759       1.85   thorpej 	p2(CARP_STAT_BADLEN,
    760       1.70       riz 	    "\t\t%" PRIu64 " discarded because packet was too short\n");
    761       1.85   thorpej 	p(CARP_STAT_BADAUTH,
    762       1.70       riz 	    "\t\t%" PRIu64 " packet%s discarded for bad authentication\n");
    763       1.85   thorpej 	p(CARP_STAT_BADVHID, "\t\t%" PRIu64 " packet%s discarded for bad vhid\n");
    764       1.85   thorpej 	p(CARP_STAT_BADADDRS, "\t\t%" PRIu64
    765       1.70       riz 		" packet%s discarded because of a bad address list\n");
    766       1.85   thorpej 	p(CARP_STAT_OPACKETS, "\t%" PRIu64 " packet%s sent (IPv4)\n");
    767       1.85   thorpej 	p(CARP_STAT_OPACKETS6, "\t%" PRIu64 " packet%s sent (IPv6)\n");
    768       1.85   thorpej 	p2(CARP_STAT_ONOMEM,
    769       1.70       riz 	    "\t\t%" PRIu64 " send failed due to mbuf memory error\n");
    770       1.69  liamjfoy #undef p
    771       1.69  liamjfoy #undef p2
    772       1.69  liamjfoy }
    773       1.69  liamjfoy 
    774       1.69  liamjfoy /*
    775       1.62      manu  * Dump PIM statistics structure.
    776       1.62      manu  */
    777       1.62      manu void
    778       1.90     lukem pim_stats(u_long off, const char *name)
    779       1.62      manu {
    780       1.62      manu 	struct pimstat pimstat;
    781       1.62      manu 
    782       1.62      manu 	if (off == 0)
    783       1.62      manu 		return;
    784       1.62      manu 	if (kread(off, (char *)&pimstat, sizeof (pimstat)) != 0) {
    785       1.62      manu 		/* XXX: PIM is probably not enabled in the kernel */
    786       1.62      manu 		return;
    787       1.62      manu 	}
    788       1.62      manu 
    789       1.62      manu 	printf("%s:\n", name);
    790       1.62      manu 
    791       1.62      manu #define	p(f, m) if (pimstat.f || sflag <= 1) \
    792       1.95    dyoung 	printf(m, pimstat.f, plural(pimstat.f))
    793       1.62      manu 
    794       1.95    dyoung 	p(pims_rcv_total_msgs, "\t%" PRIu64 " message%s received\n");
    795       1.95    dyoung 	p(pims_rcv_total_bytes, "\t%" PRIu64 " byte%s received\n");
    796       1.95    dyoung 	p(pims_rcv_tooshort, "\t%" PRIu64 " message%s received with too few bytes\n");
    797       1.95    dyoung         p(pims_rcv_badsum, "\t%" PRIu64 " message%s received with bad checksum\n");
    798       1.95    dyoung 	p(pims_rcv_badversion, "\t%" PRIu64 " message%s received with bad version\n");
    799       1.95    dyoung 	p(pims_rcv_registers_msgs, "\t%" PRIu64 " data register message%s received\n");
    800       1.95    dyoung 	p(pims_rcv_registers_bytes, "\t%" PRIu64 " data register byte%s received\n");
    801       1.95    dyoung 	p(pims_rcv_registers_wrongiif, "\t%" PRIu64 " data register message%s received on wrong iif\n");
    802       1.95    dyoung 	p(pims_rcv_badregisters, "\t%" PRIu64 " bad register%s received\n");
    803       1.95    dyoung 	p(pims_snd_registers_msgs, "\t%" PRIu64 " data register message%s sent\n");
    804       1.95    dyoung 	p(pims_snd_registers_bytes, "\t%" PRIu64 " data register byte%s sent\n");
    805       1.62      manu #undef p
    806       1.62      manu }
    807       1.62      manu 
    808       1.62      manu /*
    809       1.41     jhawk  * Dump the ARP statistics structure.
    810       1.41     jhawk  */
    811       1.41     jhawk void
    812       1.90     lukem arp_stats(u_long off, const char *name)
    813       1.41     jhawk {
    814       1.86   thorpej 	uint64_t arpstat[ARP_NSTATS];
    815       1.86   thorpej 
    816       1.86   thorpej 	if (use_sysctl) {
    817       1.86   thorpej 		size_t size = sizeof(arpstat);
    818       1.86   thorpej 
    819       1.86   thorpej 		if (sysctlbyname("net.inet.arp.stats", arpstat, &size,
    820       1.88   thorpej 				 NULL, 0) == -1)
    821       1.86   thorpej 			return;
    822       1.86   thorpej 	} else {
    823       1.88   thorpej 		warnx("%s stats not available via KVM.", name);
    824       1.88   thorpej 		return;
    825       1.86   thorpej 	}
    826       1.41     jhawk 
    827       1.41     jhawk 	printf("%s:\n", name);
    828       1.41     jhawk 
    829       1.86   thorpej #define	ps(f, m) if (arpstat[f] || sflag <= 1) \
    830       1.95    dyoung     printf(m, arpstat[f])
    831       1.86   thorpej #define	p(f, m) if (arpstat[f] || sflag <= 1) \
    832       1.95    dyoung     printf(m, arpstat[f], plural(arpstat[f]))
    833       1.86   thorpej 
    834       1.95    dyoung 	p(ARP_STAT_SNDTOTAL, "\t%" PRIu64 " packet%s sent\n");
    835       1.95    dyoung 	p(ARP_STAT_SNDREPLY, "\t\t%" PRIu64 " reply packet%s\n");
    836       1.95    dyoung 	p(ARP_STAT_SENDREQUEST, "\t\t%" PRIu64 " request packet%s\n");
    837       1.95    dyoung 
    838       1.95    dyoung 	p(ARP_STAT_RCVTOTAL, "\t%" PRIu64 " packet%s received\n");
    839       1.95    dyoung 	p(ARP_STAT_RCVREPLY, "\t\t%" PRIu64 " reply packet%s\n");
    840       1.95    dyoung 	p(ARP_STAT_RCVREQUEST, "\t\t%" PRIu64 " valid request packet%s\n");
    841       1.95    dyoung 	p(ARP_STAT_RCVMCAST, "\t\t%" PRIu64 " broadcast/multicast packet%s\n");
    842       1.95    dyoung 	p(ARP_STAT_RCVBADPROTO, "\t\t%" PRIu64 " packet%s with unknown protocol type\n");
    843       1.95    dyoung 	p(ARP_STAT_RCVBADLEN, "\t\t%" PRIu64 " packet%s with bad (short) length\n");
    844       1.95    dyoung 	p(ARP_STAT_RCVZEROTPA, "\t\t%" PRIu64 " packet%s with null target IP address\n");
    845       1.95    dyoung 	p(ARP_STAT_RCVZEROSPA, "\t\t%" PRIu64 " packet%s with null source IP address\n");
    846       1.95    dyoung 	ps(ARP_STAT_RCVNOINT, "\t\t%" PRIu64 " could not be mapped to an interface\n");
    847       1.95    dyoung 	p(ARP_STAT_RCVLOCALSHA, "\t\t%" PRIu64 " packet%s sourced from a local hardware "
    848       1.41     jhawk 	    "address\n");
    849       1.95    dyoung 	p(ARP_STAT_RCVBCASTSHA, "\t\t%" PRIu64 " packet%s with a broadcast "
    850       1.41     jhawk 	    "source hardware address\n");
    851       1.95    dyoung 	p(ARP_STAT_RCVLOCALSPA, "\t\t%" PRIu64 " duplicate%s for a local IP address\n");
    852       1.95    dyoung 	p(ARP_STAT_RCVOVERPERM, "\t\t%" PRIu64 " attempt%s to overwrite a static entry\n");
    853       1.95    dyoung 	p(ARP_STAT_RCVOVERINT, "\t\t%" PRIu64 " packet%s received on wrong interface\n");
    854       1.95    dyoung 	p(ARP_STAT_RCVOVER, "\t\t%" PRIu64 " entry%s overwritten\n");
    855       1.95    dyoung 	p(ARP_STAT_RCVLENCHG, "\t\t%" PRIu64 " change%s in hardware address length\n");
    856       1.95    dyoung 
    857       1.95    dyoung 	p(ARP_STAT_DFRTOTAL, "\t%" PRIu64 " packet%s deferred pending ARP resolution\n");
    858       1.95    dyoung 	ps(ARP_STAT_DFRSENT, "\t\t%" PRIu64 " sent\n");
    859       1.95    dyoung 	ps(ARP_STAT_DFRDROPPED, "\t\t%" PRIu64 " dropped\n");
    860       1.41     jhawk 
    861       1.95    dyoung 	p(ARP_STAT_ALLOCFAIL, "\t%" PRIu64 " failure%s to allocate llinfo\n");
    862       1.41     jhawk 
    863       1.41     jhawk #undef ps
    864       1.41     jhawk #undef p
    865        1.1       cgd }
    866        1.1       cgd 
    867        1.1       cgd /*
    868        1.1       cgd  * Pretty print an Internet address (net address + port).
    869       1.46     assar  * Take numeric_addr and numeric_port into consideration.
    870        1.1       cgd  */
    871        1.9   mycroft void
    872       1.84   thorpej inetprint(struct in_addr *in, uint16_t port, const char *proto,
    873       1.90     lukem 	  int port_numeric)
    874        1.1       cgd {
    875        1.1       cgd 	struct servent *sp = 0;
    876        1.9   mycroft 	char line[80], *cp;
    877       1.33  sommerfe 	size_t space;
    878        1.1       cgd 
    879       1.32       mrg 	(void)snprintf(line, sizeof line, "%.*s.",
    880       1.46     assar 	    (Aflag && !numeric_addr) ? 12 : 16, inetname(in));
    881       1.23     lukem 	cp = strchr(line, '\0');
    882       1.90     lukem 	if (!port_numeric && port)
    883        1.1       cgd 		sp = getservbyport((int)port, proto);
    884       1.33  sommerfe 	space = sizeof line - (cp-line);
    885        1.1       cgd 	if (sp || port == 0)
    886       1.55  jdolecek 		(void)snprintf(cp, space, "%s", sp ? sp->s_name : "*");
    887        1.1       cgd 	else
    888       1.33  sommerfe 		(void)snprintf(cp, space, "%u", ntohs(port));
    889       1.32       mrg 	(void)printf(" %-*.*s", width, width, line);
    890        1.1       cgd }
    891        1.1       cgd 
    892        1.1       cgd /*
    893        1.1       cgd  * Construct an Internet address representation.
    894       1.46     assar  * If numeric_addr has been supplied, give
    895        1.1       cgd  * numeric value, otherwise try for symbolic name.
    896        1.1       cgd  */
    897        1.1       cgd char *
    898       1.84   thorpej inetname(struct in_addr *inp)
    899        1.1       cgd {
    900       1.23     lukem 	char *cp;
    901        1.1       cgd 	static char line[50];
    902        1.1       cgd 	struct hostent *hp;
    903        1.1       cgd 	struct netent *np;
    904        1.1       cgd 	static char domain[MAXHOSTNAMELEN + 1];
    905        1.1       cgd 	static int first = 1;
    906        1.1       cgd 
    907       1.46     assar 	if (first && !numeric_addr) {
    908        1.1       cgd 		first = 0;
    909       1.31       mrg 		if (gethostname(domain, sizeof domain) == 0) {
    910       1.31       mrg 			domain[sizeof(domain) - 1] = '\0';
    911       1.31       mrg 			if ((cp = strchr(domain, '.')))
    912       1.45    itojun 				(void) strlcpy(domain, cp + 1, sizeof(domain));
    913       1.31       mrg 			else
    914       1.31       mrg 				domain[0] = 0;
    915       1.31       mrg 		} else
    916        1.1       cgd 			domain[0] = 0;
    917        1.1       cgd 	}
    918        1.1       cgd 	cp = 0;
    919       1.46     assar 	if (!numeric_addr && inp->s_addr != INADDR_ANY) {
    920        1.9   mycroft 		int net = inet_netof(*inp);
    921        1.9   mycroft 		int lna = inet_lnaof(*inp);
    922        1.1       cgd 
    923        1.1       cgd 		if (lna == INADDR_ANY) {
    924        1.1       cgd 			np = getnetbyaddr(net, AF_INET);
    925        1.1       cgd 			if (np)
    926        1.1       cgd 				cp = np->n_name;
    927        1.1       cgd 		}
    928        1.1       cgd 		if (cp == 0) {
    929        1.9   mycroft 			hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
    930        1.1       cgd 			if (hp) {
    931       1.23     lukem 				if ((cp = strchr(hp->h_name, '.')) &&
    932        1.1       cgd 				    !strcmp(cp + 1, domain))
    933        1.1       cgd 					*cp = 0;
    934        1.1       cgd 				cp = hp->h_name;
    935        1.1       cgd 			}
    936        1.1       cgd 		}
    937        1.1       cgd 	}
    938        1.9   mycroft 	if (inp->s_addr == INADDR_ANY)
    939       1.56    itojun 		strlcpy(line, "*", sizeof line);
    940        1.1       cgd 	else if (cp)
    941       1.56    itojun 		strlcpy(line, cp, sizeof line);
    942        1.1       cgd 	else {
    943        1.9   mycroft 		inp->s_addr = ntohl(inp->s_addr);
    944        1.1       cgd #define C(x)	((x) & 0xff)
    945       1.32       mrg 		(void)snprintf(line, sizeof line, "%u.%u.%u.%u",
    946       1.32       mrg 		    C(inp->s_addr >> 24), C(inp->s_addr >> 16),
    947       1.32       mrg 		    C(inp->s_addr >> 8), C(inp->s_addr));
    948       1.32       mrg #undef C
    949        1.1       cgd 	}
    950        1.1       cgd 	return (line);
    951       1.30   thorpej }
    952       1.30   thorpej 
    953       1.30   thorpej /*
    954       1.30   thorpej  * Dump the contents of a TCP PCB.
    955       1.30   thorpej  */
    956       1.30   thorpej void
    957  1.100.2.2      yamt tcp_dump(u_long off, const char *name, u_long pcbaddr)
    958       1.30   thorpej {
    959       1.78        ad 	callout_impl_t *ci;
    960       1.30   thorpej 	struct tcpcb tcpcb;
    961       1.54   thorpej 	int i, hardticks;
    962  1.100.2.2      yamt 	struct kinfo_pcb *pcblist;
    963  1.100.2.2      yamt 	size_t j, len;
    964  1.100.2.2      yamt 
    965  1.100.2.2      yamt 	if (use_sysctl)
    966  1.100.2.2      yamt 		pcblist = getpcblist_sysctl(name, &len);
    967  1.100.2.2      yamt 	else
    968  1.100.2.2      yamt 		pcblist = getpcblist_kmem(off, name, &len);
    969  1.100.2.2      yamt 
    970  1.100.2.2      yamt 	for (j = 0; j < len; j++)
    971  1.100.2.2      yamt 		if (pcblist[j].ki_ppcbaddr == pcbaddr)
    972  1.100.2.2      yamt 			break;
    973  1.100.2.2      yamt 	free(pcblist);
    974  1.100.2.2      yamt 
    975  1.100.2.2      yamt 	if (j == len)
    976  1.100.2.2      yamt 		errx(1, "0x%lx is not a valid pcb address", pcbaddr);
    977       1.30   thorpej 
    978       1.30   thorpej 	kread(pcbaddr, (char *)&tcpcb, sizeof(tcpcb));
    979       1.54   thorpej 	hardticks = get_hardticks();
    980       1.30   thorpej 
    981       1.30   thorpej 	printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
    982       1.30   thorpej 
    983       1.30   thorpej 	printf("Timers:\n");
    984       1.48   thorpej 	for (i = 0; i < TCPT_NTIMERS; i++) {
    985       1.78        ad 		ci = (callout_impl_t *)&tcpcb.t_timer[i];
    986       1.54   thorpej 		printf("\t%s: %d", tcptimers[i],
    987       1.78        ad 		    (ci->c_flags & CALLOUT_PENDING) ?
    988       1.78        ad 		    ci->c_time - hardticks : 0);
    989       1.48   thorpej 	}
    990       1.30   thorpej 	printf("\n\n");
    991       1.30   thorpej 
    992       1.30   thorpej 	if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
    993       1.30   thorpej 		printf("State: %d", tcpcb.t_state);
    994       1.30   thorpej 	else
    995       1.30   thorpej 		printf("State: %s", tcpstates[tcpcb.t_state]);
    996       1.49   thorpej 	printf(", flags 0x%x, inpcb 0x%lx, in6pcb 0x%lx\n\n", tcpcb.t_flags,
    997       1.49   thorpej 	    (u_long)tcpcb.t_inpcb, (u_long)tcpcb.t_in6pcb);
    998       1.30   thorpej 
    999       1.30   thorpej 	printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcpcb.t_rxtshift,
   1000       1.30   thorpej 	    tcpcb.t_rxtcur, tcpcb.t_dupacks);
   1001      1.100  shattere         printf("peermss %u, ourmss %u, segsz %u, segqlen %u\n\n",
   1002      1.100  shattere 	    tcpcb.t_peermss, tcpcb.t_ourmss, tcpcb.t_segsz, tcpcb.t_segqlen);
   1003       1.30   thorpej 
   1004       1.30   thorpej 	printf("snd_una %u, snd_nxt %u, snd_up %u\n",
   1005       1.30   thorpej 	    tcpcb.snd_una, tcpcb.snd_nxt, tcpcb.snd_up);
   1006       1.30   thorpej 	printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %lu\n\n",
   1007       1.30   thorpej 	    tcpcb.snd_wl1, tcpcb.snd_wl2, tcpcb.iss, tcpcb.snd_wnd);
   1008       1.30   thorpej 
   1009       1.30   thorpej 	printf("rcv_wnd %lu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
   1010       1.30   thorpej 	    tcpcb.rcv_wnd, tcpcb.rcv_nxt, tcpcb.rcv_up, tcpcb.irs);
   1011       1.30   thorpej 
   1012       1.30   thorpej 	printf("rcv_adv %u, snd_max %u, snd_cwnd %lu, snd_ssthresh %lu\n",
   1013       1.30   thorpej 	    tcpcb.rcv_adv, tcpcb.snd_max, tcpcb.snd_cwnd, tcpcb.snd_ssthresh);
   1014       1.30   thorpej 
   1015       1.47   thorpej 	printf("rcvtime %u, rtttime %u, rtseq %u, srtt %d, rttvar %d, "
   1016       1.47   thorpej 	    "rttmin %d, max_sndwnd %lu\n\n", tcpcb.t_rcvtime, tcpcb.t_rtttime,
   1017       1.47   thorpej 	    tcpcb.t_rtseq, tcpcb.t_srtt, tcpcb.t_rttvar, tcpcb.t_rttmin,
   1018       1.47   thorpej 	    tcpcb.max_sndwnd);
   1019       1.30   thorpej 
   1020       1.30   thorpej 	printf("oobflags %d, iobc %d, softerror %d\n\n", tcpcb.t_oobflags,
   1021       1.30   thorpej 	    tcpcb.t_iobc, tcpcb.t_softerror);
   1022       1.30   thorpej 
   1023       1.30   thorpej 	printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
   1024       1.30   thorpej 	    tcpcb.snd_scale, tcpcb.rcv_scale, tcpcb.request_r_scale,
   1025       1.30   thorpej 	    tcpcb.requested_s_scale);
   1026       1.30   thorpej 	printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
   1027       1.30   thorpej 	    tcpcb.ts_recent, tcpcb.ts_recent_age, tcpcb.last_ack_sent);
   1028        1.1       cgd }
   1029