]>
git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/mroute.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1989 Stephen Deering
26 * Copyright (c) 1992, 1993
27 * The Regents of the University of California. All rights reserved.
29 * This code is derived from software contributed to Berkeley by
30 * Stephen Deering of Stanford University.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)mroute.c 8.2 (Berkeley) 4/28/95
64 * Print DVMRP multicast routing structures and statistics.
69 #include <sys/param.h>
70 #include <sys/queue.h>
71 #include <sys/socket.h>
72 #include <sys/socketvar.h>
75 #include <sys/sysctl.h>
78 #include <netinet/in.h>
79 #include <netinet/igmp.h>
80 #include <net/route.h>
81 #include <netinet/ip_mroute.h>
90 struct mfc
**mfctable
= 0;
91 struct vif viftable
[MAXVIFS
];
93 register struct vif
*v
;
96 register int banner_printed
;
97 register int saved_nflag
;
104 len
= MAXVIFS
* sizeof(struct vif
);
105 if (sysctlbyname("net.inet.ip.viftable", viftable
, &len
, 0, 0) == -1) {
106 printf("No IPv4 multicast routing compiled into this system.\n");
111 for (vifi
= 0, v
= viftable
; vifi
< MAXVIFS
; ++vifi
, ++v
) {
112 if (v
->v_lcl_addr
.s_addr
== 0)
116 if (!banner_printed
) {
117 printf("\nVirtual Interface Table\n"
118 " Vif Thresh Rate Local-Address "
119 "Remote-Address Pkts-In Pkts-Out\n");
123 printf(" %2u %6u %4d %-15.15s",
124 /* opposite math of add_vif() */
125 vifi
, v
->v_threshold
, v
->v_rate_limit
* 1000 / 1024,
126 routename(v
->v_lcl_addr
.s_addr
));
127 printf(" %-15.15s", (v
->v_flags
& VIFF_TUNNEL
) ?
128 routename(v
->v_rmt_addr
.s_addr
) : "");
130 printf(" %9lu %9lu\n", v
->v_pkt_in
, v
->v_pkt_out
);
133 printf("\nVirtual Interface Table is empty\n");
135 if (sysctlbyname("net.inet.ip.mfctable", 0, &len
, 0, 0) == -1) {
136 printf("No IPv4 multicast routing compiled into this system.\n");
139 mfctable
= malloc(len
);
142 if (sysctlbyname("net.inet.ip.mfctable", mfctable
, &len
, 0, 0) == -1) {
143 printf("No IPv4 multicast routing compiled into this system.\n");
147 for (i
= 0; i
< MFCTBLSIZ
; ++i
) {
150 if (!banner_printed
) {
151 printf("\nIPv4 Multicast Forwarding Cache\n"
153 " Packets In-Vif Out-Vifs:Ttls\n");
157 printf(" %-15.15s", routename(mfc
.mfc_origin
.s_addr
));
158 printf(" %-15.15s", routename(mfc
.mfc_mcastgrp
.s_addr
));
159 printf(" %9lu", mfc
.mfc_pkt_cnt
);
160 printf(" %3d ", mfc
.mfc_parent
);
161 for (vifi
= 0; vifi
<= maxvif
; vifi
++) {
162 if (mfc
.mfc_ttls
[vifi
] > 0)
163 printf(" %u:%u", vifi
,
171 printf("\nMulticast Routing Table is empty\n");
183 struct mrtstat mrtstat
;
184 size_t len
= sizeof(struct mrtstat
);
186 if(sysctlbyname("net.inet.ip.mrtstat", &mrtstat
, &len
, 0, 0) == -1) {
187 printf("No IPv4 multicast routing compiled into this system.\n");
191 printf("IPv4 multicast forwarding:\n");
192 printf(" %10lu multicast forwarding cache lookup%s\n",
193 mrtstat
.mrts_mfc_lookups
, plural(mrtstat
.mrts_mfc_lookups
));
194 printf(" %10lu multicast forwarding cache miss%s\n",
195 mrtstat
.mrts_mfc_misses
, plurales(mrtstat
.mrts_mfc_misses
));
196 printf(" %10lu upcall%s to mrouted\n",
197 mrtstat
.mrts_upcalls
, plural(mrtstat
.mrts_upcalls
));
198 printf(" %10lu upcall queue overflow%s\n",
199 mrtstat
.mrts_upq_ovflw
, plural(mrtstat
.mrts_upq_ovflw
));
200 printf(" %10lu upcall%s dropped due to full socket buffer\n",
201 mrtstat
.mrts_upq_sockfull
, plural(mrtstat
.mrts_upq_sockfull
));
202 printf(" %10lu cache cleanup%s\n",
203 mrtstat
.mrts_cache_cleanups
, plural(mrtstat
.mrts_cache_cleanups
));
204 printf(" %10lu datagram%s with no route for origin\n",
205 mrtstat
.mrts_no_route
, plural(mrtstat
.mrts_no_route
));
206 printf(" %10lu datagram%s arrived with bad tunneling\n",
207 mrtstat
.mrts_bad_tunnel
, plural(mrtstat
.mrts_bad_tunnel
));
208 printf(" %10lu datagram%s could not be tunneled\n",
209 mrtstat
.mrts_cant_tunnel
, plural(mrtstat
.mrts_cant_tunnel
));
210 printf(" %10lu datagram%s arrived on wrong interface\n",
211 mrtstat
.mrts_wrong_if
, plural(mrtstat
.mrts_wrong_if
));
212 printf(" %10lu datagram%s selectively dropped\n",
213 mrtstat
.mrts_drop_sel
, plural(mrtstat
.mrts_drop_sel
));
214 printf(" %10lu datagram%s dropped due to queue overflow\n",
215 mrtstat
.mrts_q_overflow
, plural(mrtstat
.mrts_q_overflow
));
216 printf(" %10lu datagram%s dropped for being too large\n",
217 mrtstat
.mrts_pkt2large
, plural(mrtstat
.mrts_pkt2large
));