X-Git-Url: https://git.saurik.com/apple/network_cmds.git/blobdiff_plain/ac2f15b3eadabcc5cceb4bb7f642395e9616a902..2b484d24084b903459c5b416c06cd77b48c748b9:/netstat.tproj/mroute.c diff --git a/netstat.tproj/mroute.c b/netstat.tproj/mroute.c index 4c94d2b..b620589 100644 --- a/netstat.tproj/mroute.c +++ b/netstat.tproj/mroute.c @@ -3,22 +3,21 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." * * @APPLE_LICENSE_HEADER_END@ */ @@ -71,9 +70,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -86,11 +85,9 @@ #include "netstat.h" void -mroutepr(mfcaddr, vifaddr) - u_long mfcaddr, vifaddr; +mroutepr(void) { - u_int mrtproto; - struct mfc *mfctable[MFCTBLSIZ]; + struct mfc **mfctable = 0; struct vif viftable[MAXVIFS]; struct mfc mfc, *m; register struct vif *v; @@ -99,16 +96,17 @@ mroutepr(mfcaddr, vifaddr) register int banner_printed; register int saved_nflag; vifi_t maxvif = 0; + size_t len; + + saved_nflag = nflag; + nflag = 1; - if (mfcaddr == 0 || vifaddr == 0) { + len = MAXVIFS * sizeof(struct vif); + if (sysctlbyname("net.inet.ip.viftable", viftable, &len, 0, 0) == -1) { printf("No IPv4 multicast routing compiled into this system.\n"); return; } - saved_nflag = nflag; - nflag = 1; - - kread(vifaddr, (char *)&viftable, sizeof(viftable)); banner_printed = 0; for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { if (v->v_lcl_addr.s_addr == 0) @@ -134,13 +132,21 @@ mroutepr(mfcaddr, vifaddr) if (!banner_printed) printf("\nVirtual Interface Table is empty\n"); - kread(mfcaddr, (char *)&mfctable, sizeof(mfctable)); + if (sysctlbyname("net.inet.ip.mfctable", 0, &len, 0, 0) == -1) { + printf("No IPv4 multicast routing compiled into this system.\n"); + return; + } + mfctable = malloc(len); + if (mfctable == 0) + return; + if (sysctlbyname("net.inet.ip.mfctable", mfctable, &len, 0, 0) == -1) { + printf("No IPv4 multicast routing compiled into this system.\n"); + return; + } banner_printed = 0; for (i = 0; i < MFCTBLSIZ; ++i) { m = mfctable[i]; while(m) { - kread((u_long)m, (char *)&mfc, sizeof mfc); - if (!banner_printed) { printf("\nIPv4 Multicast Forwarding Cache\n" " Origin Group " @@ -166,21 +172,22 @@ mroutepr(mfcaddr, vifaddr) printf("\n"); nflag = saved_nflag; + + free(mfctable); } void -mrt_stats(mstaddr) - u_long mstaddr; +mrt_stats() { struct mrtstat mrtstat; + size_t len = sizeof(struct mrtstat); - if (mstaddr == 0) { + if(sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, 0, 0) == -1) { printf("No IPv4 multicast routing compiled into this system.\n"); return; } - kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); printf("IPv4 multicast forwarding:\n"); printf(" %10lu multicast forwarding cache lookup%s\n", mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups));