[haiku-commits] r38182 - haiku/trunk/src/apps/activitymonitor

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 17 Aug 2010 13:57:01 +0200 (CEST)

Author: axeld
Date: 2010-08-17 13:57:01 +0200 (Tue, 17 Aug 2010)
New Revision: 38182
Changeset: http://dev.haiku-os.org/changeset/38182
Ticket: http://dev.haiku-os.org/ticket/6457

Modified:
   haiku/trunk/src/apps/activitymonitor/Jamfile
   haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp
Log:
* The ActivityMonitor now uses the new network C++ API to retrieve the
  interface stats. This fixes bug #6457.


Modified: haiku/trunk/src/apps/activitymonitor/Jamfile
===================================================================
--- haiku/trunk/src/apps/activitymonitor/Jamfile        2010-08-17 11:45:56 UTC 
(rev 38181)
+++ haiku/trunk/src/apps/activitymonitor/Jamfile        2010-08-17 11:57:01 UTC 
(rev 38182)
@@ -1,8 +1,5 @@
 SubDir HAIKU_TOP src apps activitymonitor ;
 
-# XXX: Temporary only
-SetSubDirSupportedPlatformsBeOSCompatible ;
-
 UsePrivateHeaders shared system ;
 
 Application ActivityMonitor :
@@ -14,6 +11,6 @@
        SystemInfo.cpp
        SystemInfoHandler.cpp
 
-       : be tracker media $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS)
+       : be tracker media libbnetapi.so $(TARGET_LIBSTDC++) 
$(TARGET_NETWORK_LIBS)
        : ActivityMonitor.rdef
        ;

Modified: haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp
===================================================================
--- haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp 2010-08-17 11:45:56 UTC 
(rev 38181)
+++ haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp 2010-08-17 11:57:01 UTC 
(rev 38182)
@@ -1,20 +1,17 @@
 /*
- * Copyright 2008, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
+ * Copyright 2008-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 
 
 #include "SystemInfo.h"
-#include "SystemInfoHandler.h"
 
-#include <net/if.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <unistd.h>
+#include <NetworkInterface.h>
+#include <NetworkRoster.h>
 
+#include "SystemInfoHandler.h"
 
+
 SystemInfo::SystemInfo(SystemInfoHandler* handler)
        :
        fTime(system_time()),
@@ -158,55 +155,17 @@
        fBytesSent = 0;
        fRetrievedNetwork = true;
 
-       // we need a socket to talk to the networking stack
-       int socket = ::socket(AF_INET, SOCK_DGRAM, 0);
-       if (socket < 0)
-               return;
+       BNetworkRoster& roster = BNetworkRoster::Default();
 
-       // get a list of all interfaces
-
-       ifconf config;
-       config.ifc_len = sizeof(config.ifc_value);
-       if (ioctl(socket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0
-               || config.ifc_value == 0) {
-               close(socket);
-               return;
-       }
-
-       uint32 count = (uint32)config.ifc_value;
-
-       void *buffer = malloc(count * sizeof(struct ifreq));
-       if (buffer == NULL) {
-               close(socket);
-               return;
-       }
-
-       config.ifc_len = count * sizeof(struct ifreq);
-       config.ifc_buf = buffer;
-       if (ioctl(socket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0) {
-               close(socket);
-               return;
-       }
-
-       ifreq *interface = (ifreq *)buffer;
-
-       for (uint32 i = 0; i < count; i++) {
-               ifreq request;
-               strlcpy(request.ifr_name, interface->ifr_name, IF_NAMESIZE);
-
-#ifdef __HAIKU__
-               if (ioctl(socket, SIOCGIFSTATS, &request, sizeof(struct ifreq)) 
== 0) {
-                       fBytesReceived += request.ifr_stats.receive.bytes;
-                       fBytesSent += request.ifr_stats.send.bytes;
+       BNetworkInterface interface;
+       uint32 cookie = 0;
+       while (roster.GetNextInterface(&cookie, interface) == B_OK) {
+               ifreq_stats stats;
+               if (interface.GetStats(stats) == B_OK) {
+                       fBytesReceived += stats.receive.bytes;
+                       fBytesSent += stats.send.bytes;
                }
-#endif
-
-               interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
-                       + interface->ifr_addr.sa_len);
        }
-
-       free(buffer);
-       close(socket);
 }
 
 


Other related posts:

  • » [haiku-commits] r38182 - haiku/trunk/src/apps/activitymonitor - axeld