diff --git a/checkin_notes b/checkin_notes index 124714f8c7..e0ec092fe1 100644 --- a/checkin_notes +++ b/checkin_notes @@ -1352,3 +1352,11 @@ David 20 Feb 2010 sample_project.inc inc/ util_ops.inc + +Rom 23 Feb 2010 + - client: Add a function to the client software to be able to detect + the number of bytes sent and received across all non-loopback + interfaces. + + client/ + hostinfo_win.cpp diff --git a/client/hostinfo_win.cpp b/client/hostinfo_win.cpp index aba2a02fca..e9e9cc1d2b 100644 --- a/client/hostinfo_win.cpp +++ b/client/hostinfo_win.cpp @@ -32,6 +32,7 @@ #include "str_util.h" #include "str_replace.h" #include "client_msgs.h" +#include "error_numbers.h" #include "hostinfo_network.h" #include "hostinfo.h" #include "idlemon.h" @@ -862,6 +863,57 @@ int get_processor_info( } +// detect the network usage totals for the host. +// +int get_network_usage_totals(unsigned int& total_received, unsigned int& total_sent) { + + // Declare and initialize variables. + int i; + int iRetVal = 0; + DWORD dwSize = 0; + MIB_IFTABLE* pIfTable; + MIB_IFROW* pIfRow; + + // Allocate memory for our pointers. + pIfTable = (MIB_IFTABLE*)malloc(sizeof(MIB_IFTABLE)); + if (pIfTable == NULL) { + return ERR_MALLOC; + } + + // Make an initial call to GetIfTable to get the + // necessary size into dwSize + dwSize = sizeof(MIB_IFTABLE); + if (GetIfTable(pIfTable, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER) { + free(pIfTable); + pIfTable = (MIB_IFTABLE*)malloc(dwSize); + if (pIfTable == NULL) { + return ERR_MALLOC; + } + } + + // Make a second call to GetIfTable to get the actual + // data we want. + iRetVal = (int)GetIfTable(pIfTable, &dwSize, FALSE); + if (iRetVal == NO_ERROR) { + for (i = 0; i < (int)pIfTable->dwNumEntries; i++) { + pIfRow = (MIB_IFROW *) & pIfTable->table[i]; + if (IF_TYPE_SOFTWARE_LOOPBACK != pIfRow->dwType) { + total_received += pIfRow->dwInOctets; + total_sent += pIfRow->dwOutOctets; + } + } + } + + if (pIfTable != NULL) { + free(pIfTable); + pIfTable = NULL; + } + + return iRetVal; + +} + + // Gets host information; called on startup and before each sched RPC // int HOST_INFO::get_host_info() { diff --git a/lib/boinc_win.h b/lib/boinc_win.h index 6d020669ed..2539f5a54e 100644 --- a/lib/boinc_win.h +++ b/lib/boinc_win.h @@ -60,6 +60,7 @@ #include #include #include +#include #if !defined(__CYGWIN32__) || defined(USE_WINSOCK) diff --git a/win_build/boinc_cli.vcproj b/win_build/boinc_cli.vcproj index 7476f2e0d7..0787fa9ea1 100644 --- a/win_build/boinc_cli.vcproj +++ b/win_build/boinc_cli.vcproj @@ -409,7 +409,7 @@ />