xref: /f-stack/tools/netstat/common.h (revision 22ce4aff)
1*22ce4affSfengbojiang /*-
2*22ce4affSfengbojiang  * SPDX-License-Identifier: BSD-3-Clause
3*22ce4affSfengbojiang  *
4*22ce4affSfengbojiang  * Copyright (c) 1992, 1993
5*22ce4affSfengbojiang  *	Regents of the University of California.  All rights reserved.
6*22ce4affSfengbojiang  *
7*22ce4affSfengbojiang  * Redistribution and use in source and binary forms, with or without
8*22ce4affSfengbojiang  * modification, are permitted provided that the following conditions
9*22ce4affSfengbojiang  * are met:
10*22ce4affSfengbojiang  * 1. Redistributions of source code must retain the above copyright
11*22ce4affSfengbojiang  *    notice, this list of conditions and the following disclaimer.
12*22ce4affSfengbojiang  * 2. Redistributions in binary form must reproduce the above copyright
13*22ce4affSfengbojiang  *    notice, this list of conditions and the following disclaimer in the
14*22ce4affSfengbojiang  *    documentation and/or other materials provided with the distribution.
15*22ce4affSfengbojiang  * 3. Neither the name of the University nor the names of its contributors
16*22ce4affSfengbojiang  *    may be used to endorse or promote products derived from this software
17*22ce4affSfengbojiang  *    without specific prior written permission.
18*22ce4affSfengbojiang  *
19*22ce4affSfengbojiang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*22ce4affSfengbojiang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*22ce4affSfengbojiang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*22ce4affSfengbojiang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*22ce4affSfengbojiang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*22ce4affSfengbojiang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*22ce4affSfengbojiang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*22ce4affSfengbojiang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*22ce4affSfengbojiang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*22ce4affSfengbojiang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*22ce4affSfengbojiang  * SUCH DAMAGE.
30*22ce4affSfengbojiang  *
31*22ce4affSfengbojiang  *	@(#)netstat.h	8.2 (Berkeley) 1/4/94
32*22ce4affSfengbojiang  * $FreeBSD$
33*22ce4affSfengbojiang  */
34*22ce4affSfengbojiang 
35*22ce4affSfengbojiang #ifndef _NETSTAT_COMMON_H_
36*22ce4affSfengbojiang #define _NETSTAT_COMMON_H_
37*22ce4affSfengbojiang 
38*22ce4affSfengbojiang struct bits {
39*22ce4affSfengbojiang 	u_long	b_mask;
40*22ce4affSfengbojiang 	char	b_val;
41*22ce4affSfengbojiang 	const char *b_name;
42*22ce4affSfengbojiang };
43*22ce4affSfengbojiang extern struct bits rt_bits[];
44*22ce4affSfengbojiang 
45*22ce4affSfengbojiang const char *fmt_flags(const struct bits *p, int f);
46*22ce4affSfengbojiang void print_flags_generic(int flags, const struct bits *pbits,
47*22ce4affSfengbojiang     const char *format, const char *tag_name);
48*22ce4affSfengbojiang int print_sockaddr(const char *name, struct sockaddr *sa,
49*22ce4affSfengbojiang     struct sockaddr *mask, int flags, int width);
50*22ce4affSfengbojiang 
51*22ce4affSfengbojiang struct ifmap_entry {
52*22ce4affSfengbojiang 	char ifname[IFNAMSIZ];
53*22ce4affSfengbojiang };
54*22ce4affSfengbojiang 
55*22ce4affSfengbojiang struct ifmap_entry *prepare_ifmap(size_t *ifmap_size);
56*22ce4affSfengbojiang 
57*22ce4affSfengbojiang struct rt_msghdr;
58*22ce4affSfengbojiang struct nhops_map {
59*22ce4affSfengbojiang 	uint32_t		idx;
60*22ce4affSfengbojiang 	struct rt_msghdr	*rtm;
61*22ce4affSfengbojiang };
62*22ce4affSfengbojiang 
63*22ce4affSfengbojiang struct nhops_dump {
64*22ce4affSfengbojiang 	void 		*nh_buf;
65*22ce4affSfengbojiang 	struct nhops_map *nh_map;
66*22ce4affSfengbojiang 	size_t		nh_count;
67*22ce4affSfengbojiang };
68*22ce4affSfengbojiang 
69*22ce4affSfengbojiang void dump_nhops_sysctl(int fibnum, int af, struct nhops_dump *nd);
70*22ce4affSfengbojiang struct nhop_map;
71*22ce4affSfengbojiang void nhop_map_update(struct nhop_map *map, uint32_t idx, char *gw, char *ifname);
72*22ce4affSfengbojiang 
73*22ce4affSfengbojiang 
74*22ce4affSfengbojiang #endif
75*22ce4affSfengbojiang 
76