Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / common / C / netstat / mroute.c
blobc8a95475fd545d4f2f37783a6f3072223b93adf9
1 /*
2 * Copyright (c) 1989 Stephen Deering
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 2006
6 * Pavel Fedin
8 * This code is derived from software contributed to Berkeley by
9 * Stephen Deering of Stanford University.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
39 * @(#)mroute.c 8.1 (Berkeley) 6/6/93
43 * Print DVMRP multicast routing structures and statistics.
45 * MROUTING 1.0
48 #ifdef ENABLE_MULTICAST
49 #include <sys/param.h>
50 #include <sys/socket.h>
51 #include <sys/socketvar.h>
52 #include <sys/protosw.h>
54 #include <net/if.h>
55 #include <netinet/in.h>
56 #include <netinet/igmp.h>
57 #define KERNEL 1
58 #include <netinet/ip_mroute.h>
59 #undef KERNEL
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include "netstat.h"
65 void
66 mroutepr(mrpaddr, mrtaddr, vifaddr)
67 u_long mrpaddr, mrtaddr, vifaddr;
69 #if 0
70 u_int mrtproto;
71 struct mrt *mrttable[MRTHASHSIZ];
72 struct vif viftable[MAXVIFS];
73 register struct mrt *mrt;
74 struct mrt smrt;
75 register struct vif *v;
76 register vifi_t vifi;
77 register struct in_addr *grp;
78 register int i, n;
79 register int banner_printed;
80 register int saved_nflag;
82 if (mrpaddr == 0) {
83 printf("ip_mrtproto: symbol not in namelist\n");
84 return;
87 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
88 switch (mrtproto) {
90 case 0:
91 printf("no multicast routing compiled into this system\n");
92 return;
94 case IGMP_DVMRP:
95 break;
97 default:
98 printf("multicast routing protocol %u, unknown\n", mrtproto);
99 return;
102 if (mrtaddr == 0) {
103 printf("mrttable: symbol not in namelist\n");
104 return;
106 if (vifaddr == 0) {
107 printf("viftable: symbol not in namelist\n");
108 return;
111 saved_nflag = nflag;
112 nflag = 1;
114 kread(vifaddr, (char *)&viftable, sizeof(viftable));
115 banner_printed = 0;
116 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
117 if (v->v_lcl_addr.s_addr == 0)
118 continue;
120 if (!banner_printed) {
121 printf("\nVirtual Interface Table\n%s%s",
122 " Vif Threshold Local-Address ",
123 "Remote-Address Groups\n");
124 banner_printed = 1;
127 printf(" %2u %3u %-15.15s",
128 vifi, v->v_threshold, routename(v->v_lcl_addr.s_addr));
129 printf(" %-15.15s\n", (v->v_flags & VIFF_TUNNEL) ?
130 routename(v->v_rmt_addr.s_addr) : "");
132 n = v->v_lcl_grps_n;
133 grp = (struct in_addr *)malloc(n * sizeof(*grp));
134 if (grp == NULL) {
135 printf("v_lcl_grps_n: malloc failed\n");
136 return;
138 kread((u_long)v->v_lcl_grps, (caddr_t)grp, n * sizeof(*grp));
139 for (i = 0; i < n; ++i)
140 printf("%51s %-15.15s\n",
141 "", routename((grp++)->s_addr));
142 free(grp);
144 if (!banner_printed)
145 printf("\nVirtual Interface Table is empty\n");
147 kread(mrtaddr, (char *)&mrttable, sizeof(mrttable));
148 banner_printed = 0;
149 for (i = 0; i < MRTHASHSIZ; ++i) {
150 for (mrt = mrttable[i]; mrt != NULL; mrt = mrt->mrt_next) {
151 if (!banner_printed) {
152 printf("\nMulticast Routing Table\n%s",
153 " Hash Origin-Subnet In-Vif Out-Vifs\n");
154 banner_printed = 1;
157 kread((u_long)mrt, (char *)&smrt, sizeof(*mrt));
158 mrt = &smrt;
159 printf(" %3u %-15.15s %2u ",
160 i, netname(mrt->mrt_origin.s_addr,
161 ntohl(mrt->mrt_originmask.s_addr)),
162 mrt->mrt_parent);
163 for (vifi = 0; vifi < MAXVIFS; ++vifi)
164 if (VIFM_ISSET(vifi, mrt->mrt_children))
165 printf(" %u%c",
166 vifi,
167 VIFM_ISSET(vifi, mrt->mrt_leaves) ?
168 '*' : ' ');
169 printf("\n");
172 if (!banner_printed)
173 printf("\nMulticast Routing Table is empty\n");
175 printf("\n");
176 nflag = saved_nflag;
177 #else
178 printf("this isn't supported yet\n");
179 #endif
183 void
184 mrt_stats(mrpaddr, mstaddr)
185 u_long mrpaddr, mstaddr;
187 u_int mrtproto;
188 struct mrtstat mrtstat;
190 if(mrpaddr == 0) {
191 printf("ip_mrtproto: symbol not in namelist\n");
192 return;
195 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
196 switch (mrtproto) {
197 case 0:
198 printf("no multicast routing compiled into this system\n");
199 return;
201 case IGMP_DVMRP:
202 break;
204 default:
205 printf("multicast routing protocol %u, unknown\n", mrtproto);
206 return;
209 if (mstaddr == 0) {
210 printf("mrtstat: symbol not in namelist\n");
211 return;
214 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
215 printf("multicast routing:\n");
216 printf(" %10u multicast forwarding cache lookup%s\n",
217 mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups));
218 printf(" %10u multicast forwarding cache miss%s\n",
219 mrtstat.mrts_mfc_misses, plurales(mrtstat.mrts_mfc_misses));
220 printf(" %10u upcall%s to mrouted\n",
221 mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
222 printf(" %10u upcall queue overflow%s\n",
223 mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
224 printf(" %10u cache cleanup%s\n",
225 mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
226 printf(" %10u datagram%s with no route for origin\n",
227 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
228 printf(" %10u datagram%s with malformed tunnel options\n",
229 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
230 printf(" %10u datagram%s with no room for tunnel options\n",
231 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
232 printf(" %10u datagram%s arrived on wrong interface\n",
233 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
234 printf(" %10u datagram%s selectively dropped\n",
235 mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
236 printf(" %10u datagram%s dropped due to queue overflow\n",
237 mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
238 printf(" %10u datagram%s dropped for being too large\n",
239 mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
241 #endif