[PC-BSD Commits] r2069 - pcbsd/trunk/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Mon Jun 9 10:56:52 PDT 2008


Author: tim
Date: 2008-06-09 10:56:52 -0700 (Mon, 09 Jun 2008)
New Revision: 2069

Modified:
   pcbsd/trunk/libpcbsd/netif.cpp
Log:
Implemented packetsTx and Rx, and errorsTx and Rx

Modified: pcbsd/trunk/libpcbsd/netif.cpp
===================================================================
--- pcbsd/trunk/libpcbsd/netif.cpp	2008-06-09 15:59:28 UTC (rev 2068)
+++ pcbsd/trunk/libpcbsd/netif.cpp	2008-06-09 17:56:52 UTC (rev 2069)
@@ -175,3 +175,99 @@
 
    return (ifr.ifr_flags & IFF_UP) ? 1 : 0;
 }
+
+long NetworkInterface::packetsRx()
+{
+   int mib[6];
+   size_t len;
+   char *buf;
+   struct if_msghdr *ifm;
+
+   mib[0] = CTL_NET;
+   mib[1] = AF_ROUTE;
+   mib[2] = 0;
+   mib[3] = AF_LINK;
+   mib[4] = NET_RT_IFLIST;
+   mib[5] = if_nametoindex(name);
+
+   //First find the size of the return, so we can adjust buf accordingly
+   sysctl(mib, 6, NULL, &len, NULL, 0);
+   buf = (char *) malloc(len);
+   sysctl(mib, 6, buf, &len, NULL, 0);
+
+   ifm = (if_msghdr *) buf;
+
+   return ifm->ifm_data.ifi_ipackets;
+}
+
+long NetworkInterface::packetsTx()
+{
+   int mib[6];
+   size_t len;
+   char *buf;
+   struct if_msghdr *ifm;
+
+   mib[0] = CTL_NET;
+   mib[1] = AF_ROUTE;
+   mib[2] = 0;
+   mib[3] = AF_LINK;
+   mib[4] = NET_RT_IFLIST;
+   mib[5] = if_nametoindex(name);
+
+   //First find the size of the return, so we can adjust buf accordingly
+   sysctl(mib, 6, NULL, &len, NULL, 0);
+   buf = (char *) malloc(len);
+   sysctl(mib, 6, buf, &len, NULL, 0);
+
+   ifm = (if_msghdr *) buf;
+
+   return ifm->ifm_data.ifi_opackets;
+}
+
+long NetworkInterface::errorsRx()
+{
+   int mib[6];
+   size_t len;
+   char *buf;
+   struct if_msghdr *ifm;
+
+   mib[0] = CTL_NET;
+   mib[1] = AF_ROUTE;
+   mib[2] = 0;
+   mib[3] = AF_LINK;
+   mib[4] = NET_RT_IFLIST;
+   mib[5] = if_nametoindex(name);
+
+   //First find the size of the return, so we can adjust buf accordingly
+   sysctl(mib, 6, NULL, &len, NULL, 0);
+   buf = (char *) malloc(len);
+   sysctl(mib, 6, buf, &len, NULL, 0);
+
+   ifm = (if_msghdr *) buf;
+
+   return ifm->ifm_data.ifi_ierrors;
+}
+
+long NetworkInterface::errorsTx()
+{
+   int mib[6];
+   size_t len;
+   char *buf;
+   struct if_msghdr *ifm;
+
+   mib[0] = CTL_NET;
+   mib[1] = AF_ROUTE;
+   mib[2] = 0;
+   mib[3] = AF_LINK;
+   mib[4] = NET_RT_IFLIST;
+   mib[5] = if_nametoindex(name);
+
+   //First find the size of the return, so we can adjust buf accordingly
+   sysctl(mib, 6, NULL, &len, NULL, 0);
+   buf = (char *) malloc(len);
+   sysctl(mib, 6, buf, &len, NULL, 0);
+
+   ifm = (if_msghdr *) buf;
+
+   return ifm->ifm_data.ifi_oerrors;
+}



More information about the Commits mailing list