* 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
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
SubDir HAIKU_TOP src apps activitymonitor ;
|
SubDir HAIKU_TOP src apps activitymonitor ;
|
||||||
|
|
||||||
# XXX: Temporary only
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
|
||||||
|
|
||||||
UsePrivateHeaders shared system ;
|
UsePrivateHeaders shared system ;
|
||||||
|
|
||||||
Application ActivityMonitor :
|
Application ActivityMonitor :
|
||||||
@@ -14,6 +11,6 @@ Application ActivityMonitor :
|
|||||||
SystemInfo.cpp
|
SystemInfo.cpp
|
||||||
SystemInfoHandler.cpp
|
SystemInfoHandler.cpp
|
||||||
|
|
||||||
: be tracker media $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS)
|
: be tracker media libbnetapi.so $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS)
|
||||||
: ActivityMonitor.rdef
|
: ActivityMonitor.rdef
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2008-2010, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "SystemInfo.h"
|
#include "SystemInfo.h"
|
||||||
#include "SystemInfoHandler.h"
|
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <NetworkInterface.h>
|
||||||
#include <stdlib.h>
|
#include <NetworkRoster.h>
|
||||||
#include <string.h>
|
|
||||||
#include <sys/socket.h>
|
#include "SystemInfoHandler.h"
|
||||||
#include <sys/sockio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
|
|
||||||
SystemInfo::SystemInfo(SystemInfoHandler* handler)
|
SystemInfo::SystemInfo(SystemInfoHandler* handler)
|
||||||
@@ -158,55 +155,17 @@ SystemInfo::_RetrieveNetwork()
|
|||||||
fBytesSent = 0;
|
fBytesSent = 0;
|
||||||
fRetrievedNetwork = true;
|
fRetrievedNetwork = true;
|
||||||
|
|
||||||
// we need a socket to talk to the networking stack
|
BNetworkRoster& roster = BNetworkRoster::Default();
|
||||||
int socket = ::socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
if (socket < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// get a list of all interfaces
|
BNetworkInterface interface;
|
||||||
|
uint32 cookie = 0;
|
||||||
ifconf config;
|
while (roster.GetNextInterface(&cookie, interface) == B_OK) {
|
||||||
config.ifc_len = sizeof(config.ifc_value);
|
ifreq_stats stats;
|
||||||
if (ioctl(socket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0
|
if (interface.GetStats(stats) == B_OK) {
|
||||||
|| config.ifc_value == 0) {
|
fBytesReceived += stats.receive.bytes;
|
||||||
close(socket);
|
fBytesSent += stats.send.bytes;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
|
|
||||||
+ interface->ifr_addr.sa_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
close(socket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user