xref: /f-stack/tools/netstat/netstat.h (revision 10c1fea8)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1992, 1993
5  *	Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)netstat.h	8.2 (Berkeley) 1/4/94
32  * $FreeBSD$
33  */
34 
35 #include <sys/cdefs.h>
36 
37 #ifdef FSTACK
38 #ifndef __unused
39 #define __unused __attribute__((__unused__))
40 #endif
41 #endif
42 
43 #define	satosin(sa)	((struct sockaddr_in *)(sa))
44 #define	satosin6(sa)	((struct sockaddr_in6 *)(sa))
45 #define	sin6tosa(sin6)	((struct sockaddr *)(sin6))
46 
47 extern int	Aflag;	/* show addresses of protocol control block */
48 extern int	aflag;	/* show all sockets (including servers) */
49 extern int	bflag;	/* show i/f total bytes in/out */
50 extern int	cflag;	/* show congestion control stats */
51 extern int	Cflag;	/* show congestion control algo and stack */
52 extern int	dflag;	/* show i/f dropped packets */
53 extern int	gflag;	/* show group (multicast) routing or stats */
54 extern int	hflag;	/* show counters in human readable format */
55 extern int	iflag;	/* show interfaces */
56 extern int	Lflag;	/* show size of listen queues */
57 extern int	mflag;	/* show memory stats */
58 extern int	noutputs;	/* how much outputs before we exit */
59 extern int	numeric_addr;	/* show addresses numerically */
60 extern int	numeric_port;	/* show ports numerically */
61 extern int	Pflag;	/* show TCP log ID */
62 extern int	rflag;	/* show routing tables (or routing stats) */
63 extern int	Rflag;	/* show flowid / RSS information */
64 extern int	sflag;	/* show protocol statistics */
65 extern int	Tflag;  /* show TCP control block info */
66 extern int	Wflag;	/* wide display */
67 extern int	xflag;	/* extended display, includes all socket buffer info */
68 extern int	zflag;	/* zero stats */
69 
70 extern int	interval; /* repeat interval for i/f stats */
71 
72 extern char	*interface; /* desired i/f for stats, or NULL for all i/fs */
73 extern int	unit;	/* unit number for above */
74 
75 extern int	live;	/* true if we are examining a live system */
76 
77 typedef	int kreadfn_t(u_long, void *, size_t);
78 int	fetch_stats(const char *, u_long, void *, size_t, kreadfn_t);
79 int	fetch_stats_ro(const char *, u_long, void *, size_t, kreadfn_t);
80 
81 int	kread(u_long addr, void *buf, size_t size);
82 uint64_t kread_counter(u_long addr);
83 int	kread_counters(u_long addr, void *buf, size_t size);
84 void	kset_dpcpu(u_int);
85 const char *plural(uintmax_t);
86 const char *plurales(uintmax_t);
87 const char *pluralies(uintmax_t);
88 
89 struct sockaddr;
90 struct socket;
91 struct xsocket;
92 int	sotoxsocket(struct socket *, struct xsocket *);
93 void	protopr(u_long, const char *, int, int);
94 void	tcp_stats(u_long, const char *, int, int);
95 void	udp_stats(u_long, const char *, int, int);
96 #ifdef SCTP
97 void	sctp_protopr(u_long, const char *, int, int);
98 void	sctp_stats(u_long, const char *, int, int);
99 #endif
100 void	arp_stats(u_long, const char *, int, int);
101 void	ip_stats(u_long, const char *, int, int);
102 void	icmp_stats(u_long, const char *, int, int);
103 void	igmp_stats(u_long, const char *, int, int);
104 void	pim_stats(u_long, const char *, int, int);
105 void	carp_stats(u_long, const char *, int, int);
106 void	pfsync_stats(u_long, const char *, int, int);
107 #ifdef IPSEC
108 void	ipsec_stats(u_long, const char *, int, int);
109 void	esp_stats(u_long, const char *, int, int);
110 void	ah_stats(u_long, const char *, int, int);
111 void	ipcomp_stats(u_long, const char *, int, int);
112 #endif
113 
114 #ifdef INET
115 struct in_addr;
116 
117 char	*inetname(struct in_addr *);
118 #endif
119 
120 #ifdef INET6
121 struct in6_addr;
122 
123 char	*inet6name(struct in6_addr *);
124 void	ip6_stats(u_long, const char *, int, int);
125 void	ip6_ifstats(char *);
126 void	icmp6_stats(u_long, const char *, int, int);
127 void	icmp6_ifstats(char *);
128 void	pim6_stats(u_long, const char *, int, int);
129 void	rip6_stats(u_long, const char *, int, int);
130 void	mroute6pr(void);
131 void	mrt6_stats(void);
132 
133 struct sockaddr_in6;
134 struct in6_addr;
135 void in6_fillscopeid(struct sockaddr_in6 *);
136 void	inet6print(const char *, struct in6_addr *, int, const char *, int);
137 #endif /*INET6*/
138 
139 #ifdef IPSEC
140 void	pfkey_stats(u_long, const char *, int, int);
141 #endif
142 
143 void	mbpr(void *, u_long);
144 
145 void	netisr_stats(void);
146 
147 void	hostpr(u_long, u_long);
148 void	impstats(u_long, u_long);
149 
150 void	intpr(void (*)(char *), int);
151 
152 void	pr_family(int);
153 void	rt_stats(void);
154 
155 char	*routename(struct sockaddr *, int);
156 const char *netname(struct sockaddr *, struct sockaddr *);
157 void	routepr(int, int);
158 int	p_sockaddr(const char *name, struct sockaddr *sa,
159 	    struct sockaddr *mask, int flags, int width);
160 const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask,
161 	    int flags);
162 
163 #ifdef NETGRAPH
164 void	netgraphprotopr(u_long, const char *, int, int);
165 #endif
166 
167 void	unixpr(u_long, u_long, u_long, u_long, u_long, bool *);
168 
169 void	mroutepr(void);
170 void	mrt_stats(void);
171 void	bpf_stats(char *);
172 void	nhops_print(int fibnum, int af);
173 void	nhgrp_print(int fibnum, int af);
174