xref: /freebsd/usr.bin/netstat/netstat.h (revision 87b759f0fa1f7554d50ce640c40138512bbded44)
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 
32 #include <sys/cdefs.h>
33 
34 #define NETSTAT_XO_VERSION "1"
35 
36 #define	satosin(sa)	((struct sockaddr_in *)(sa))
37 #define	satosin6(sa)	((struct sockaddr_in6 *)(sa))
38 #define	sin6tosa(sin6)	((struct sockaddr *)(sin6))
39 
40 extern int	Aflag;	/* show addresses of protocol control block */
41 extern int	aflag;	/* show all sockets (including servers) */
42 extern int	bflag;	/* show i/f total bytes in/out */
43 extern int	cflag;	/* show congestion control stats */
44 extern int	Cflag;	/* show congestion control algo and stack */
45 extern int	dflag;	/* show i/f dropped packets */
46 extern int	gflag;	/* show group (multicast) routing or stats */
47 extern int	hflag;	/* show counters in human readable format */
48 extern int	iflag;	/* show interfaces */
49 extern int	Lflag;	/* show size of listen queues */
50 extern int	mflag;	/* show memory stats */
51 extern int	noutputs;	/* how much outputs before we exit */
52 extern int	numeric_addr;	/* show addresses numerically */
53 extern int	numeric_port;	/* show ports numerically */
54 extern int	Pflag;	/* show TCP log ID */
55 extern int	rflag;	/* show routing tables (or routing stats) */
56 extern int	Rflag;	/* show flowid / RSS information */
57 extern int	sflag;	/* show protocol statistics */
58 extern int	Tflag;  /* show TCP control block info */
59 extern int	Wflag;	/* wide display */
60 extern int	xflag;	/* extended display, includes all socket buffer info */
61 extern int	zflag;	/* zero stats */
62 
63 extern int	interval; /* repeat interval for i/f stats */
64 
65 extern char	*interface; /* desired i/f for stats, or NULL for all i/fs */
66 extern int	unit;	/* unit number for above */
67 
68 extern int	live;	/* true if we are examining a live system */
69 
70 typedef	int kreadfn_t(u_long, void *, size_t);
71 int	fetch_stats(const char *, u_long, void *, size_t, kreadfn_t);
72 int	fetch_stats_ro(const char *, u_long, void *, size_t, kreadfn_t);
73 
74 int	kread(u_long addr, void *buf, size_t size);
75 uint64_t kread_counter(u_long addr);
76 int	kread_counters(u_long addr, void *buf, size_t size);
77 void	kset_dpcpu(u_int);
78 const char *plural(uintmax_t);
79 const char *plurales(uintmax_t);
80 const char *pluralies(uintmax_t);
81 
82 struct sockaddr;
83 struct socket;
84 struct xsocket;
85 int	sotoxsocket(struct socket *, struct xsocket *);
86 void	protopr(u_long, const char *, int, int);
87 void	tcp_stats(u_long, const char *, int, int);
88 void	udp_stats(u_long, const char *, int, int);
89 #ifdef SCTP
90 void	sctp_protopr(u_long, const char *, int, int);
91 void	sctp_stats(u_long, const char *, int, int);
92 #endif
93 void	arp_stats(u_long, const char *, int, int);
94 void	divert_stats(u_long, const char *, int, int);
95 void	ip_stats(u_long, const char *, int, int);
96 void	icmp_stats(u_long, const char *, int, int);
97 void	igmp_stats(u_long, const char *, int, int);
98 void	pim_stats(u_long, const char *, int, int);
99 void	carp_stats(u_long, const char *, int, int);
100 void	pfsync_stats(u_long, const char *, int, int);
101 void	pflow_stats(u_long, const char *, int, int);
102 #ifdef IPSEC
103 void	ipsec_stats(u_long, const char *, int, int);
104 void	esp_stats(u_long, const char *, int, int);
105 void	ah_stats(u_long, const char *, int, int);
106 void	ipcomp_stats(u_long, const char *, int, int);
107 #endif
108 
109 #ifdef INET
110 struct in_addr;
111 
112 char	*inetname(struct in_addr *);
113 #endif
114 
115 #ifdef INET6
116 struct in6_addr;
117 
118 char	*inet6name(struct in6_addr *);
119 void	ip6_stats(u_long, const char *, int, int);
120 void	ip6_ifstats(char *);
121 void	icmp6_stats(u_long, const char *, int, int);
122 void	icmp6_ifstats(char *);
123 void	pim6_stats(u_long, const char *, int, int);
124 void	rip6_stats(u_long, const char *, int, int);
125 void	mroute6pr(void);
126 void	mrt6_stats(void);
127 
128 struct sockaddr_in6;
129 struct in6_addr;
130 void in6_fillscopeid(struct sockaddr_in6 *);
131 void	inet6print(const char *, struct in6_addr *, int, const char *, int);
132 #endif /*INET6*/
133 
134 #ifdef IPSEC
135 void	pfkey_stats(u_long, const char *, int, int);
136 #endif
137 
138 void	mbpr(void *, u_long);
139 
140 void	netisr_stats(void);
141 
142 void	hostpr(u_long, u_long);
143 void	impstats(u_long, u_long);
144 
145 void	intpr(void (*)(char *), int);
146 
147 void	pr_family(int);
148 void	rt_stats(void);
149 
150 char	*routename(struct sockaddr *, int);
151 const char *netname(struct sockaddr *, struct sockaddr *);
152 void	routepr(int, int);
153 int	p_sockaddr(const char *name, struct sockaddr *sa,
154 	    struct sockaddr *mask, int flags, int width);
155 const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask,
156 	    int flags);
157 
158 #ifdef NETGRAPH
159 void	netgraphprotopr(u_long, const char *, int, int);
160 #endif
161 
162 void	unixpr(u_long, u_long, u_long, u_long, u_long, bool *);
163 
164 void	mroutepr(void);
165 void	mrt_stats(void);
166 void	bpf_stats(char *);
167 void	nhops_print(int fibnum, int af);
168 void	nhgrp_print(int fibnum, int af);
169