From b250dfdf26390c0a005301017ff347ada66ac1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 17 Aug 2010 11:57:01 +0000 Subject: [PATCH] * The ActivityMonitor now uses the new network C++ API to retrieve the interface stats. This fixes bug #6457. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38182 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/activitymonitor/Jamfile | 5 +- src/apps/activitymonitor/SystemInfo.cpp | 67 +++++-------------------- 2 files changed, 14 insertions(+), 58 deletions(-) diff --git a/src/apps/activitymonitor/Jamfile b/src/apps/activitymonitor/Jamfile index c9e045e9cb..fb5ed5c056 100644 --- a/src/apps/activitymonitor/Jamfile +++ b/src/apps/activitymonitor/Jamfile @@ -1,8 +1,5 @@ SubDir HAIKU_TOP src apps activitymonitor ; -# XXX: Temporary only -SetSubDirSupportedPlatformsBeOSCompatible ; - UsePrivateHeaders shared system ; Application ActivityMonitor : @@ -14,6 +11,6 @@ Application ActivityMonitor : SystemInfo.cpp SystemInfoHandler.cpp - : be tracker media $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS) + : be tracker media libbnetapi.so $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS) : ActivityMonitor.rdef ; diff --git a/src/apps/activitymonitor/SystemInfo.cpp b/src/apps/activitymonitor/SystemInfo.cpp index 0f32ac3b6b..66c679b5d5 100644 --- a/src/apps/activitymonitor/SystemInfo.cpp +++ b/src/apps/activitymonitor/SystemInfo.cpp @@ -1,18 +1,15 @@ /* - * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ #include "SystemInfo.h" -#include "SystemInfoHandler.h" -#include -#include -#include -#include -#include -#include +#include +#include + +#include "SystemInfoHandler.h" SystemInfo::SystemInfo(SystemInfoHandler* handler) @@ -158,55 +155,17 @@ SystemInfo::_RetrieveNetwork() 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); }