From 0e03940802cebefdf6b0597a154bd9395e1af4d2 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 18 Jun 2014 15:45:45 +0200 Subject: Add the vanilla version of the project This version can still be found here: http://www.roland-riegel.de/nload/index.html --- src/devreader-solaris.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/devreader-solaris.cpp (limited to 'src/devreader-solaris.cpp') diff --git a/src/devreader-solaris.cpp b/src/devreader-solaris.cpp new file mode 100644 index 0000000..478b3ca --- /dev/null +++ b/src/devreader-solaris.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +/*************************************************************************** + * Solaris specific network code taken out of gkrellm * + * Copyright by Bill Wilson * + * Solaris code by Daisuke Yabuki * + * adapted for nload by Roland Riegel * + ***************************************************************************/ + +#include "devreader-solaris.h" + +#include +#include +#include +#include + +#include +#include + +using namespace std; + +DevReaderSolaris::DevReaderSolaris(const string& deviceName) + : DevReader(deviceName) +{ +} + +DevReaderSolaris::~DevReaderSolaris() +{ +} + +list DevReaderSolaris::findAllDevices() +{ + list interfaceNames; + struct if_nameindex* interfaces = if_nameindex(); + + if(!interfaces) + return interfaceNames; + + int i = 0; + while(interfaces[i].if_name) + { + interfaceNames.push_back(string(interfaces[i].if_name)); + ++i; + } + + if_freenameindex(interfaces); + + return interfaceNames; +} + +void DevReaderSolaris::readFromDevice(DataFrame& dataFrame) +{ + kstat_ctl_t *kc; + kstat_t *ksp; + kstat_named_t *knp; + char* devName = 0; + + if(m_deviceName.empty()) + return; + + devName = (char*) malloc(m_deviceName.length() + 1); + strncpy(devName, m_deviceName.c_str(), m_deviceName.length()); + devName[m_deviceName.length()] = '\0'; + + kc = kstat_open(); + ksp = kstat_lookup(kc, NULL, -1, devName); + if(ksp && kstat_read(kc, ksp, NULL) >= 0) + { + knp = (kstat_named_t *) kstat_data_lookup(ksp, "rbytes"); + dataFrame.setTotalDataIn(knp ? knp->value.ui32 : 0); + + knp = (kstat_named_t *) kstat_data_lookup(ksp, "obytes"); + dataFrame.setTotalDataOut(knp ? knp->value.ui32 : 0); + + knp = (kstat_named_t *) kstat_data_lookup(ksp, "ipackets"); + dataFrame.setTotalPacketsIn(knp ? knp->value.ui32 : 0); + + knp = (kstat_named_t *) kstat_data_lookup(ksp, "opackets"); + dataFrame.setTotalPacketsOut(knp ? knp->value.ui32 : 0); + + knp = (kstat_named_t *) kstat_data_lookup(ksp, "ierrors"); + dataFrame.setTotalErrorsIn(knp ? knp->value.ui32 : 0); + + knp = (kstat_named_t *) kstat_data_lookup(ksp, "oerrors"); + dataFrame.setTotalErrorsOut(knp ? knp->value.ui32 : 0); + + dataFrame.setValid(true); + } + + kstat_close(kc); + free(devName); + devName = 0; +} + -- cgit v1.2.3