xref: /freebsd/usr.bin/netstat/inet.c (revision cc65eb4e792a203a8b4a17b0e3af7831e5044eca)
165475bc8SDavid E. O'Brien /*-
205ddff6eSPeter Wemm  * Copyright (c) 1983, 1988, 1993, 1995
39b50d902SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
49b50d902SRodney W. Grimes  *
59b50d902SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
69b50d902SRodney W. Grimes  * modification, are permitted provided that the following conditions
79b50d902SRodney W. Grimes  * are met:
89b50d902SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
99b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
109b50d902SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
119b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
129b50d902SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
149b50d902SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
159b50d902SRodney W. Grimes  *    without specific prior written permission.
169b50d902SRodney W. Grimes  *
179b50d902SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
189b50d902SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199b50d902SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209b50d902SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
219b50d902SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
229b50d902SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
239b50d902SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249b50d902SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
259b50d902SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
269b50d902SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
279b50d902SRodney W. Grimes  * SUCH DAMAGE.
289b50d902SRodney W. Grimes  */
299b50d902SRodney W. Grimes 
306cc6f122SPhilippe Charnier #if 0
319b50d902SRodney W. Grimes #ifndef lint
3205ddff6eSPeter Wemm static char sccsid[] = "@(#)inet.c	8.5 (Berkeley) 5/24/95";
339b50d902SRodney W. Grimes #endif /* not lint */
346cc6f122SPhilippe Charnier #endif
356cc6f122SPhilippe Charnier 
366cc6f122SPhilippe Charnier #include <sys/cdefs.h>
376cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$");
389b50d902SRodney W. Grimes 
399b50d902SRodney W. Grimes #include <sys/param.h>
40d8d89152SDavid Greenman #include <sys/queue.h>
41feda1a43SJohn Baldwin #include <sys/domain.h>
42f35a2092SMaksim Yevmenkin #include <sys/protosw.h>
439b50d902SRodney W. Grimes #include <sys/socket.h>
449b50d902SRodney W. Grimes #include <sys/socketvar.h>
454e00c309SGarrett Wollman #include <sys/sysctl.h>
469b50d902SRodney W. Grimes 
479b50d902SRodney W. Grimes #include <net/route.h>
4854fc657dSGeorge V. Neville-Neil #include <net/if_arp.h>
499b50d902SRodney W. Grimes #include <netinet/in.h>
509b50d902SRodney W. Grimes #include <netinet/in_systm.h>
519b50d902SRodney W. Grimes #include <netinet/ip.h>
52a9771948SGleb Smirnoff #include <netinet/ip_carp.h>
53cfa1ca9dSYoshinobu Inoue #ifdef INET6
54cfa1ca9dSYoshinobu Inoue #include <netinet/ip6.h>
55cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
569b50d902SRodney W. Grimes #include <netinet/in_pcb.h>
579b50d902SRodney W. Grimes #include <netinet/ip_icmp.h>
589b50d902SRodney W. Grimes #include <netinet/icmp_var.h>
599b50d902SRodney W. Grimes #include <netinet/igmp_var.h>
609b50d902SRodney W. Grimes #include <netinet/ip_var.h>
61c7b9b5bbSJeffrey Hsu #include <netinet/pim_var.h>
629b50d902SRodney W. Grimes #include <netinet/tcp.h>
639b50d902SRodney W. Grimes #include <netinet/tcpip.h>
649b50d902SRodney W. Grimes #include <netinet/tcp_seq.h>
659b50d902SRodney W. Grimes #define	TCPSTATES
669b50d902SRodney W. Grimes #include <netinet/tcp_fsm.h>
679b50d902SRodney W. Grimes #include <netinet/tcp_timer.h>
689b50d902SRodney W. Grimes #include <netinet/tcp_var.h>
699b50d902SRodney W. Grimes #include <netinet/udp.h>
709b50d902SRodney W. Grimes #include <netinet/udp_var.h>
719b50d902SRodney W. Grimes 
729b50d902SRodney W. Grimes #include <arpa/inet.h>
734f81ef50SGarrett Wollman #include <err.h>
744f81ef50SGarrett Wollman #include <errno.h>
75d121b556SBrian Somers #include <libutil.h>
769b50d902SRodney W. Grimes #include <netdb.h>
777b95a1ebSYaroslav Tykhiy #include <stdint.h>
789b50d902SRodney W. Grimes #include <stdio.h>
794f81ef50SGarrett Wollman #include <stdlib.h>
80ade9ccfeSMarcel Moolenaar #include <stdbool.h>
819b50d902SRodney W. Grimes #include <string.h>
829b50d902SRodney W. Grimes #include <unistd.h>
83ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
849b50d902SRodney W. Grimes #include "netstat.h"
85dbfd8708SGleb Smirnoff #include "nl_defs.h"
869b50d902SRodney W. Grimes 
87046aad39SHajimu UMEMOTO void	inetprint(const char *, struct in_addr *, int, const char *, int,
88046aad39SHajimu UMEMOTO     const int);
89cfa1ca9dSYoshinobu Inoue #ifdef INET6
90aa0a1e58SJeff Roberson static int udp_done, tcp_done, sdp_done;
91cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
929b50d902SRodney W. Grimes 
93feda1a43SJohn Baldwin static int
94*cc65eb4eSGleb Smirnoff pcblist_sysctl(int proto, const char *name, char **bufp)
95feda1a43SJohn Baldwin {
96feda1a43SJohn Baldwin 	const char *mibvar;
97feda1a43SJohn Baldwin 	char *buf;
98feda1a43SJohn Baldwin 	size_t len;
99feda1a43SJohn Baldwin 
100feda1a43SJohn Baldwin 	switch (proto) {
101feda1a43SJohn Baldwin 	case IPPROTO_TCP:
102feda1a43SJohn Baldwin 		mibvar = "net.inet.tcp.pcblist";
103feda1a43SJohn Baldwin 		break;
104feda1a43SJohn Baldwin 	case IPPROTO_UDP:
105feda1a43SJohn Baldwin 		mibvar = "net.inet.udp.pcblist";
106feda1a43SJohn Baldwin 		break;
107feda1a43SJohn Baldwin 	case IPPROTO_DIVERT:
108feda1a43SJohn Baldwin 		mibvar = "net.inet.divert.pcblist";
109feda1a43SJohn Baldwin 		break;
110feda1a43SJohn Baldwin 	default:
111feda1a43SJohn Baldwin 		mibvar = "net.inet.raw.pcblist";
112feda1a43SJohn Baldwin 		break;
113feda1a43SJohn Baldwin 	}
114aa0a1e58SJeff Roberson 	if (strncmp(name, "sdp", 3) == 0)
115aa0a1e58SJeff Roberson 		mibvar = "net.inet.sdp.pcblist";
116feda1a43SJohn Baldwin 	len = 0;
117feda1a43SJohn Baldwin 	if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) {
118feda1a43SJohn Baldwin 		if (errno != ENOENT)
119ade9ccfeSMarcel Moolenaar 			xo_warn("sysctl: %s", mibvar);
120feda1a43SJohn Baldwin 		return (0);
121feda1a43SJohn Baldwin 	}
122ef1cb629SMarcelo Araujo 	if ((buf = malloc(len)) == NULL) {
123ade9ccfeSMarcel Moolenaar 		xo_warnx("malloc %lu bytes", (u_long)len);
124feda1a43SJohn Baldwin 		return (0);
125feda1a43SJohn Baldwin 	}
126feda1a43SJohn Baldwin 	if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) {
127ade9ccfeSMarcel Moolenaar 		xo_warn("sysctl: %s", mibvar);
128feda1a43SJohn Baldwin 		free(buf);
129feda1a43SJohn Baldwin 		return (0);
130feda1a43SJohn Baldwin 	}
131feda1a43SJohn Baldwin 	*bufp = buf;
132feda1a43SJohn Baldwin 	return (1);
133feda1a43SJohn Baldwin }
134feda1a43SJohn Baldwin 
135feda1a43SJohn Baldwin /*
136feda1a43SJohn Baldwin  * Copied directly from uipc_socket2.c.  We leave out some fields that are in
137feda1a43SJohn Baldwin  * nested structures that aren't used to avoid extra work.
138feda1a43SJohn Baldwin  */
139feda1a43SJohn Baldwin static void
140feda1a43SJohn Baldwin sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb)
141feda1a43SJohn Baldwin {
1420f9d0a73SGleb Smirnoff 	xsb->sb_cc = sb->sb_ccc;
143feda1a43SJohn Baldwin 	xsb->sb_hiwat = sb->sb_hiwat;
144feda1a43SJohn Baldwin 	xsb->sb_mbcnt = sb->sb_mbcnt;
14549f287f8SGeorge V. Neville-Neil 	xsb->sb_mcnt = sb->sb_mcnt;
14649f287f8SGeorge V. Neville-Neil 	xsb->sb_ccnt = sb->sb_ccnt;
147feda1a43SJohn Baldwin 	xsb->sb_mbmax = sb->sb_mbmax;
148feda1a43SJohn Baldwin 	xsb->sb_lowat = sb->sb_lowat;
149feda1a43SJohn Baldwin 	xsb->sb_flags = sb->sb_flags;
150feda1a43SJohn Baldwin 	xsb->sb_timeo = sb->sb_timeo;
151feda1a43SJohn Baldwin }
152feda1a43SJohn Baldwin 
153feda1a43SJohn Baldwin int
154feda1a43SJohn Baldwin sotoxsocket(struct socket *so, struct xsocket *xso)
155feda1a43SJohn Baldwin {
156feda1a43SJohn Baldwin 	struct protosw proto;
157feda1a43SJohn Baldwin 	struct domain domain;
158feda1a43SJohn Baldwin 
159feda1a43SJohn Baldwin 	bzero(xso, sizeof *xso);
160feda1a43SJohn Baldwin 	xso->xso_len = sizeof *xso;
161feda1a43SJohn Baldwin 	xso->xso_so = so;
162feda1a43SJohn Baldwin 	xso->so_type = so->so_type;
163feda1a43SJohn Baldwin 	xso->so_options = so->so_options;
164feda1a43SJohn Baldwin 	xso->so_linger = so->so_linger;
165feda1a43SJohn Baldwin 	xso->so_state = so->so_state;
166feda1a43SJohn Baldwin 	xso->so_pcb = so->so_pcb;
167feda1a43SJohn Baldwin 	if (kread((uintptr_t)so->so_proto, &proto, sizeof(proto)) != 0)
168feda1a43SJohn Baldwin 		return (-1);
169feda1a43SJohn Baldwin 	xso->xso_protocol = proto.pr_protocol;
170feda1a43SJohn Baldwin 	if (kread((uintptr_t)proto.pr_domain, &domain, sizeof(domain)) != 0)
171feda1a43SJohn Baldwin 		return (-1);
172feda1a43SJohn Baldwin 	xso->xso_family = domain.dom_family;
173feda1a43SJohn Baldwin 	xso->so_qlen = so->so_qlen;
174feda1a43SJohn Baldwin 	xso->so_incqlen = so->so_incqlen;
175feda1a43SJohn Baldwin 	xso->so_qlimit = so->so_qlimit;
176feda1a43SJohn Baldwin 	xso->so_timeo = so->so_timeo;
177feda1a43SJohn Baldwin 	xso->so_error = so->so_error;
178feda1a43SJohn Baldwin 	xso->so_oobmark = so->so_oobmark;
179feda1a43SJohn Baldwin 	sbtoxsockbuf(&so->so_snd, &xso->so_snd);
180feda1a43SJohn Baldwin 	sbtoxsockbuf(&so->so_rcv, &xso->so_rcv);
181feda1a43SJohn Baldwin 	return (0);
182feda1a43SJohn Baldwin }
183feda1a43SJohn Baldwin 
1849b50d902SRodney W. Grimes /*
1859b50d902SRodney W. Grimes  * Print a summary of connections related to an Internet
1869b50d902SRodney W. Grimes  * protocol.  For TCP, also give state of connection.
1879b50d902SRodney W. Grimes  * Listening processes (aflag) are suppressed unless the
1889b50d902SRodney W. Grimes  * -a (all) flag is specified.
1899b50d902SRodney W. Grimes  */
1909b50d902SRodney W. Grimes void
191feda1a43SJohn Baldwin protopr(u_long off, const char *name, int af1, int proto)
1929b50d902SRodney W. Grimes {
1939b50d902SRodney W. Grimes 	static int first = 1;
194*cc65eb4eSGleb Smirnoff 	int istcp;
1954f81ef50SGarrett Wollman 	char *buf;
196feda1a43SJohn Baldwin 	const char *vchar;
197*cc65eb4eSGleb Smirnoff 	struct xtcpcb *tp;
198*cc65eb4eSGleb Smirnoff 	struct xinpcb *inp;
1994f81ef50SGarrett Wollman 	struct xinpgen *xig, *oxig;
2004f81ef50SGarrett Wollman 	struct xsocket *so;
2019b50d902SRodney W. Grimes 
2024f81ef50SGarrett Wollman 	istcp = 0;
2034f81ef50SGarrett Wollman 	switch (proto) {
2044f81ef50SGarrett Wollman 	case IPPROTO_TCP:
205cfa1ca9dSYoshinobu Inoue #ifdef INET6
206aa0a1e58SJeff Roberson 		if (strncmp(name, "sdp", 3) != 0) {
207cfa1ca9dSYoshinobu Inoue 			if (tcp_done != 0)
208cfa1ca9dSYoshinobu Inoue 				return;
209cfa1ca9dSYoshinobu Inoue 			else
210cfa1ca9dSYoshinobu Inoue 				tcp_done = 1;
211aa0a1e58SJeff Roberson 		} else {
212aa0a1e58SJeff Roberson 			if (sdp_done != 0)
213aa0a1e58SJeff Roberson 				return;
214aa0a1e58SJeff Roberson 			else
215aa0a1e58SJeff Roberson 				sdp_done = 1;
216aa0a1e58SJeff Roberson 		}
217cfa1ca9dSYoshinobu Inoue #endif
2184f81ef50SGarrett Wollman 		istcp = 1;
2194f81ef50SGarrett Wollman 		break;
2204f81ef50SGarrett Wollman 	case IPPROTO_UDP:
221cfa1ca9dSYoshinobu Inoue #ifdef INET6
222cfa1ca9dSYoshinobu Inoue 		if (udp_done != 0)
223cfa1ca9dSYoshinobu Inoue 			return;
224cfa1ca9dSYoshinobu Inoue 		else
225cfa1ca9dSYoshinobu Inoue 			udp_done = 1;
226cfa1ca9dSYoshinobu Inoue #endif
2274f81ef50SGarrett Wollman 		break;
2284f81ef50SGarrett Wollman 	}
229*cc65eb4eSGleb Smirnoff 
230*cc65eb4eSGleb Smirnoff 	if (!pcblist_sysctl(proto, name, &buf))
2319b50d902SRodney W. Grimes 		return;
2324f81ef50SGarrett Wollman 
2334f81ef50SGarrett Wollman 	oxig = xig = (struct xinpgen *)buf;
2344f81ef50SGarrett Wollman 	for (xig = (struct xinpgen *)((char *)xig + xig->xig_len);
2354f81ef50SGarrett Wollman 	    xig->xig_len > sizeof(struct xinpgen);
2364f81ef50SGarrett Wollman 	    xig = (struct xinpgen *)((char *)xig + xig->xig_len)) {
2379b50d902SRodney W. Grimes 		if (istcp) {
238*cc65eb4eSGleb Smirnoff 			tp = (struct xtcpcb *)xig;
239*cc65eb4eSGleb Smirnoff 			inp = &tp->xt_inp;
2404f81ef50SGarrett Wollman 		} else {
241*cc65eb4eSGleb Smirnoff 			inp = (struct xinpcb *)xig;
2429b50d902SRodney W. Grimes 		}
243*cc65eb4eSGleb Smirnoff 		so = &inp->xi_socket;
2444f81ef50SGarrett Wollman 
2454f81ef50SGarrett Wollman 		/* Ignore sockets for protocols other than the desired one. */
246feda1a43SJohn Baldwin 		if (so->xso_protocol != proto)
2474f81ef50SGarrett Wollman 			continue;
2484f81ef50SGarrett Wollman 
2494f81ef50SGarrett Wollman 		/* Ignore PCBs which were freed during copyout. */
2504f81ef50SGarrett Wollman 		if (inp->inp_gencnt > oxig->xig_gen)
2514f81ef50SGarrett Wollman 			continue;
2524f81ef50SGarrett Wollman 
253a01e3379SDavid Malone 		if ((af1 == AF_INET && (inp->inp_vflag & INP_IPV4) == 0)
254cfa1ca9dSYoshinobu Inoue #ifdef INET6
255a01e3379SDavid Malone 		    || (af1 == AF_INET6 && (inp->inp_vflag & INP_IPV6) == 0)
256cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
257a01e3379SDavid Malone 		    || (af1 == AF_UNSPEC && ((inp->inp_vflag & INP_IPV4) == 0
258cfa1ca9dSYoshinobu Inoue #ifdef INET6
2593feeb332SDavid E. O'Brien 					  && (inp->inp_vflag & INP_IPV6) == 0
260cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
261cfa1ca9dSYoshinobu Inoue 			))
262cfa1ca9dSYoshinobu Inoue 		    )
263cfa1ca9dSYoshinobu Inoue 			continue;
264cfa1ca9dSYoshinobu Inoue 		if (!aflag &&
265cfa1ca9dSYoshinobu Inoue 		    (
2662b286cedSBruce M Simpson 		     (istcp && tp->t_state == TCPS_LISTEN)
2672b286cedSBruce M Simpson 		     || (af1 == AF_INET &&
268cfa1ca9dSYoshinobu Inoue 		      inet_lnaof(inp->inp_laddr) == INADDR_ANY)
269cfa1ca9dSYoshinobu Inoue #ifdef INET6
270a01e3379SDavid Malone 		     || (af1 == AF_INET6 &&
271cfa1ca9dSYoshinobu Inoue 			 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
272cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
273a01e3379SDavid Malone 		     || (af1 == AF_UNSPEC &&
274cfa1ca9dSYoshinobu Inoue 			 (((inp->inp_vflag & INP_IPV4) != 0 &&
275cfa1ca9dSYoshinobu Inoue 			   inet_lnaof(inp->inp_laddr) == INADDR_ANY)
276cfa1ca9dSYoshinobu Inoue #ifdef INET6
277cfa1ca9dSYoshinobu Inoue 			  || ((inp->inp_vflag & INP_IPV6) != 0 &&
278cfa1ca9dSYoshinobu Inoue 			      IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
279cfa1ca9dSYoshinobu Inoue #endif
280cfa1ca9dSYoshinobu Inoue 			  ))
281cfa1ca9dSYoshinobu Inoue 		     ))
2824f81ef50SGarrett Wollman 			continue;
2834f81ef50SGarrett Wollman 
2849b50d902SRodney W. Grimes 		if (first) {
285ac55add0SGuido van Rooij 			if (!Lflag) {
286ade9ccfeSMarcel Moolenaar 				xo_emit("Active Internet connections");
2879b50d902SRodney W. Grimes 				if (aflag)
288ade9ccfeSMarcel Moolenaar 					xo_emit(" (including servers)");
289ac55add0SGuido van Rooij 			} else
290ade9ccfeSMarcel Moolenaar 				xo_emit(
291ac55add0SGuido van Rooij 	"Current listen queue sizes (qlen/incqlen/maxqlen)");
292ade9ccfeSMarcel Moolenaar 			xo_emit("\n");
2939b50d902SRodney W. Grimes 			if (Aflag)
294ade9ccfeSMarcel Moolenaar 				xo_emit("{T:/%-*s} ", 2 * (int)sizeof(void *),
295ade9ccfeSMarcel Moolenaar 				    "Tcpcb");
296ac55add0SGuido van Rooij 			if (Lflag)
297ade9ccfeSMarcel Moolenaar 				xo_emit((Aflag && !Wflag) ?
298db2627f4SMichael Tuexen 				    "{T:/%-5.5s} {T:/%-32.32s} {T:/%-18.18s}" :
299046aad39SHajimu UMEMOTO 				    ((!Wflag || af1 == AF_INET) ?
300db2627f4SMichael Tuexen 				    "{T:/%-5.5s} {T:/%-32.32s} {T:/%-22.22s}" :
301db2627f4SMichael Tuexen 				    "{T:/%-5.5s} {T:/%-32.32s} {T:/%-45.45s}"),
302afc74015SRuslan Ermilov 				    "Proto", "Listen", "Local Address");
303afc74015SRuslan Ermilov 			else if (Tflag)
304ade9ccfeSMarcel Moolenaar 				xo_emit((Aflag && !Wflag) ?
305ade9ccfeSMarcel Moolenaar     "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%s}" :
306046aad39SHajimu UMEMOTO 				    ((!Wflag || af1 == AF_INET) ?
307046aad39SHajimu UMEMOTO     "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%s}" :
308046aad39SHajimu UMEMOTO     "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%s}"),
309f5d34df5SGeorge V. Neville-Neil 				    "Proto", "Rexmit", "OOORcv", "0-win",
31049f287f8SGeorge V. Neville-Neil 				    "Local Address", "Foreign Address");
311afc74015SRuslan Ermilov 			else {
312ade9ccfeSMarcel Moolenaar 				xo_emit((Aflag && !Wflag) ?
313ade9ccfeSMarcel Moolenaar     "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%-18.18s}" :
314046aad39SHajimu UMEMOTO 				    ((!Wflag || af1 == AF_INET) ?
315046aad39SHajimu UMEMOTO     "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%-22.22s}" :
316046aad39SHajimu UMEMOTO     "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%-45.45s}"),
317afc74015SRuslan Ermilov 				    "Proto", "Recv-Q", "Send-Q",
318afc74015SRuslan Ermilov 				    "Local Address", "Foreign Address");
31985b0f0f3SAdrian Chadd 				if (!xflag && !Rflag)
320ade9ccfeSMarcel Moolenaar 					xo_emit(" (state)");
321afc74015SRuslan Ermilov 			}
322b8614722SMike Silbersack 			if (xflag) {
323ade9ccfeSMarcel Moolenaar 				xo_emit(" {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} "
324ade9ccfeSMarcel Moolenaar 				    "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} "
325ade9ccfeSMarcel Moolenaar 				    "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} "
326ade9ccfeSMarcel Moolenaar 				    "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s}",
327ade9ccfeSMarcel Moolenaar 				    "R-MBUF", "S-MBUF", "R-CLUS", "S-CLUS",
328ade9ccfeSMarcel Moolenaar 				    "R-HIWA", "S-HIWA", "R-LOWA", "S-LOWA",
329ade9ccfeSMarcel Moolenaar 				    "R-BCNT", "S-BCNT", "R-BMAX", "S-BMAX");
330ade9ccfeSMarcel Moolenaar 				xo_emit(" {T:/%7.7s} {T:/%7.7s} {T:/%7.7s} "
331ade9ccfeSMarcel Moolenaar 				    "{T:/%7.7s} {T:/%7.7s} {T:/%7.7s}",
332ade9ccfeSMarcel Moolenaar 				    "rexmt", "persist", "keep", "2msl",
333ade9ccfeSMarcel Moolenaar 				    "delack", "rcvtime");
33485b0f0f3SAdrian Chadd 			} else if (Rflag) {
335ade9ccfeSMarcel Moolenaar 				xo_emit("  {T:/%8.8s} {T:/%5.5s}",
33685b0f0f3SAdrian Chadd 				    "flowid", "ftype");
33794f138feSGeorge V. Neville-Neil 			}
338ade9ccfeSMarcel Moolenaar 			xo_emit("\n");
3399b50d902SRodney W. Grimes 			first = 0;
3409b50d902SRodney W. Grimes 		}
341fb5d0fbdSRuslan Ermilov 		if (Lflag && so->so_qlimit == 0)
342fb5d0fbdSRuslan Ermilov 			continue;
343ade9ccfeSMarcel Moolenaar 		xo_open_instance("socket");
344e4ec3989SDag-Erling Smørgrav 		if (Aflag) {
345e4ec3989SDag-Erling Smørgrav 			if (istcp)
346ade9ccfeSMarcel Moolenaar 				xo_emit("{q:address/%*lx} ",
347ade9ccfeSMarcel Moolenaar 				    2 * (int)sizeof(void *),
348ade9ccfeSMarcel Moolenaar 				    (u_long)inp->inp_ppcb);
349e4ec3989SDag-Erling Smørgrav 			else
350d9646465SGleb Smirnoff 				xo_emit("{q:address/%*lx} ",
351ade9ccfeSMarcel Moolenaar 				    2 * (int)sizeof(void *),
352ade9ccfeSMarcel Moolenaar 				    (u_long)so->so_pcb);
353e4ec3989SDag-Erling Smørgrav 		}
354cfa1ca9dSYoshinobu Inoue #ifdef INET6
355fc60ab7bSYoshinobu Inoue 		if ((inp->inp_vflag & INP_IPV6) != 0)
3563feeb332SDavid E. O'Brien 			vchar = ((inp->inp_vflag & INP_IPV4) != 0) ?
3573feeb332SDavid E. O'Brien 			    "46" : "6";
358fc60ab7bSYoshinobu Inoue 		else
359cfa1ca9dSYoshinobu Inoue #endif
3603feeb332SDavid E. O'Brien 		vchar = ((inp->inp_vflag & INP_IPV4) != 0) ?
3613feeb332SDavid E. O'Brien 		    "4" : "";
36209fe6320SNavdeep Parhar 		if (istcp && (tp->t_flags & TF_TOE) != 0)
363ade9ccfeSMarcel Moolenaar 			xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", "toe", vchar);
36409fe6320SNavdeep Parhar 		else
365ade9ccfeSMarcel Moolenaar 			xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", name, vchar);
366fb5d0fbdSRuslan Ermilov 		if (Lflag) {
3677325dfbbSAlfred Perlstein 			char buf1[33];
368fc60ab7bSYoshinobu Inoue 
3697325dfbbSAlfred Perlstein 			snprintf(buf1, sizeof buf1, "%u/%u/%u", so->so_qlen,
370fb5d0fbdSRuslan Ermilov 			    so->so_incqlen, so->so_qlimit);
3717325dfbbSAlfred Perlstein 			xo_emit("{:listen-queue-sizes/%-32.32s} ", buf1);
372f5d34df5SGeorge V. Neville-Neil 		} else if (Tflag) {
373f5d34df5SGeorge V. Neville-Neil 			if (istcp)
374ade9ccfeSMarcel Moolenaar 				xo_emit("{:sent-retransmit-packets/%6u} "
375ade9ccfeSMarcel Moolenaar 				    "{:received-out-of-order-packets/%6u} "
376ade9ccfeSMarcel Moolenaar 				    "{:sent-zero-window/%6u} ",
377ade9ccfeSMarcel Moolenaar 				    tp->t_sndrexmitpack, tp->t_rcvoopack,
378ade9ccfeSMarcel Moolenaar 				    tp->t_sndzerowin);
3790eaa116eSHajimu UMEMOTO 			else
3800eaa116eSHajimu UMEMOTO 				xo_emit("{P:/%21s}", "");
381fb5d0fbdSRuslan Ermilov 		} else {
382ade9ccfeSMarcel Moolenaar 			xo_emit("{:receive-bytes-waiting/%6u} "
383ade9ccfeSMarcel Moolenaar 			    "{:send-bytes-waiting/%6u} ",
3840f9d0a73SGleb Smirnoff 			    so->so_rcv.sb_cc, so->so_snd.sb_cc);
385fc60ab7bSYoshinobu Inoue 		}
38665ea0024SAssar Westerlund 		if (numeric_port) {
387cfa1ca9dSYoshinobu Inoue 			if (inp->inp_vflag & INP_IPV4) {
388ade9ccfeSMarcel Moolenaar 				inetprint("local", &inp->inp_laddr,
389046aad39SHajimu UMEMOTO 				    (int)inp->inp_lport, name, 1, af1);
390ac55add0SGuido van Rooij 				if (!Lflag)
391ade9ccfeSMarcel Moolenaar 					inetprint("remote", &inp->inp_faddr,
392046aad39SHajimu UMEMOTO 					    (int)inp->inp_fport, name, 1, af1);
393cfa1ca9dSYoshinobu Inoue 			}
394cfa1ca9dSYoshinobu Inoue #ifdef INET6
395cfa1ca9dSYoshinobu Inoue 			else if (inp->inp_vflag & INP_IPV6) {
396ade9ccfeSMarcel Moolenaar 				inet6print("local", &inp->in6p_laddr,
397cfa1ca9dSYoshinobu Inoue 				    (int)inp->inp_lport, name, 1);
398ac55add0SGuido van Rooij 				if (!Lflag)
399ade9ccfeSMarcel Moolenaar 					inet6print("remote", &inp->in6p_faddr,
400cfa1ca9dSYoshinobu Inoue 					    (int)inp->inp_fport, name, 1);
401cfa1ca9dSYoshinobu Inoue 			} /* else nothing printed now */
402cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
4034f81ef50SGarrett Wollman 		} else if (inp->inp_flags & INP_ANONPORT) {
404cfa1ca9dSYoshinobu Inoue 			if (inp->inp_vflag & INP_IPV4) {
405ade9ccfeSMarcel Moolenaar 				inetprint("local", &inp->inp_laddr,
406046aad39SHajimu UMEMOTO 				    (int)inp->inp_lport, name, 1, af1);
407ac55add0SGuido van Rooij 				if (!Lflag)
408ade9ccfeSMarcel Moolenaar 					inetprint("remote", &inp->inp_faddr,
409046aad39SHajimu UMEMOTO 					    (int)inp->inp_fport, name, 0, af1);
410cfa1ca9dSYoshinobu Inoue 			}
411cfa1ca9dSYoshinobu Inoue #ifdef INET6
412cfa1ca9dSYoshinobu Inoue 			else if (inp->inp_vflag & INP_IPV6) {
413ade9ccfeSMarcel Moolenaar 				inet6print("local", &inp->in6p_laddr,
414cfa1ca9dSYoshinobu Inoue 				    (int)inp->inp_lport, name, 1);
415ac55add0SGuido van Rooij 				if (!Lflag)
416ade9ccfeSMarcel Moolenaar 					inet6print("remote", &inp->in6p_faddr,
417cfa1ca9dSYoshinobu Inoue 					    (int)inp->inp_fport, name, 0);
418cfa1ca9dSYoshinobu Inoue 			} /* else nothing printed now */
419cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
4208d612dd2SPoul-Henning Kamp 		} else {
421cfa1ca9dSYoshinobu Inoue 			if (inp->inp_vflag & INP_IPV4) {
422ade9ccfeSMarcel Moolenaar 				inetprint("local", &inp->inp_laddr,
423046aad39SHajimu UMEMOTO 				    (int)inp->inp_lport, name, 0, af1);
424ac55add0SGuido van Rooij 				if (!Lflag)
425ade9ccfeSMarcel Moolenaar 					inetprint("remote", &inp->inp_faddr,
426ac55add0SGuido van Rooij 					    (int)inp->inp_fport, name,
427046aad39SHajimu UMEMOTO 					    inp->inp_lport != inp->inp_fport,
428046aad39SHajimu UMEMOTO 					    af1);
429cfa1ca9dSYoshinobu Inoue 			}
430cfa1ca9dSYoshinobu Inoue #ifdef INET6
431cfa1ca9dSYoshinobu Inoue 			else if (inp->inp_vflag & INP_IPV6) {
432ade9ccfeSMarcel Moolenaar 				inet6print("local", &inp->in6p_laddr,
433cfa1ca9dSYoshinobu Inoue 				    (int)inp->inp_lport, name, 0);
434ac55add0SGuido van Rooij 				if (!Lflag)
435ade9ccfeSMarcel Moolenaar 					inet6print("remote", &inp->in6p_faddr,
436cfa1ca9dSYoshinobu Inoue 					    (int)inp->inp_fport, name,
4373feeb332SDavid E. O'Brien 					    inp->inp_lport != inp->inp_fport);
438cfa1ca9dSYoshinobu Inoue 			} /* else nothing printed now */
439cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
4408d612dd2SPoul-Henning Kamp 		}
44149f287f8SGeorge V. Neville-Neil 		if (xflag) {
442ade9ccfeSMarcel Moolenaar 			xo_emit("{:receive-mbufs/%6u} {:send-mbufs/%6u} "
443ade9ccfeSMarcel Moolenaar 			    "{:receive-clusters/%6u} {:send-clusters/%6u} "
444ade9ccfeSMarcel Moolenaar 			    "{:receive-high-water/%6u} {:send-high-water/%6u} "
445ade9ccfeSMarcel Moolenaar 			    "{:receive-low-water/%6u} {:send-low-water/%6u} "
446ade9ccfeSMarcel Moolenaar 			    "{:receive-mbuf-bytes/%6u} {:send-mbuf-bytes/%6u} "
447ade9ccfeSMarcel Moolenaar 			    "{:receive-mbuf-bytes-max/%6u} "
448ade9ccfeSMarcel Moolenaar 			    "{:send-mbuf-bytes-max/%6u}",
44949f287f8SGeorge V. Neville-Neil 			    so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt,
45049f287f8SGeorge V. Neville-Neil 			    so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt,
45149f287f8SGeorge V. Neville-Neil 			    so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat,
45249f287f8SGeorge V. Neville-Neil 			    so->so_rcv.sb_lowat, so->so_snd.sb_lowat,
45349f287f8SGeorge V. Neville-Neil 			    so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
45449f287f8SGeorge V. Neville-Neil 			    so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
455*cc65eb4eSGleb Smirnoff 			if (istcp)
456ade9ccfeSMarcel Moolenaar 				xo_emit(" {:retransmit-timer/%4d.%02d} "
457ade9ccfeSMarcel Moolenaar 				    "{:persist-timer/%4d.%02d} "
458ade9ccfeSMarcel Moolenaar 				    "{:keepalive-timer/%4d.%02d} "
459ade9ccfeSMarcel Moolenaar 				    "{:msl2-timer/%4d.%02d} "
460ade9ccfeSMarcel Moolenaar 				    "{:delay-ack-timer/%4d.%02d} "
461ade9ccfeSMarcel Moolenaar 				    "{:inactivity-timer/%4d.%02d}",
462*cc65eb4eSGleb Smirnoff 				    tp->tt_rexmt / 1000,
463*cc65eb4eSGleb Smirnoff 				    (tp->tt_rexmt % 1000) / 10,
464*cc65eb4eSGleb Smirnoff 				    tp->tt_persist / 1000,
465*cc65eb4eSGleb Smirnoff 				    (tp->tt_persist % 1000) / 10,
466*cc65eb4eSGleb Smirnoff 				    tp->tt_keep / 1000,
467*cc65eb4eSGleb Smirnoff 				    (tp->tt_keep % 1000) / 10,
468*cc65eb4eSGleb Smirnoff 				    tp->tt_2msl / 1000,
469*cc65eb4eSGleb Smirnoff 				    (tp->tt_2msl % 1000) / 10,
470*cc65eb4eSGleb Smirnoff 				    tp->tt_delack / 1000,
471*cc65eb4eSGleb Smirnoff 				    (tp->tt_delack % 1000) / 10,
472*cc65eb4eSGleb Smirnoff 				    tp->t_rcvtime / 1000,
473*cc65eb4eSGleb Smirnoff 				    (tp->t_rcvtime % 1000) / 10);
474b8614722SMike Silbersack 		}
47585b0f0f3SAdrian Chadd 		if (istcp && !Lflag && !xflag && !Tflag && !Rflag) {
4764f81ef50SGarrett Wollman 			if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES)
477ade9ccfeSMarcel Moolenaar 				xo_emit("{:tcp-state/%d}", tp->t_state);
4789a94a597SGarrett Wollman 			else {
479ade9ccfeSMarcel Moolenaar 				xo_emit("{:tcp-state/%s}",
480ade9ccfeSMarcel Moolenaar 				    tcpstates[tp->t_state]);
481513822ddSAdam David #if defined(TF_NEEDSYN) && defined(TF_NEEDFIN)
4829a94a597SGarrett Wollman 				/* Show T/TCP `hidden state' */
4834f81ef50SGarrett Wollman 				if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN))
484ade9ccfeSMarcel Moolenaar 					xo_emit("{:need-syn-or-fin/*}");
485513822ddSAdam David #endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */
4869a94a597SGarrett Wollman 			}
4879b50d902SRodney W. Grimes 		}
48885b0f0f3SAdrian Chadd 		if (Rflag) {
489ade9ccfeSMarcel Moolenaar 			/* XXX: is this right Alfred */
490ade9ccfeSMarcel Moolenaar 			xo_emit(" {:flow-id/%08x} {:flow-type/%5d}",
49185b0f0f3SAdrian Chadd 			    inp->inp_flowid,
49285b0f0f3SAdrian Chadd 			    inp->inp_flowtype);
49385b0f0f3SAdrian Chadd 		}
494ade9ccfeSMarcel Moolenaar 		xo_emit("\n");
495ade9ccfeSMarcel Moolenaar 		xo_close_instance("socket");
4969b50d902SRodney W. Grimes 	}
4974f81ef50SGarrett Wollman 	if (xig != oxig && xig->xig_gen != oxig->xig_gen) {
4984f81ef50SGarrett Wollman 		if (oxig->xig_count > xig->xig_count) {
499ade9ccfeSMarcel Moolenaar 			xo_emit("Some {d:lost/%s} sockets may have been "
500ade9ccfeSMarcel Moolenaar 			    "deleted.\n", name);
5014f81ef50SGarrett Wollman 		} else if (oxig->xig_count < xig->xig_count) {
502ade9ccfeSMarcel Moolenaar 			xo_emit("Some {d:created/%s} sockets may have been "
503ade9ccfeSMarcel Moolenaar 			    "created.\n", name);
5044f81ef50SGarrett Wollman 		} else {
505ade9ccfeSMarcel Moolenaar 			xo_emit("Some {d:changed/%s} sockets may have been "
506ade9ccfeSMarcel Moolenaar 			    "created or deleted.\n", name);
5074f81ef50SGarrett Wollman 		}
5084f81ef50SGarrett Wollman 	}
5094f81ef50SGarrett Wollman 	free(buf);
5109b50d902SRodney W. Grimes }
5119b50d902SRodney W. Grimes 
5129b50d902SRodney W. Grimes /*
5139b50d902SRodney W. Grimes  * Dump TCP statistics structure.
5149b50d902SRodney W. Grimes  */
5159b50d902SRodney W. Grimes void
516feda1a43SJohn Baldwin tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
5179b50d902SRodney W. Grimes {
5189eddb899SMark Johnston 	struct tcpstat tcpstat;
519dbfd8708SGleb Smirnoff 	uint64_t tcps_states[TCP_NSTATES];
5209b50d902SRodney W. Grimes 
521cfa1ca9dSYoshinobu Inoue #ifdef INET6
522cfa1ca9dSYoshinobu Inoue 	if (tcp_done != 0)
523cfa1ca9dSYoshinobu Inoue 		return;
524cfa1ca9dSYoshinobu Inoue 	else
525cfa1ca9dSYoshinobu Inoue 		tcp_done = 1;
526cfa1ca9dSYoshinobu Inoue #endif
527cfa1ca9dSYoshinobu Inoue 
5289eddb899SMark Johnston 	if (fetch_stats("net.inet.tcp.stats", off, &tcpstat,
5299eddb899SMark Johnston 	    sizeof(tcpstat), kread_counters) != 0)
530feda1a43SJohn Baldwin 		return;
531feda1a43SJohn Baldwin 
532dbfd8708SGleb Smirnoff 	if (fetch_stats_ro("net.inet.tcp.states", nl[N_TCPS_STATES].n_value,
533dbfd8708SGleb Smirnoff 	    &tcps_states, sizeof(tcps_states), kread_counters) != 0)
534dbfd8708SGleb Smirnoff 		return;
535dbfd8708SGleb Smirnoff 
536ade9ccfeSMarcel Moolenaar 	xo_open_container("tcp");
537ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
5389b50d902SRodney W. Grimes 
5399b50d902SRodney W. Grimes #define	p(f, m) if (tcpstat.f || sflag <= 1)				\
540ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t )tcpstat.f, plural(tcpstat.f))
54122694ebaSBruce Evans #define	p1a(f, m) if (tcpstat.f || sflag <= 1)				\
542ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t )tcpstat.f)
5439b50d902SRodney W. Grimes #define	p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1)	\
544ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1),		\
5455923c293SGleb Smirnoff 	    (uintmax_t )tcpstat.f2, plural(tcpstat.f2))
54622694ebaSBruce Evans #define	p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1)	\
547ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1),		\
5485923c293SGleb Smirnoff 	    (uintmax_t )tcpstat.f2)
5499b50d902SRodney W. Grimes #define	p3(f, m) if (tcpstat.f || sflag <= 1)				\
550ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t )tcpstat.f, pluralies(tcpstat.f))
5519b50d902SRodney W. Grimes 
552ade9ccfeSMarcel Moolenaar 	p(tcps_sndtotal, "\t{:sent-packets/%ju} {N:/packet%s sent}\n");
553ade9ccfeSMarcel Moolenaar 	p2(tcps_sndpack,tcps_sndbyte, "\t\t{:sent-data-packets/%ju} "
554ade9ccfeSMarcel Moolenaar 	    "{N:/data packet%s} ({:sent-data-bytes/%ju} {N:/byte%s})\n");
555ade9ccfeSMarcel Moolenaar 	p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t"
556ade9ccfeSMarcel Moolenaar 	    "{:sent-retransmitted-packets/%ju} {N:/data packet%s} "
557ade9ccfeSMarcel Moolenaar 	    "({:sent-retransmitted-bytes/%ju} {N:/byte%s}) "
558ade9ccfeSMarcel Moolenaar 	    "{N:retransmitted}\n");
559ade9ccfeSMarcel Moolenaar 	p(tcps_sndrexmitbad, "\t\t"
560ade9ccfeSMarcel Moolenaar 	    "{:sent-unnecessary-retransmitted-packets/%ju} "
561ade9ccfeSMarcel Moolenaar 	    "{N:/data packet%s unnecessarily retransmitted}\n");
562ade9ccfeSMarcel Moolenaar 	p(tcps_mturesent, "\t\t{:sent-resends-by-mtu-discovery/%ju} "
563ade9ccfeSMarcel Moolenaar 	    "{N:/resend%s initiated by MTU discovery}\n");
564ade9ccfeSMarcel Moolenaar 	p2a(tcps_sndacks, tcps_delack, "\t\t{:sent-ack-only-packets/%ju} "
565ade9ccfeSMarcel Moolenaar 	    "{N:/ack-only packet%s/} ({:sent-packets-delayed/%ju} "
566ade9ccfeSMarcel Moolenaar 	    "{N:delayed})\n");
567ade9ccfeSMarcel Moolenaar 	p(tcps_sndurg, "\t\t{:sent-urg-only-packets/%ju} "
568ade9ccfeSMarcel Moolenaar 	    "{N:/URG only packet%s}\n");
569ade9ccfeSMarcel Moolenaar 	p(tcps_sndprobe, "\t\t{:sent-window-probe-packets/%ju} "
570ade9ccfeSMarcel Moolenaar 	    "{N:/window probe packet%s}\n");
571ade9ccfeSMarcel Moolenaar 	p(tcps_sndwinup, "\t\t{:sent-window-update-packets/%ju} "
572ade9ccfeSMarcel Moolenaar 	    "{N:/window update packet%s}\n");
573ade9ccfeSMarcel Moolenaar 	p(tcps_sndctrl, "\t\t{:sent-control-packets/%ju} "
574ade9ccfeSMarcel Moolenaar 	    "{N:/control packet%s}\n");
575ade9ccfeSMarcel Moolenaar 	p(tcps_rcvtotal, "\t{:received-packets/%ju} "
576ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s received}\n");
577ade9ccfeSMarcel Moolenaar 	p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t"
578ade9ccfeSMarcel Moolenaar 	    "{:received-ack-packets/%ju} {N:/ack%s} "
579ade9ccfeSMarcel Moolenaar 	    "{N:(for} {:received-ack-bytes/%ju} {N:/byte%s})\n");
580ade9ccfeSMarcel Moolenaar 	p(tcps_rcvdupack, "\t\t{:received-duplicate-acks/%ju} "
581ade9ccfeSMarcel Moolenaar 	    "{N:/duplicate ack%s}\n");
582ade9ccfeSMarcel Moolenaar 	p(tcps_rcvacktoomuch, "\t\t{:received-acks-for-unsent-data/%ju} "
583ade9ccfeSMarcel Moolenaar 	    "{N:/ack%s for unsent data}\n");
584ade9ccfeSMarcel Moolenaar 	p2(tcps_rcvpack, tcps_rcvbyte, "\t\t"
585ade9ccfeSMarcel Moolenaar 	    "{:received-in-sequence-packets/%ju} {N:/packet%s} "
586ade9ccfeSMarcel Moolenaar 	    "({:received-in-sequence-bytes/%ju} {N:/byte%s}) "
587ade9ccfeSMarcel Moolenaar 	    "{N:received in-sequence}\n");
588ade9ccfeSMarcel Moolenaar 	p2(tcps_rcvduppack, tcps_rcvdupbyte, "\t\t"
589ade9ccfeSMarcel Moolenaar 	    "{:received-completely-duplicate-packets/%ju} "
590ade9ccfeSMarcel Moolenaar 	    "{N:/completely duplicate packet%s} "
591ade9ccfeSMarcel Moolenaar 	    "({:received-completely-duplicate-bytes/%ju} {N:/byte%s})\n");
592ade9ccfeSMarcel Moolenaar 	p(tcps_pawsdrop, "\t\t{:received-old-duplicate-packets/%ju} "
593ade9ccfeSMarcel Moolenaar 	    "{N:/old duplicate packet%s}\n");
594ade9ccfeSMarcel Moolenaar 	p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, "\t\t"
595ade9ccfeSMarcel Moolenaar 	    "{:received-some-duplicate-packets/%ju} "
596ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s with some dup. data} "
597ade9ccfeSMarcel Moolenaar 	    "({:received-some-duplicate-bytes/%ju} {N:/byte%s duped/})\n");
598ade9ccfeSMarcel Moolenaar 	p2(tcps_rcvoopack, tcps_rcvoobyte, "\t\t{:received-out-of-order/%ju} "
599ade9ccfeSMarcel Moolenaar 	    "{N:/out-of-order packet%s} "
600ade9ccfeSMarcel Moolenaar 	    "({:received-out-of-order-bytes/%ju} {N:/byte%s})\n");
601ade9ccfeSMarcel Moolenaar 	p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, "\t\t"
602ade9ccfeSMarcel Moolenaar 	    "{:received-after-window-packets/%ju} {N:/packet%s} "
603ade9ccfeSMarcel Moolenaar 	    "({:received-after-window-bytes/%ju} {N:/byte%s}) "
604ade9ccfeSMarcel Moolenaar 	    "{N:of data after window}\n");
605ade9ccfeSMarcel Moolenaar 	p(tcps_rcvwinprobe, "\t\t{:received-window-probes/%ju} "
606ade9ccfeSMarcel Moolenaar 	    "{N:/window probe%s}\n");
607ade9ccfeSMarcel Moolenaar 	p(tcps_rcvwinupd, "\t\t{:receive-window-update-packets/%ju} "
608ade9ccfeSMarcel Moolenaar 	    "{N:/window update packet%s}\n");
609ade9ccfeSMarcel Moolenaar 	p(tcps_rcvafterclose, "\t\t{:received-after-close-packets/%ju} "
610ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s received after close}\n");
611ade9ccfeSMarcel Moolenaar 	p(tcps_rcvbadsum, "\t\t{:discard-bad-checksum/%ju} "
612ade9ccfeSMarcel Moolenaar 	    "{N:/discarded for bad checksum%s}\n");
613ade9ccfeSMarcel Moolenaar 	p(tcps_rcvbadoff, "\t\t{:discard-bad-header-offset/%ju} "
614ade9ccfeSMarcel Moolenaar 	    "{N:/discarded for bad header offset field%s}\n");
615ade9ccfeSMarcel Moolenaar 	p1a(tcps_rcvshort, "\t\t{:discard-too-short/%ju} "
616ade9ccfeSMarcel Moolenaar 	    "{N:discarded because packet too short}\n");
617ade9ccfeSMarcel Moolenaar 	p1a(tcps_rcvmemdrop, "\t\t{:discard-memory-problems/%ju} "
618ade9ccfeSMarcel Moolenaar 	    "{N:discarded due to memory problems}\n");
619ade9ccfeSMarcel Moolenaar 	p(tcps_connattempt, "\t{:connection-requests/%ju} "
620ade9ccfeSMarcel Moolenaar 	    "{N:/connection request%s}\n");
621ade9ccfeSMarcel Moolenaar 	p(tcps_accepts, "\t{:connections-accepts/%ju} "
622ade9ccfeSMarcel Moolenaar 	    "{N:/connection accept%s}\n");
623ade9ccfeSMarcel Moolenaar 	p(tcps_badsyn, "\t{:bad-connection-attempts/%ju} "
624ade9ccfeSMarcel Moolenaar 	    "{N:/bad connection attempt%s}\n");
625ade9ccfeSMarcel Moolenaar 	p(tcps_listendrop, "\t{:listen-queue-overflows/%ju} "
626ade9ccfeSMarcel Moolenaar 	    "{N:/listen queue overflow%s}\n");
627ade9ccfeSMarcel Moolenaar 	p(tcps_badrst, "\t{:ignored-in-window-resets/%ju} "
628ade9ccfeSMarcel Moolenaar 	    "{N:/ignored RSTs in the window%s}\n");
629ade9ccfeSMarcel Moolenaar 	p(tcps_connects, "\t{:connections-established/%ju} "
630ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s established (including accepts)}\n");
631e9d2c201SMarcelo Araujo 	p(tcps_usedrtt, "\t\t{:connections-hostcache-rtt/%ju} "
632e9d2c201SMarcelo Araujo 	    "{N:/time%s used RTT from hostcache}\n");
633e9d2c201SMarcelo Araujo 	p(tcps_usedrttvar, "\t\t{:connections-hostcache-rttvar/%ju} "
634e9d2c201SMarcelo Araujo 	    "{N:/time%s used RTT variance from hostcache}\n");
635e9d2c201SMarcelo Araujo 	p(tcps_usedssthresh, "\t\t{:connections-hostcache-ssthresh/%ju} "
636e9d2c201SMarcelo Araujo 	    "{N:/time%s used slow-start threshold from hostcache}\n");
637ade9ccfeSMarcel Moolenaar 	p2(tcps_closed, tcps_drops, "\t{:connections-closed/%ju} "
638ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s closed (including} "
639ade9ccfeSMarcel Moolenaar 	    "{:connection-drops/%ju} {N:/drop%s})\n");
640ade9ccfeSMarcel Moolenaar 	p(tcps_cachedrtt, "\t\t{:connections-updated-rtt-on-close/%ju} "
641ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s updated cached RTT on close}\n");
642ade9ccfeSMarcel Moolenaar 	p(tcps_cachedrttvar, "\t\t"
643ade9ccfeSMarcel Moolenaar 	    "{:connections-updated-variance-on-close/%ju} "
644ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s updated cached RTT variance on close}\n");
645ade9ccfeSMarcel Moolenaar 	p(tcps_cachedssthresh, "\t\t"
646ade9ccfeSMarcel Moolenaar 	    "{:connections-updated-ssthresh-on-close/%ju} "
647ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s updated cached ssthresh on close}\n");
648ade9ccfeSMarcel Moolenaar 	p(tcps_conndrops, "\t{:embryonic-connections-dropped/%ju} "
649ade9ccfeSMarcel Moolenaar 	    "{N:/embryonic connection%s dropped}\n");
650ade9ccfeSMarcel Moolenaar 	p2(tcps_rttupdated, tcps_segstimed, "\t{:segments-updated-rtt/%ju} "
651ade9ccfeSMarcel Moolenaar 	    "{N:/segment%s updated rtt (of} "
652ade9ccfeSMarcel Moolenaar 	    "{:segment-update-attempts/%ju} {N:/attempt%s})\n");
653ade9ccfeSMarcel Moolenaar 	p(tcps_rexmttimeo, "\t{:retransmit-timeouts/%ju} "
654ade9ccfeSMarcel Moolenaar 	    "{N:/retransmit timeout%s}\n");
655ade9ccfeSMarcel Moolenaar 	p(tcps_timeoutdrop, "\t\t"
656ade9ccfeSMarcel Moolenaar 	    "{:connections-dropped-by-retransmit-timeout/%ju} "
657ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s dropped by rexmit timeout}\n");
658ade9ccfeSMarcel Moolenaar 	p(tcps_persisttimeo, "\t{:persist-timeout/%ju} "
659ade9ccfeSMarcel Moolenaar 	    "{N:/persist timeout%s}\n");
660ade9ccfeSMarcel Moolenaar 	p(tcps_persistdrop, "\t\t"
661ade9ccfeSMarcel Moolenaar 	    "{:connections-dropped-by-persist-timeout/%ju} "
662ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s dropped by persist timeout}\n");
663ade9ccfeSMarcel Moolenaar 	p(tcps_finwait2_drops, "\t"
664ade9ccfeSMarcel Moolenaar 	    "{:connections-dropped-by-finwait2-timeout/%ju} "
665ade9ccfeSMarcel Moolenaar 	    "{N:/Connection%s (fin_wait_2) dropped because of timeout}\n");
666ade9ccfeSMarcel Moolenaar 	p(tcps_keeptimeo, "\t{:keepalive-timeout/%ju} "
667ade9ccfeSMarcel Moolenaar 	    "{N:/keepalive timeout%s}\n");
668ade9ccfeSMarcel Moolenaar 	p(tcps_keepprobe, "\t\t{:keepalive-probes/%ju} "
669ade9ccfeSMarcel Moolenaar 	    "{N:/keepalive probe%s sent}\n");
670ade9ccfeSMarcel Moolenaar 	p(tcps_keepdrops, "\t\t{:connections-dropped-by-keepalives/%ju} "
671ade9ccfeSMarcel Moolenaar 	    "{N:/connection%s dropped by keepalive}\n");
672ade9ccfeSMarcel Moolenaar 	p(tcps_predack, "\t{:ack-header-predictions/%ju} "
673ade9ccfeSMarcel Moolenaar 	    "{N:/correct ACK header prediction%s}\n");
674ade9ccfeSMarcel Moolenaar 	p(tcps_preddat, "\t{:data-packet-header-predictions/%ju} "
675ade9ccfeSMarcel Moolenaar 	    "{N:/correct data packet header prediction%s}\n");
67660a31b3aSJonathan Lemon 
677ade9ccfeSMarcel Moolenaar 	xo_open_container("syncache");
678b6101dafSPaul Saab 
679ade9ccfeSMarcel Moolenaar 	p3(tcps_sc_added, "\t{:entries-added/%ju} "
680ade9ccfeSMarcel Moolenaar 	    "{N:/syncache entr%s added}\n");
681ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_retransmitted, "\t\t{:retransmitted/%ju} "
682ade9ccfeSMarcel Moolenaar 	    "{N:/retransmitted}\n");
683ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_dupsyn, "\t\t{:duplicates/%ju} {N:/dupsyn}\n");
684ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_dropped, "\t\t{:dropped/%ju} {N:/dropped}\n");
685ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_completed, "\t\t{:completed/%ju} {N:/completed}\n");
686ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_bucketoverflow, "\t\t{:bucket-overflow/%ju} "
687ade9ccfeSMarcel Moolenaar 	    "{N:/bucket overflow}\n");
688ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_cacheoverflow, "\t\t{:cache-overflow/%ju} "
689ade9ccfeSMarcel Moolenaar 	    "{N:/cache overflow}\n");
690ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_reset, "\t\t{:reset/%ju} {N:/reset}\n");
691ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_stale, "\t\t{:stale/%ju} {N:/stale}\n");
692ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_aborted, "\t\t{:aborted/%ju} {N:/aborted}\n");
693ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_badack, "\t\t{:bad-ack/%ju} {N:/badack}\n");
694ade9ccfeSMarcel Moolenaar 	p1a(tcps_sc_unreach, "\t\t{:unreachable/%ju} {N:/unreach}\n");
695ade9ccfeSMarcel Moolenaar 	p(tcps_sc_zonefail, "\t\t{:zone-failures/%ju} {N:/zone failure%s}\n");
696ade9ccfeSMarcel Moolenaar 	p(tcps_sc_sendcookie, "\t{:sent-cookies/%ju} {N:/cookie%s sent}\n");
697ade9ccfeSMarcel Moolenaar 	p(tcps_sc_recvcookie, "\t{:receivd-cookies/%ju} "
698ade9ccfeSMarcel Moolenaar 	    "{N:/cookie%s received}\n");
699699ef999SRuslan Ermilov 
700ade9ccfeSMarcel Moolenaar 	xo_close_container("syncache");
701b6101dafSPaul Saab 
702ade9ccfeSMarcel Moolenaar 	xo_open_container("hostcache");
703a4993b25SBjoern A. Zeeb 
704ade9ccfeSMarcel Moolenaar 	p3(tcps_hc_added, "\t{:entries-added/%ju} "
705ade9ccfeSMarcel Moolenaar 	    "{N:/hostcache entr%s added}\n");
706ade9ccfeSMarcel Moolenaar 	p1a(tcps_hc_bucketoverflow, "\t\t{:buffer-overflows/%ju} "
707ade9ccfeSMarcel Moolenaar 	    "{N:/bucket overflow}\n");
708ade9ccfeSMarcel Moolenaar 
709ade9ccfeSMarcel Moolenaar 	xo_close_container("hostcache");
710ade9ccfeSMarcel Moolenaar 
711ade9ccfeSMarcel Moolenaar 	xo_open_container("sack");
712ade9ccfeSMarcel Moolenaar 
713ade9ccfeSMarcel Moolenaar 	p(tcps_sack_recovery_episode, "\t{:recovery-episodes/%ju} "
714ade9ccfeSMarcel Moolenaar 	    "{N:/SACK recovery episode%s}\n");
715ade9ccfeSMarcel Moolenaar  	p(tcps_sack_rexmits, "\t{:segment-retransmits/%ju} "
716ade9ccfeSMarcel Moolenaar 	    "{N:/segment rexmit%s in SACK recovery episodes}\n");
717ade9ccfeSMarcel Moolenaar  	p(tcps_sack_rexmit_bytes, "\t{:byte-retransmits/%ju} "
718ade9ccfeSMarcel Moolenaar 	    "{N:/byte rexmit%s in SACK recovery episodes}\n");
719ade9ccfeSMarcel Moolenaar  	p(tcps_sack_rcv_blocks, "\t{:received-blocks/%ju} "
720ade9ccfeSMarcel Moolenaar 	    "{N:/SACK option%s (SACK blocks) received}\n");
721ade9ccfeSMarcel Moolenaar 	p(tcps_sack_send_blocks, "\t{:sent-option-blocks/%ju} "
722ade9ccfeSMarcel Moolenaar 	    "{N:/SACK option%s (SACK blocks) sent}\n");
723ade9ccfeSMarcel Moolenaar 	p1a(tcps_sack_sboverflow, "\t{:scoreboard-overflows/%ju} "
724ade9ccfeSMarcel Moolenaar 	    "{N:/SACK scoreboard overflow}\n");
725ade9ccfeSMarcel Moolenaar 
726ade9ccfeSMarcel Moolenaar 	xo_close_container("sack");
727ade9ccfeSMarcel Moolenaar 	xo_open_container("ecn");
728ade9ccfeSMarcel Moolenaar 
729ade9ccfeSMarcel Moolenaar 	p(tcps_ecn_ce, "\t{:ce-packets/%ju} "
730ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s with ECN CE bit set}\n");
731ade9ccfeSMarcel Moolenaar 	p(tcps_ecn_ect0, "\t{:ect0-packets/%ju} "
732ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s with ECN ECT(0) bit set}\n");
733ade9ccfeSMarcel Moolenaar 	p(tcps_ecn_ect1, "\t{:ect1-packets/%ju} "
734ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s with ECN ECT(1) bit set}\n");
735ade9ccfeSMarcel Moolenaar 	p(tcps_ecn_shs, "\t{:handshakes/%ju} "
736ade9ccfeSMarcel Moolenaar 	    "{N:/successful ECN handshake%s}\n");
737ade9ccfeSMarcel Moolenaar 	p(tcps_ecn_rcwnd, "\t{:congestion-reductions/%ju} "
738ade9ccfeSMarcel Moolenaar 	    "{N:/time%s ECN reduced the congestion window}\n");
739fcf59617SAndrey V. Elsukov 
740fcf59617SAndrey V. Elsukov 	xo_close_container("ecn");
741fcf59617SAndrey V. Elsukov 	xo_open_container("tcp-signature");
742fcf59617SAndrey V. Elsukov 	p(tcps_sig_rcvgoodsig, "\t{:received-good-signature/%ju} "
743fcf59617SAndrey V. Elsukov 	    "{N:/packet%s with matching signature received}\n");
744fcf59617SAndrey V. Elsukov 	p(tcps_sig_rcvbadsig, "\t{:received-bad-signature/%ju} "
745fcf59617SAndrey V. Elsukov 	    "{N:/packet%s with bad signature received}\n");
746fcf59617SAndrey V. Elsukov 	p(tcps_sig_err_buildsig, "\t{:failed-make-signature/%ju} "
747fcf59617SAndrey V. Elsukov 	    "{N:/time%s failed to make signature due to no SA}\n");
748fcf59617SAndrey V. Elsukov 	p(tcps_sig_err_sigopt, "\t{:no-signature-expected/%ju} "
749fcf59617SAndrey V. Elsukov 	    "{N:/time%s unexpected signature received}\n");
750fcf59617SAndrey V. Elsukov 	p(tcps_sig_err_nosigopt, "\t{:no-signature-provided/%ju} "
751fcf59617SAndrey V. Elsukov 	    "{N:/time%s no signature provided by segment}\n");
7529b50d902SRodney W. Grimes  #undef p
75322694ebaSBruce Evans  #undef p1a
7549b50d902SRodney W. Grimes  #undef p2
75522694ebaSBruce Evans  #undef p2a
7569b50d902SRodney W. Grimes  #undef p3
757fcf59617SAndrey V. Elsukov 	xo_close_container("tcp-signature");
758dbfd8708SGleb Smirnoff 
759dbfd8708SGleb Smirnoff 	xo_open_container("TCP connection count by state");
760dbfd8708SGleb Smirnoff 	xo_emit("{T:/TCP connection count by state}:\n");
761dbfd8708SGleb Smirnoff 	for (int i = 0; i < TCP_NSTATES; i++) {
762dbfd8708SGleb Smirnoff 		/*
763dbfd8708SGleb Smirnoff 		 * XXXGL: is there a way in libxo to use %s
764dbfd8708SGleb Smirnoff 		 * in the "content string" of a format
765dbfd8708SGleb Smirnoff 		 * string? I failed to do that, that's why
766dbfd8708SGleb Smirnoff 		 * a temporary buffer is used to construct
767dbfd8708SGleb Smirnoff 		 * format string for xo_emit().
768dbfd8708SGleb Smirnoff 		 */
769dbfd8708SGleb Smirnoff 		char fmtbuf[80];
770dbfd8708SGleb Smirnoff 
771dbfd8708SGleb Smirnoff 		if (sflag > 1 && tcps_states[i] == 0)
772dbfd8708SGleb Smirnoff 			continue;
773dbfd8708SGleb Smirnoff 		snprintf(fmtbuf, sizeof(fmtbuf), "\t{:%s/%%ju} "
774dbfd8708SGleb Smirnoff                     "{Np:/connection ,connections} in %s state\n",
775dbfd8708SGleb Smirnoff 		    tcpstates[i], tcpstates[i]);
776dbfd8708SGleb Smirnoff 		xo_emit(fmtbuf, (uintmax_t )tcps_states[i]);
777dbfd8708SGleb Smirnoff 	}
778dbfd8708SGleb Smirnoff 	xo_close_container("TCP connection count by state");
779dbfd8708SGleb Smirnoff 
780ade9ccfeSMarcel Moolenaar 	xo_close_container("tcp");
7819b50d902SRodney W. Grimes }
7829b50d902SRodney W. Grimes 
7839b50d902SRodney W. Grimes /*
7849b50d902SRodney W. Grimes  * Dump UDP statistics structure.
7859b50d902SRodney W. Grimes  */
7869b50d902SRodney W. Grimes void
787feda1a43SJohn Baldwin udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
7889b50d902SRodney W. Grimes {
7899eddb899SMark Johnston 	struct udpstat udpstat;
790c80211e3SAndrey V. Elsukov 	uint64_t delivered;
7919b50d902SRodney W. Grimes 
792cfa1ca9dSYoshinobu Inoue #ifdef INET6
793cfa1ca9dSYoshinobu Inoue 	if (udp_done != 0)
794cfa1ca9dSYoshinobu Inoue 		return;
795cfa1ca9dSYoshinobu Inoue 	else
796cfa1ca9dSYoshinobu Inoue 		udp_done = 1;
797cfa1ca9dSYoshinobu Inoue #endif
798cfa1ca9dSYoshinobu Inoue 
7999eddb899SMark Johnston 	if (fetch_stats("net.inet.udp.stats", off, &udpstat,
8009eddb899SMark Johnston 	    sizeof(udpstat), kread_counters) != 0)
801feda1a43SJohn Baldwin 		return;
802feda1a43SJohn Baldwin 
803ade9ccfeSMarcel Moolenaar 	xo_open_container("udp");
804ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
805ade9ccfeSMarcel Moolenaar 
8069b50d902SRodney W. Grimes #define	p(f, m) if (udpstat.f || sflag <= 1) \
807ade9ccfeSMarcel Moolenaar 	xo_emit("\t" m, (uintmax_t)udpstat.f, plural(udpstat.f))
80822694ebaSBruce Evans #define	p1a(f, m) if (udpstat.f || sflag <= 1) \
809ade9ccfeSMarcel Moolenaar 	xo_emit("\t" m, (uintmax_t)udpstat.f)
810ade9ccfeSMarcel Moolenaar 
811ade9ccfeSMarcel Moolenaar 	p(udps_ipackets, "{:received-datagrams/%ju} "
812ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s received}\n");
813ade9ccfeSMarcel Moolenaar 	p1a(udps_hdrops, "{:dropped-incomplete-headers/%ju} "
814ade9ccfeSMarcel Moolenaar 	    "{N:/with incomplete header}\n");
815ade9ccfeSMarcel Moolenaar 	p1a(udps_badlen, "{:dropped-bad-data-length/%ju} "
816ade9ccfeSMarcel Moolenaar 	    "{N:/with bad data length field}\n");
817ade9ccfeSMarcel Moolenaar 	p1a(udps_badsum, "{:dropped-bad-checksum/%ju} "
818ade9ccfeSMarcel Moolenaar 	    "{N:/with bad checksum}\n");
819ade9ccfeSMarcel Moolenaar 	p1a(udps_nosum, "{:dropped-no-checksum/%ju} "
820ade9ccfeSMarcel Moolenaar 	    "{N:/with no checksum}\n");
821ade9ccfeSMarcel Moolenaar 	p1a(udps_noport, "{:dropped-no-socket/%ju} "
822ade9ccfeSMarcel Moolenaar 	    "{N:/dropped due to no socket}\n");
823ade9ccfeSMarcel Moolenaar 	p(udps_noportbcast, "{:dropped-broadcast-multicast/%ju} "
824ade9ccfeSMarcel Moolenaar 	    "{N:/broadcast\\/multicast datagram%s undelivered}\n");
825ade9ccfeSMarcel Moolenaar 	p1a(udps_fullsock, "{:dropped-full-socket-buffer/%ju} "
826ade9ccfeSMarcel Moolenaar 	    "{N:/dropped due to full socket buffers}\n");
827ade9ccfeSMarcel Moolenaar 	p1a(udpps_pcbhashmiss, "{:not-for-hashed-pcb/%ju} "
828ade9ccfeSMarcel Moolenaar 	    "{N:/not for hashed pcb}\n");
8299b50d902SRodney W. Grimes 	delivered = udpstat.udps_ipackets -
8309b50d902SRodney W. Grimes 		    udpstat.udps_hdrops -
8319b50d902SRodney W. Grimes 		    udpstat.udps_badlen -
8329b50d902SRodney W. Grimes 		    udpstat.udps_badsum -
8339b50d902SRodney W. Grimes 		    udpstat.udps_noport -
8349b50d902SRodney W. Grimes 		    udpstat.udps_noportbcast -
8359b50d902SRodney W. Grimes 		    udpstat.udps_fullsock;
8369b50d902SRodney W. Grimes 	if (delivered || sflag <= 1)
837ade9ccfeSMarcel Moolenaar 		xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n",
838ade9ccfeSMarcel Moolenaar 		    (uint64_t)delivered);
839ade9ccfeSMarcel Moolenaar 	p(udps_opackets, "{:output-packets/%ju} {N:/datagram%s output}\n");
84071498f30SBruce M Simpson 	/* the next statistic is cumulative in udps_noportbcast */
841ade9ccfeSMarcel Moolenaar 	p(udps_filtermcast, "{:multicast-source-filter-matches/%ju} "
842ade9ccfeSMarcel Moolenaar 	    "{N:/time%s multicast source filter matched}\n");
8439b50d902SRodney W. Grimes #undef p
84422694ebaSBruce Evans #undef p1a
845ade9ccfeSMarcel Moolenaar 	xo_close_container("udp");
8469b50d902SRodney W. Grimes }
8479b50d902SRodney W. Grimes 
8489b50d902SRodney W. Grimes /*
849a9771948SGleb Smirnoff  * Dump CARP statistics structure.
850a9771948SGleb Smirnoff  */
851a9771948SGleb Smirnoff void
852feda1a43SJohn Baldwin carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
853a9771948SGleb Smirnoff {
8549eddb899SMark Johnston 	struct carpstats carpstat;
855a9771948SGleb Smirnoff 
8569eddb899SMark Johnston 	if (fetch_stats("net.inet.carp.stats", off, &carpstat,
8579eddb899SMark Johnston 	    sizeof(carpstat), kread_counters) != 0)
858a9771948SGleb Smirnoff 		return;
859a9771948SGleb Smirnoff 
860ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
861ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
862a9771948SGleb Smirnoff 
863a9771948SGleb Smirnoff #define	p(f, m) if (carpstat.f || sflag <= 1) \
864ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)carpstat.f, plural(carpstat.f))
865a9771948SGleb Smirnoff #define	p2(f, m) if (carpstat.f || sflag <= 1) \
866ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)carpstat.f)
867a9771948SGleb Smirnoff 
868ade9ccfeSMarcel Moolenaar 	p(carps_ipackets, "\t{:received-inet-packets/%ju} "
869ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s received (IPv4)}\n");
870ade9ccfeSMarcel Moolenaar 	p(carps_ipackets6, "\t{:received-inet6-packets/%ju} "
871ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s received (IPv6)}\n");
872ade9ccfeSMarcel Moolenaar 	p(carps_badttl, "\t\t{:dropped-wrong-ttl/%ju} "
873ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s discarded for wrong TTL}\n");
874ade9ccfeSMarcel Moolenaar 	p(carps_hdrops, "\t\t{:dropped-short-header/%ju} "
875ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s shorter than header}\n");
876ade9ccfeSMarcel Moolenaar 	p(carps_badsum, "\t\t{:dropped-bad-checksum/%ju} "
877ade9ccfeSMarcel Moolenaar 	    "{N:/discarded for bad checksum%s}\n");
878ade9ccfeSMarcel Moolenaar 	p(carps_badver,	"\t\t{:dropped-bad-version/%ju} "
879ade9ccfeSMarcel Moolenaar 	    "{N:/discarded packet%s with a bad version}\n");
880ade9ccfeSMarcel Moolenaar 	p2(carps_badlen, "\t\t{:dropped-short-packet/%ju} "
881ade9ccfeSMarcel Moolenaar 	    "{N:/discarded because packet too short}\n");
882ade9ccfeSMarcel Moolenaar 	p2(carps_badauth, "\t\t{:dropped-bad-authentication/%ju} "
883ade9ccfeSMarcel Moolenaar 	    "{N:/discarded for bad authentication}\n");
884ade9ccfeSMarcel Moolenaar 	p2(carps_badvhid, "\t\t{:dropped-bad-vhid/%ju} "
885ade9ccfeSMarcel Moolenaar 	    "{N:/discarded for bad vhid}\n");
886ade9ccfeSMarcel Moolenaar 	p2(carps_badaddrs, "\t\t{:dropped-bad-address-list/%ju} "
887ade9ccfeSMarcel Moolenaar 	    "{N:/discarded because of a bad address list}\n");
888ade9ccfeSMarcel Moolenaar 	p(carps_opackets, "\t{:sent-inet-packets/%ju} "
889ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent (IPv4)}\n");
890ade9ccfeSMarcel Moolenaar 	p(carps_opackets6, "\t{:sent-inet6-packets/%ju} "
891ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent (IPv6)}\n");
892ade9ccfeSMarcel Moolenaar 	p2(carps_onomem, "\t\t{:send-failed-memory-error/%ju} "
893ade9ccfeSMarcel Moolenaar 	    "{N:/send failed due to mbuf memory error}\n");
894a9771948SGleb Smirnoff #if notyet
895ade9ccfeSMarcel Moolenaar 	p(carps_ostates, "\t\t{:send-state-updates/%s} "
896ade9ccfeSMarcel Moolenaar 	    "{N:/state update%s sent}\n");
897a9771948SGleb Smirnoff #endif
898a9771948SGleb Smirnoff #undef p
899a9771948SGleb Smirnoff #undef p2
900ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
901a9771948SGleb Smirnoff }
902a9771948SGleb Smirnoff 
903a9771948SGleb Smirnoff /*
9049b50d902SRodney W. Grimes  * Dump IP statistics structure.
9059b50d902SRodney W. Grimes  */
9069b50d902SRodney W. Grimes void
907feda1a43SJohn Baldwin ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
9089b50d902SRodney W. Grimes {
9099eddb899SMark Johnston 	struct ipstat ipstat;
9109b50d902SRodney W. Grimes 
9119eddb899SMark Johnston 	if (fetch_stats("net.inet.ip.stats", off, &ipstat,
9129eddb899SMark Johnston 	    sizeof(ipstat), kread_counters) != 0)
9139b50d902SRodney W. Grimes 		return;
9144f81ef50SGarrett Wollman 
915ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
916ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
9179b50d902SRodney W. Grimes 
9189b50d902SRodney W. Grimes #define	p(f, m) if (ipstat.f || sflag <= 1) \
919ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t )ipstat.f, plural(ipstat.f))
92022694ebaSBruce Evans #define	p1a(f, m) if (ipstat.f || sflag <= 1) \
921ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t )ipstat.f)
9229b50d902SRodney W. Grimes 
923ade9ccfeSMarcel Moolenaar 	p(ips_total, "\t{:received-packets/%ju} "
924ade9ccfeSMarcel Moolenaar 	    "{N:/total packet%s received}\n");
925ade9ccfeSMarcel Moolenaar 	p(ips_badsum, "\t{:dropped-bad-checksum/%ju} "
926ade9ccfeSMarcel Moolenaar 	    "{N:/bad header checksum%s}\n");
927ade9ccfeSMarcel Moolenaar 	p1a(ips_toosmall, "\t{:dropped-below-minimum-size/%ju} "
928ade9ccfeSMarcel Moolenaar 	    "{N:/with size smaller than minimum}\n");
929ade9ccfeSMarcel Moolenaar 	p1a(ips_tooshort, "\t{:dropped-short-packets/%ju} "
930ade9ccfeSMarcel Moolenaar 	    "{N:/with data size < data length}\n");
931ade9ccfeSMarcel Moolenaar 	p1a(ips_toolong, "\t{:dropped-too-long/%ju} "
932ade9ccfeSMarcel Moolenaar 	    "{N:/with ip length > max ip packet size}\n");
933ade9ccfeSMarcel Moolenaar 	p1a(ips_badhlen, "\t{:dropped-short-header-length/%ju} "
934ade9ccfeSMarcel Moolenaar 	    "{N:/with header length < data size}\n");
935ade9ccfeSMarcel Moolenaar 	p1a(ips_badlen, "\t{:dropped-short-data/%ju} "
936ade9ccfeSMarcel Moolenaar 	    "{N:/with data length < header length}\n");
937ade9ccfeSMarcel Moolenaar 	p1a(ips_badoptions, "\t{:dropped-bad-options/%ju} "
938ade9ccfeSMarcel Moolenaar 	    "{N:/with bad options}\n");
939ade9ccfeSMarcel Moolenaar 	p1a(ips_badvers, "\t{:dropped-bad-version/%ju} "
940ade9ccfeSMarcel Moolenaar 	    "{N:/with incorrect version number}\n");
941ade9ccfeSMarcel Moolenaar 	p(ips_fragments, "\t{:received-fragments/%ju} "
942ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s received}\n");
943ade9ccfeSMarcel Moolenaar 	p(ips_fragdropped, "\t{:dropped-fragments/%ju} "
944ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped (dup or out of space)}\n");
945ade9ccfeSMarcel Moolenaar 	p(ips_fragtimeout, "\t{:dropped-fragments-after-timeout/%ju} "
946ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped after timeout}\n");
947ade9ccfeSMarcel Moolenaar 	p(ips_reassembled, "\t{:reassembled-packets/%ju} "
948ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s reassembled ok}\n");
949ade9ccfeSMarcel Moolenaar 	p(ips_delivered, "\t{:received-local-packets/%ju} "
950ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s for this host}\n");
951ade9ccfeSMarcel Moolenaar 	p(ips_noproto, "\t{:dropped-unknown-protocol/%ju} "
952ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s for unknown\\/unsupported protocol}\n");
953ade9ccfeSMarcel Moolenaar 	p(ips_forward, "\t{:forwarded-packets/%ju} "
954ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s forwarded}");
955ade9ccfeSMarcel Moolenaar 	p(ips_fastforward, " ({:fast-forwarded-packets/%ju} "
956ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s fast forwarded})");
957958d6f7fSPierre Beyssac 	if (ipstat.ips_forward || sflag <= 1)
958ade9ccfeSMarcel Moolenaar 		xo_emit("\n");
959ade9ccfeSMarcel Moolenaar 	p(ips_cantforward, "\t{:packets-cannot-forward/%ju} "
960ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s not forwardable}\n");
961ade9ccfeSMarcel Moolenaar 	p(ips_notmember, "\t{:received-unknown-multicast-group/%ju} "
962ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s received for unknown multicast group}\n");
963ade9ccfeSMarcel Moolenaar 	p(ips_redirectsent, "\t{:redirects-sent/%ju} "
964ade9ccfeSMarcel Moolenaar 	    "{N:/redirect%s sent}\n");
965ade9ccfeSMarcel Moolenaar 	p(ips_localout, "\t{:sent-packets/%ju} "
966ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent from this host}\n");
967ade9ccfeSMarcel Moolenaar 	p(ips_rawout, "\t{:send-packets-fabricated-header/%ju} "
968ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent with fabricated ip header}\n");
969ade9ccfeSMarcel Moolenaar 	p(ips_odropped, "\t{:discard-no-mbufs/%ju} "
970ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s dropped due to no bufs, etc.}\n");
971ade9ccfeSMarcel Moolenaar 	p(ips_noroute, "\t{:discard-no-route/%ju} "
972ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s discarded due to no route}\n");
973ade9ccfeSMarcel Moolenaar 	p(ips_fragmented, "\t{:sent-fragments/%ju} "
974ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s fragmented}\n");
975ade9ccfeSMarcel Moolenaar 	p(ips_ofragments, "\t{:fragments-created/%ju} "
976ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s created}\n");
977ade9ccfeSMarcel Moolenaar 	p(ips_cantfrag, "\t{:discard-cannot-fragment/%ju} "
978ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s that can't be fragmented}\n");
979ade9ccfeSMarcel Moolenaar 	p(ips_nogif, "\t{:discard-tunnel-no-gif/%ju} "
980ade9ccfeSMarcel Moolenaar 	    "{N:/tunneling packet%s that can't find gif}\n");
981ade9ccfeSMarcel Moolenaar 	p(ips_badaddr, "\t{:discard-bad-address/%ju} "
982ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with bad address in header}\n");
9839b50d902SRodney W. Grimes #undef p
98422694ebaSBruce Evans #undef p1a
985ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
9869b50d902SRodney W. Grimes }
9879b50d902SRodney W. Grimes 
98854fc657dSGeorge V. Neville-Neil /*
98954fc657dSGeorge V. Neville-Neil  * Dump ARP statistics structure.
99054fc657dSGeorge V. Neville-Neil  */
99154fc657dSGeorge V. Neville-Neil void
99254fc657dSGeorge V. Neville-Neil arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
99354fc657dSGeorge V. Neville-Neil {
9949eddb899SMark Johnston 	struct arpstat arpstat;
99554fc657dSGeorge V. Neville-Neil 
9969eddb899SMark Johnston 	if (fetch_stats("net.link.ether.arp.stats", off, &arpstat,
9979eddb899SMark Johnston 	    sizeof(arpstat), kread_counters) != 0)
99854fc657dSGeorge V. Neville-Neil 		return;
99954fc657dSGeorge V. Neville-Neil 
1000ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
1001ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
100254fc657dSGeorge V. Neville-Neil 
100354fc657dSGeorge V. Neville-Neil #define	p(f, m) if (arpstat.f || sflag <= 1) \
1004ade9ccfeSMarcel Moolenaar 	xo_emit("\t" m, (uintmax_t)arpstat.f, plural(arpstat.f))
100554fc657dSGeorge V. Neville-Neil #define	p2(f, m) if (arpstat.f || sflag <= 1) \
1006ade9ccfeSMarcel Moolenaar 	xo_emit("\t" m, (uintmax_t)arpstat.f, pluralies(arpstat.f))
100754fc657dSGeorge V. Neville-Neil 
1008ade9ccfeSMarcel Moolenaar 	p(txrequests, "{:sent-requests/%ju} {N:/ARP request%s sent}\n");
1009ade9ccfeSMarcel Moolenaar 	p2(txreplies, "{:sent-replies/%ju} {N:/ARP repl%s sent}\n");
1010ade9ccfeSMarcel Moolenaar 	p(rxrequests, "{:received-requests/%ju} "
1011ade9ccfeSMarcel Moolenaar 	    "{N:/ARP request%s received}\n");
1012ade9ccfeSMarcel Moolenaar 	p2(rxreplies, "{:received-replies/%ju} "
1013ade9ccfeSMarcel Moolenaar 	    "{N:/ARP repl%s received}\n");
1014ade9ccfeSMarcel Moolenaar 	p(received, "{:received-packers/%ju} "
1015ade9ccfeSMarcel Moolenaar 	    "{N:/ARP packet%s received}\n");
1016ade9ccfeSMarcel Moolenaar 	p(dropped, "{:dropped-no-entry/%ju} "
1017ade9ccfeSMarcel Moolenaar 	    "{N:/total packet%s dropped due to no ARP entry}\n");
1018ade9ccfeSMarcel Moolenaar 	p(timeouts, "{:entries-timeout/%ju} "
1019ade9ccfeSMarcel Moolenaar 	    "{N:/ARP entry%s timed out}\n");
1020ade9ccfeSMarcel Moolenaar 	p(dupips, "{:dropped-duplicate-address/%ju} "
1021ade9ccfeSMarcel Moolenaar 	    "{N:/Duplicate IP%s seen}\n");
102254fc657dSGeorge V. Neville-Neil #undef p
102354fc657dSGeorge V. Neville-Neil #undef p2
1024ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
102554fc657dSGeorge V. Neville-Neil }
102654fc657dSGeorge V. Neville-Neil 
102754fc657dSGeorge V. Neville-Neil 
102854fc657dSGeorge V. Neville-Neil 
10294063583aSMaxim Konovalov static	const char *icmpnames[ICMP_MAXTYPE + 1] = {
10304063583aSMaxim Konovalov 	"echo reply",			/* RFC 792 */
10319b50d902SRodney W. Grimes 	"#1",
10329b50d902SRodney W. Grimes 	"#2",
10334063583aSMaxim Konovalov 	"destination unreachable",	/* RFC 792 */
10344063583aSMaxim Konovalov 	"source quench",		/* RFC 792 */
10354063583aSMaxim Konovalov 	"routing redirect",		/* RFC 792 */
10369b50d902SRodney W. Grimes 	"#6",
10379b50d902SRodney W. Grimes 	"#7",
10384063583aSMaxim Konovalov 	"echo",				/* RFC 792 */
10394063583aSMaxim Konovalov 	"router advertisement",		/* RFC 1256 */
10404063583aSMaxim Konovalov 	"router solicitation",		/* RFC 1256 */
10414063583aSMaxim Konovalov 	"time exceeded",		/* RFC 792 */
10424063583aSMaxim Konovalov 	"parameter problem",		/* RFC 792 */
10434063583aSMaxim Konovalov 	"time stamp",			/* RFC 792 */
10444063583aSMaxim Konovalov 	"time stamp reply",		/* RFC 792 */
10454063583aSMaxim Konovalov 	"information request",		/* RFC 792 */
10464063583aSMaxim Konovalov 	"information request reply",	/* RFC 792 */
10474063583aSMaxim Konovalov 	"address mask request",		/* RFC 950 */
10484063583aSMaxim Konovalov 	"address mask reply",		/* RFC 950 */
10494063583aSMaxim Konovalov 	"#19",
10504063583aSMaxim Konovalov 	"#20",
10514063583aSMaxim Konovalov 	"#21",
10524063583aSMaxim Konovalov 	"#22",
10534063583aSMaxim Konovalov 	"#23",
10544063583aSMaxim Konovalov 	"#24",
10554063583aSMaxim Konovalov 	"#25",
10564063583aSMaxim Konovalov 	"#26",
10574063583aSMaxim Konovalov 	"#27",
10584063583aSMaxim Konovalov 	"#28",
10594063583aSMaxim Konovalov 	"#29",
10604063583aSMaxim Konovalov 	"icmp traceroute",		/* RFC 1393 */
10614063583aSMaxim Konovalov 	"datagram conversion error",	/* RFC 1475 */
10624063583aSMaxim Konovalov 	"mobile host redirect",
10634063583aSMaxim Konovalov 	"IPv6 where-are-you",
10644063583aSMaxim Konovalov 	"IPv6 i-am-here",
10654063583aSMaxim Konovalov 	"mobile registration req",
10664063583aSMaxim Konovalov 	"mobile registration reply",
10674063583aSMaxim Konovalov 	"domain name request",		/* RFC 1788 */
10684063583aSMaxim Konovalov 	"domain name reply",		/* RFC 1788 */
10694063583aSMaxim Konovalov 	"icmp SKIP",
10704063583aSMaxim Konovalov 	"icmp photuris",		/* RFC 2521 */
10719b50d902SRodney W. Grimes };
10729b50d902SRodney W. Grimes 
10739b50d902SRodney W. Grimes /*
10749b50d902SRodney W. Grimes  * Dump ICMP statistics.
10759b50d902SRodney W. Grimes  */
10769b50d902SRodney W. Grimes void
1077feda1a43SJohn Baldwin icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
10789b50d902SRodney W. Grimes {
10799eddb899SMark Johnston 	struct icmpstat icmpstat;
10804e00c309SGarrett Wollman 	size_t len;
10819eddb899SMark Johnston 	int i, first;
10829b50d902SRodney W. Grimes 
10839eddb899SMark Johnston 	if (fetch_stats("net.inet.icmp.stats", off, &icmpstat,
10849eddb899SMark Johnston 	    sizeof(icmpstat), kread_counters) != 0)
1085c73d99b5SRuslan Ermilov 		return;
10864e00c309SGarrett Wollman 
1087ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
1088ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
10899b50d902SRodney W. Grimes 
10909b50d902SRodney W. Grimes #define	p(f, m) if (icmpstat.f || sflag <= 1) \
1091ade9ccfeSMarcel Moolenaar 	xo_emit(m, icmpstat.f, plural(icmpstat.f))
109222694ebaSBruce Evans #define	p1a(f, m) if (icmpstat.f || sflag <= 1) \
1093ade9ccfeSMarcel Moolenaar 	xo_emit(m, icmpstat.f)
1094bd714208SRuslan Ermilov #define	p2(f, m) if (icmpstat.f || sflag <= 1) \
1095ade9ccfeSMarcel Moolenaar 	xo_emit(m, icmpstat.f, plurales(icmpstat.f))
10969b50d902SRodney W. Grimes 
1097ade9ccfeSMarcel Moolenaar 	p(icps_error, "\t{:icmp-calls/%lu} "
1098ade9ccfeSMarcel Moolenaar 	    "{N:/call%s to icmp_error}\n");
1099ade9ccfeSMarcel Moolenaar 	p(icps_oldicmp, "\t{:errors-not-from-message/%lu} "
1100ade9ccfeSMarcel Moolenaar 	    "{N:/error%s not generated in response to an icmp message}\n");
1101ade9ccfeSMarcel Moolenaar 
1102ade9ccfeSMarcel Moolenaar 	for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) {
11039b50d902SRodney W. Grimes 		if (icmpstat.icps_outhist[i] != 0) {
11049b50d902SRodney W. Grimes 			if (first) {
1105ade9ccfeSMarcel Moolenaar 				xo_open_list("output-histogram");
1106ade9ccfeSMarcel Moolenaar 				xo_emit("\tOutput histogram:\n");
11079b50d902SRodney W. Grimes 				first = 0;
11089b50d902SRodney W. Grimes 			}
1109ade9ccfeSMarcel Moolenaar 			xo_open_instance("output-histogram");
11104063583aSMaxim Konovalov 			if (icmpnames[i] != NULL)
1111ade9ccfeSMarcel Moolenaar 				xo_emit("\t\t{k:name/%s}: {:count/%lu}\n",
1112ade9ccfeSMarcel Moolenaar 				    icmpnames[i], icmpstat.icps_outhist[i]);
11134063583aSMaxim Konovalov 			else
1114ade9ccfeSMarcel Moolenaar 				xo_emit("\t\tunknown ICMP #{k:name/%d}: "
1115ade9ccfeSMarcel Moolenaar 				    "{:count/%lu}\n",
1116ade9ccfeSMarcel Moolenaar 				    i, icmpstat.icps_outhist[i]);
1117ade9ccfeSMarcel Moolenaar 			xo_close_instance("output-histogram");
11189b50d902SRodney W. Grimes 		}
1119ade9ccfeSMarcel Moolenaar 	}
1120ade9ccfeSMarcel Moolenaar 	if (!first)
1121ade9ccfeSMarcel Moolenaar 		xo_close_list("output-histogram");
1122ade9ccfeSMarcel Moolenaar 
1123ade9ccfeSMarcel Moolenaar 	p(icps_badcode, "\t{:dropped-bad-code/%lu} "
1124ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad code fields}\n");
1125ade9ccfeSMarcel Moolenaar 	p(icps_tooshort, "\t{:dropped-too-short/%lu} "
1126ade9ccfeSMarcel Moolenaar 	    "{N:/message%s less than the minimum length}\n");
1127ade9ccfeSMarcel Moolenaar 	p(icps_checksum, "\t{:dropped-bad-checksum/%lu} "
1128ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad checksum}\n");
1129ade9ccfeSMarcel Moolenaar 	p(icps_badlen, "\t{:dropped-bad-length/%lu} "
1130ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad length}\n");
1131ade9ccfeSMarcel Moolenaar 	p1a(icps_bmcastecho, "\t{:dropped-multicast-echo/%lu} "
1132ade9ccfeSMarcel Moolenaar 	    "{N:/multicast echo requests ignored}\n");
1133ade9ccfeSMarcel Moolenaar 	p1a(icps_bmcasttstamp, "\t{:dropped-multicast-timestamp/%lu} "
1134ade9ccfeSMarcel Moolenaar 	    "{N:/multicast timestamp requests ignored}\n");
1135ade9ccfeSMarcel Moolenaar 
1136ade9ccfeSMarcel Moolenaar 	for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) {
11379b50d902SRodney W. Grimes 		if (icmpstat.icps_inhist[i] != 0) {
11389b50d902SRodney W. Grimes 			if (first) {
1139ade9ccfeSMarcel Moolenaar 				xo_open_list("input-histogram");
1140ade9ccfeSMarcel Moolenaar 				xo_emit("\tInput histogram:\n");
11419b50d902SRodney W. Grimes 				first = 0;
11429b50d902SRodney W. Grimes 			}
1143ade9ccfeSMarcel Moolenaar 			xo_open_instance("input-histogram");
11444063583aSMaxim Konovalov 			if (icmpnames[i] != NULL)
1145ade9ccfeSMarcel Moolenaar 				xo_emit("\t\t{k:name/%s}: {:count/%lu}\n",
1146ade9ccfeSMarcel Moolenaar 					icmpnames[i],
11479b50d902SRodney W. Grimes 					icmpstat.icps_inhist[i]);
11484063583aSMaxim Konovalov 			else
1149ade9ccfeSMarcel Moolenaar 				xo_emit(
1150ade9ccfeSMarcel Moolenaar 			"\t\tunknown ICMP #{k:name/%d}: {:count/%lu}\n",
1151ade9ccfeSMarcel Moolenaar 					i, icmpstat.icps_inhist[i]);
1152ade9ccfeSMarcel Moolenaar 			xo_close_instance("input-histogram");
11539b50d902SRodney W. Grimes 		}
1154ade9ccfeSMarcel Moolenaar 	}
1155ade9ccfeSMarcel Moolenaar 	if (!first)
1156ade9ccfeSMarcel Moolenaar 		xo_close_list("input-histogram");
1157ade9ccfeSMarcel Moolenaar 
1158ade9ccfeSMarcel Moolenaar 	p(icps_reflect, "\t{:sent-packets/%lu} "
1159ade9ccfeSMarcel Moolenaar 	    "{N:/message response%s generated}\n");
1160ade9ccfeSMarcel Moolenaar 	p2(icps_badaddr, "\t{:discard-invalid-return-address/%lu} "
1161ade9ccfeSMarcel Moolenaar 	    "{N:/invalid return address%s}\n");
1162ade9ccfeSMarcel Moolenaar 	p(icps_noroute, "\t{:discard-no-route/%lu} "
1163ade9ccfeSMarcel Moolenaar 	    "{N:/no return route%s}\n");
11649b50d902SRodney W. Grimes #undef p
116522694ebaSBruce Evans #undef p1a
1166bd714208SRuslan Ermilov #undef p2
1167feda1a43SJohn Baldwin 	if (live) {
11684e00c309SGarrett Wollman 		len = sizeof i;
1169feda1a43SJohn Baldwin 		if (sysctlbyname("net.inet.icmp.maskrepl", &i, &len, NULL, 0) <
1170feda1a43SJohn Baldwin 		    0)
11714e00c309SGarrett Wollman 			return;
1172ade9ccfeSMarcel Moolenaar 		xo_emit("\tICMP address mask responses are "
1173ade9ccfeSMarcel Moolenaar 		    "{q:icmp-address-responses/%sabled}\n", i ? "en" : "dis");
11749b50d902SRodney W. Grimes 	}
1175ade9ccfeSMarcel Moolenaar 
1176ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1177feda1a43SJohn Baldwin }
11789b50d902SRodney W. Grimes 
1179d10910e6SBruce M Simpson /*
1180d10910e6SBruce M Simpson  * Dump IGMP statistics structure.
1181d10910e6SBruce M Simpson  */
1182d10910e6SBruce M Simpson void
1183d10910e6SBruce M Simpson igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
1184d10910e6SBruce M Simpson {
11859eddb899SMark Johnston 	struct igmpstat igmpstat;
1186d10910e6SBruce M Simpson 
11879eddb899SMark Johnston 	if (fetch_stats("net.inet.igmp.stats", 0, &igmpstat,
11889eddb899SMark Johnston 	    sizeof(igmpstat), kread) != 0)
1189d10910e6SBruce M Simpson 		return;
1190d10910e6SBruce M Simpson 
1191d10910e6SBruce M Simpson 	if (igmpstat.igps_version != IGPS_VERSION_3) {
1192ade9ccfeSMarcel Moolenaar 		xo_warnx("%s: version mismatch (%d != %d)", __func__,
1193d10910e6SBruce M Simpson 		    igmpstat.igps_version, IGPS_VERSION_3);
1194d10910e6SBruce M Simpson 	}
1195d10910e6SBruce M Simpson 	if (igmpstat.igps_len != IGPS_VERSION3_LEN) {
1196ade9ccfeSMarcel Moolenaar 		xo_warnx("%s: size mismatch (%d != %d)", __func__,
1197d10910e6SBruce M Simpson 		    igmpstat.igps_len, IGPS_VERSION3_LEN);
1198d10910e6SBruce M Simpson 	}
1199d10910e6SBruce M Simpson 
1200ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
1201ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1202d10910e6SBruce M Simpson 
1203d10910e6SBruce M Simpson #define	p64(f, m) if (igmpstat.f || sflag <= 1) \
1204ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t) igmpstat.f, plural(igmpstat.f))
1205d10910e6SBruce M Simpson #define	py64(f, m) if (igmpstat.f || sflag <= 1) \
1206ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f))
1207ade9ccfeSMarcel Moolenaar 
1208ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_total, "\t{:received-messages/%ju} "
1209ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1210ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_tooshort, "\t{:dropped-too-short/%ju} "
1211ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with too few bytes}\n");
1212ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_badttl, "\t{:dropped-wrong-ttl/%ju} "
1213ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with wrong TTL}\n");
1214ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
1215ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad checksum}\n");
1216ade9ccfeSMarcel Moolenaar 	py64(igps_rcv_v1v2_queries, "\t{:received-membership-queries/%ju} "
1217ade9ccfeSMarcel Moolenaar 	    "{N:/V1\\/V2 membership quer%s received}\n");
1218ade9ccfeSMarcel Moolenaar 	py64(igps_rcv_v3_queries, "\t{:received-v3-membership-queries/%ju} "
1219ade9ccfeSMarcel Moolenaar 	    "{N:/V3 membership quer%s received}\n");
1220ade9ccfeSMarcel Moolenaar 	py64(igps_rcv_badqueries, "\t{:dropped-membership-queries/%ju} "
1221ade9ccfeSMarcel Moolenaar 	    "{N:/membership quer%s received with invalid field(s)}\n");
1222ade9ccfeSMarcel Moolenaar 	py64(igps_rcv_gen_queries, "\t{:received-general-queries/%ju} "
1223ade9ccfeSMarcel Moolenaar 	    "{N:/general quer%s received}\n");
1224ade9ccfeSMarcel Moolenaar 	py64(igps_rcv_group_queries, "\t{:received-group-queries/%ju} "
1225ade9ccfeSMarcel Moolenaar 	    "{N:/group quer%s received}\n");
1226ade9ccfeSMarcel Moolenaar 	py64(igps_rcv_gsr_queries, "\t{:received-group-source-queries/%ju} "
1227ade9ccfeSMarcel Moolenaar 	    "{N:/group-source quer%s received}\n");
1228ade9ccfeSMarcel Moolenaar 	py64(igps_drop_gsr_queries, "\t{:dropped-group-source-queries/%ju} "
1229ade9ccfeSMarcel Moolenaar 	    "{N:/group-source quer%s dropped}\n");
1230ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_reports, "\t{:received-membership-requests/%ju} "
1231ade9ccfeSMarcel Moolenaar 	    "{N:/membership report%s received}\n");
1232ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_badreports, "\t{:dropped-membership-reports/%ju} "
1233ade9ccfeSMarcel Moolenaar 	    "{N:/membership report%s received with invalid field(s)}\n");
1234ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_ourreports, "\t"
1235ade9ccfeSMarcel Moolenaar 	    "{:received-membership-reports-matching/%ju} "
1236ade9ccfeSMarcel Moolenaar 	    "{N:/membership report%s received for groups to which we belong}"
1237ade9ccfeSMarcel Moolenaar 	    "\n");
1238ade9ccfeSMarcel Moolenaar 	p64(igps_rcv_nora, "\t{:received-v3-reports-no-router-alert/%ju} "
1239ade9ccfeSMarcel Moolenaar 	    "{N:/V3 report%s received without Router Alert}\n");
1240ade9ccfeSMarcel Moolenaar 	p64(igps_snd_reports, "\t{:sent-membership-reports/%ju} "
1241ade9ccfeSMarcel Moolenaar 	    "{N:/membership report%s sent}\n");
1242d10910e6SBruce M Simpson #undef p64
1243d10910e6SBruce M Simpson #undef py64
1244ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1245d10910e6SBruce M Simpson }
12469b50d902SRodney W. Grimes 
12479b50d902SRodney W. Grimes /*
1248c7b9b5bbSJeffrey Hsu  * Dump PIM statistics structure.
1249c7b9b5bbSJeffrey Hsu  */
1250c7b9b5bbSJeffrey Hsu void
1251feda1a43SJohn Baldwin pim_stats(u_long off __unused, const char *name, int af1 __unused,
1252feda1a43SJohn Baldwin     int proto __unused)
1253c7b9b5bbSJeffrey Hsu {
12549eddb899SMark Johnston 	struct pimstat pimstat;
1255c7b9b5bbSJeffrey Hsu 
12569eddb899SMark Johnston 	if (fetch_stats("net.inet.pim.stats", off, &pimstat,
12579eddb899SMark Johnston 	    sizeof(pimstat), kread_counters) != 0)
1258c7b9b5bbSJeffrey Hsu 		return;
1259c7b9b5bbSJeffrey Hsu 
1260ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
1261ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1262c7b9b5bbSJeffrey Hsu 
1263c7b9b5bbSJeffrey Hsu #define	p(f, m) if (pimstat.f || sflag <= 1) \
1264ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)pimstat.f, plural(pimstat.f))
1265c7b9b5bbSJeffrey Hsu #define	py(f, m) if (pimstat.f || sflag <= 1) \
1266ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)pimstat.f, pimstat.f != 1 ? "ies" : "y")
1267ade9ccfeSMarcel Moolenaar 
1268ade9ccfeSMarcel Moolenaar 	p(pims_rcv_total_msgs, "\t{:received-messages/%ju} "
1269ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1270ade9ccfeSMarcel Moolenaar 	p(pims_rcv_total_bytes, "\t{:received-bytes/%ju} "
1271ade9ccfeSMarcel Moolenaar 	    "{N:/byte%s received}\n");
1272ade9ccfeSMarcel Moolenaar 	p(pims_rcv_tooshort, "\t{:dropped-too-short/%ju} "
1273ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with too few bytes}\n");
1274ade9ccfeSMarcel Moolenaar 	p(pims_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
1275ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad checksum}\n");
1276ade9ccfeSMarcel Moolenaar 	p(pims_rcv_badversion, "\t{:dropped-bad-version/%ju} "
1277ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad version}\n");
1278ade9ccfeSMarcel Moolenaar 	p(pims_rcv_registers_msgs, "\t{:received-data-register-messages/%ju} "
1279ade9ccfeSMarcel Moolenaar 	    "{N:/data register message%s received}\n");
1280ade9ccfeSMarcel Moolenaar 	p(pims_rcv_registers_bytes, "\t{:received-data-register-bytes/%ju} "
1281ade9ccfeSMarcel Moolenaar 	    "{N:/data register byte%s received}\n");
1282ade9ccfeSMarcel Moolenaar 	p(pims_rcv_registers_wrongiif, "\t"
1283ade9ccfeSMarcel Moolenaar 	    "{:received-data-register-wrong-interface/%ju} "
1284ade9ccfeSMarcel Moolenaar 	    "{N:/data register message%s received on wrong iif}\n");
1285ade9ccfeSMarcel Moolenaar 	p(pims_rcv_badregisters, "\t{:received-bad-registers/%ju} "
1286ade9ccfeSMarcel Moolenaar 	    "{N:/bad register%s received}\n");
1287ade9ccfeSMarcel Moolenaar 	p(pims_snd_registers_msgs, "\t{:sent-data-register-messages/%ju} "
1288ade9ccfeSMarcel Moolenaar 	    "{N:/data register message%s sent}\n");
1289ade9ccfeSMarcel Moolenaar 	p(pims_snd_registers_bytes, "\t{:sent-data-register-bytes/%ju} "
1290ade9ccfeSMarcel Moolenaar 	    "{N:/data register byte%s sent}\n");
1291c7b9b5bbSJeffrey Hsu #undef p
1292c7b9b5bbSJeffrey Hsu #undef py
1293ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1294c7b9b5bbSJeffrey Hsu }
1295c7b9b5bbSJeffrey Hsu 
1296c7b9b5bbSJeffrey Hsu /*
12979b50d902SRodney W. Grimes  * Pretty print an Internet address (net address + port).
12989b50d902SRodney W. Grimes  */
12999b50d902SRodney W. Grimes void
1300ade9ccfeSMarcel Moolenaar inetprint(const char *container, struct in_addr *in, int port,
1301046aad39SHajimu UMEMOTO     const char *proto, int num_port, const int af1)
13029b50d902SRodney W. Grimes {
13039b50d902SRodney W. Grimes 	struct servent *sp = 0;
13049b50d902SRodney W. Grimes 	char line[80], *cp;
1305cfa1ca9dSYoshinobu Inoue 	int width;
1306f193c8ceSXin LI 	size_t alen, plen;
13079b50d902SRodney W. Grimes 
1308ade9ccfeSMarcel Moolenaar 	if (container)
1309ade9ccfeSMarcel Moolenaar 		xo_open_container(container);
1310ade9ccfeSMarcel Moolenaar 
1311080b7f49SDag-Erling Smørgrav 	if (Wflag)
1312f193c8ceSXin LI 	    snprintf(line, sizeof(line), "%s.", inetname(in));
1313080b7f49SDag-Erling Smørgrav 	else
1314f193c8ceSXin LI 	    snprintf(line, sizeof(line), "%.*s.",
1315f193c8ceSXin LI 		(Aflag && !num_port) ? 12 : 16, inetname(in));
1316f193c8ceSXin LI 	alen = strlen(line);
1317f193c8ceSXin LI 	cp = line + alen;
1318a01e3379SDavid Malone 	if (!num_port && port)
13199b50d902SRodney W. Grimes 		sp = getservbyport((int)port, proto);
13209b50d902SRodney W. Grimes 	if (sp || port == 0)
1321f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
1322f193c8ceSXin LI 		    "%.15s ", sp ? sp->s_name : "*");
13239b50d902SRodney W. Grimes 	else
1324f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
1325f193c8ceSXin LI 		    "%d ", ntohs((u_short)port));
1326046aad39SHajimu UMEMOTO 	width = (Aflag && !Wflag) ? 18 :
1327046aad39SHajimu UMEMOTO 		((!Wflag || af1 == AF_INET) ? 22 : 45);
1328080b7f49SDag-Erling Smørgrav 	if (Wflag)
1329ade9ccfeSMarcel Moolenaar 		xo_emit("{d:target/%-*s} ", width, line);
1330080b7f49SDag-Erling Smørgrav 	else
1331ade9ccfeSMarcel Moolenaar 		xo_emit("{d:target/%-*.*s} ", width, width, line);
1332ade9ccfeSMarcel Moolenaar 
1333f193c8ceSXin LI 	plen = strlen(cp) - 1;
1334f193c8ceSXin LI 	alen--;
1335ade9ccfeSMarcel Moolenaar 	xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
1336ade9ccfeSMarcel Moolenaar 	    plen, cp);
1337ade9ccfeSMarcel Moolenaar 
1338ade9ccfeSMarcel Moolenaar 	if (container)
1339ade9ccfeSMarcel Moolenaar 		xo_close_container(container);
13409b50d902SRodney W. Grimes }
13419b50d902SRodney W. Grimes 
13429b50d902SRodney W. Grimes /*
13439b50d902SRodney W. Grimes  * Construct an Internet address representation.
134465ea0024SAssar Westerlund  * If numeric_addr has been supplied, give
13459b50d902SRodney W. Grimes  * numeric value, otherwise try for symbolic name.
13469b50d902SRodney W. Grimes  */
13479b50d902SRodney W. Grimes char *
13485e051718SAssar Westerlund inetname(struct in_addr *inp)
13499b50d902SRodney W. Grimes {
1350a01e3379SDavid Malone 	char *cp;
1351d121b556SBrian Somers 	static char line[MAXHOSTNAMELEN];
13529b50d902SRodney W. Grimes 	struct hostent *hp;
13539b50d902SRodney W. Grimes 	struct netent *np;
13549b50d902SRodney W. Grimes 
13559b50d902SRodney W. Grimes 	cp = 0;
135665ea0024SAssar Westerlund 	if (!numeric_addr && inp->s_addr != INADDR_ANY) {
13579b50d902SRodney W. Grimes 		int net = inet_netof(*inp);
13589b50d902SRodney W. Grimes 		int lna = inet_lnaof(*inp);
13599b50d902SRodney W. Grimes 
13609b50d902SRodney W. Grimes 		if (lna == INADDR_ANY) {
13619b50d902SRodney W. Grimes 			np = getnetbyaddr(net, AF_INET);
13629b50d902SRodney W. Grimes 			if (np)
13639b50d902SRodney W. Grimes 				cp = np->n_name;
13649b50d902SRodney W. Grimes 		}
1365ef1cb629SMarcelo Araujo 		if (cp == NULL) {
13669b50d902SRodney W. Grimes 			hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
13679b50d902SRodney W. Grimes 			if (hp) {
13689b50d902SRodney W. Grimes 				cp = hp->h_name;
1369d121b556SBrian Somers 				trimdomain(cp, strlen(cp));
13709b50d902SRodney W. Grimes 			}
13719b50d902SRodney W. Grimes 		}
13729b50d902SRodney W. Grimes 	}
13739b50d902SRodney W. Grimes 	if (inp->s_addr == INADDR_ANY)
13749b50d902SRodney W. Grimes 		strcpy(line, "*");
13759a1f6729SWarner Losh 	else if (cp) {
13761c109628SXin LI 		strlcpy(line, cp, sizeof(line));
13779a1f6729SWarner Losh 	} else {
13789b50d902SRodney W. Grimes 		inp->s_addr = ntohl(inp->s_addr);
137922694ebaSBruce Evans #define	C(x)	((u_int)((x) & 0xff))
1380f193c8ceSXin LI 		snprintf(line, sizeof(line), "%u.%u.%u.%u",
1381f193c8ceSXin LI 		    C(inp->s_addr >> 24), C(inp->s_addr >> 16),
1382f193c8ceSXin LI 		    C(inp->s_addr >> 8), C(inp->s_addr));
13839b50d902SRodney W. Grimes 	}
13849b50d902SRodney W. Grimes 	return (line);
13859b50d902SRodney W. Grimes }
1386