]> git.saurik.com Git - apple/network_cmds.git/blobdiff - netstat.tproj/mbuf.c
network_cmds-245.tar.gz
[apple/network_cmds.git] / netstat.tproj / mbuf.c
index 260f6aa1502e43d60c03522d7e06e6fcc45bccc5..66e96feea9526d0eab1e884d97b654a7dbc6a3af 100644 (file)
@@ -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@
  */
@@ -57,9 +56,9 @@
 
 
 #include <sys/param.h>
-#include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/mbuf.h>
+#include <sys/sysctl.h>
 
 #include <stdio.h>
 #include "netstat.h"
@@ -106,23 +105,20 @@ bool seen[256];                   /* "have we seen this type yet?" */
  * Print mbuf statistics.
  */
 void
-mbpr(mbaddr)
-       u_long mbaddr;
+mbpr(void)
 {
-       register int totmem, totfree, totmbufs;
-       register int i;
-       register struct mbtypes *mp;
+       int totmem, totfree, totmbufs;
+       int i;
+       struct mbtypes *mp;
+       size_t len;
 
        if (nmbtypes != 256) {
                fprintf(stderr,
                    "netstat: unexpected change to mbstat; check source\n");
                return;
        }
-       if (mbaddr == 0) {
-               fprintf(stderr, "netstat: mbstat: symbol not in namelist\n");
-               return;
-       }
-       if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat)))
+       len = sizeof(mbstat);
+       if (sysctlbyname("kern.ipc.mbstat", &mbstat, &len, 0, 0) == -1)
                return;
 
        totmbufs = 0;
@@ -144,8 +140,11 @@ mbpr(mbaddr)
        printf("%u/%u mbuf clusters in use\n",
               (unsigned int)(mbstat.m_clusters - mbstat.m_clfree),
               (unsigned int)mbstat.m_clusters);
-       totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES;
-       totfree = mbstat.m_clfree * MCLBYTES;
+       printf("%u/%u mbuf 4KB clusters in use\n",
+              (unsigned int)(mbstat.m_bigclusters - mbstat.m_bigclfree),
+              (unsigned int)mbstat.m_bigclusters);
+       totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES + mbstat.m_bigclusters * mbstat.m_bigmclbytes;
+       totfree = mbstat.m_clfree * MCLBYTES + mbstat.m_bigclfree * mbstat.m_bigmclbytes;
        printf("%u Kbytes allocated to network (%d%% in use)\n",
                totmem / 1024, (totmem - totfree) * 100 / totmem);
        printf("%u requests for memory denied\n",