#include #include #include #include #include #include #include #include #include #include #include #include "util.h" #include "gfanet.h" ///////////////////////////////////////////////////////////////////////////// #define _PROC_NET_DEV "/proc/net/dev" ///////////////////////////////////////////////////////////////////////////// int GetAvailableInterfaces(NETINTERFACE_LIST &nil) { static const std::string strRegExLine = "^\\s*([^:]+):\\s*([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)$"; static std::regex regl(strRegExLine, std::regex_constants::ECMAScript | std::regex_constants::optimize); std::string buf; int nCntItf = 0; if(ReadFile(_PROC_NET_DEV, buf) > 0) { std::string line; std::istringstream iss(buf); std::istream stm(iss.rdbuf()); while(std::getline(stm, line)) { std::smatch resl; if( line.size() > 0 && regex_search(line, resl, regl)) { if(resl.size() == 18) { NETINTERFACE ni; memset(&ni, 0, sizeof(ni)); resl[1].str().copy(ni.name, sizeof(ni.name) - 1); ni.stats.rx_bytes = std::stoul(resl[2].str()); ni.stats.rx_packets = std::stoul(resl[3].str()); ni.stats.rx_errors = std::stoul(resl[4].str()); ni.stats.rx_dropped = std::stoul(resl[5].str()); ni.stats.rx_fifo_errors = std::stoul(resl[6].str()); ni.stats.rx_frame_errors = std::stoul(resl[7].str()); ni.stats.rx_compressed = std::stoul(resl[8].str()); ni.stats.rx_multicast = std::stoul(resl[9].str()); ni.stats.tx_bytes = std::stoul(resl[10].str()); ni.stats.tx_packets = std::stoul(resl[11].str()); ni.stats.tx_errors = std::stoul(resl[12].str()); ni.stats.tx_dropped = std::stoul(resl[13].str()); ni.stats.tx_fifo_errors = std::stoul(resl[14].str()); ni.stats.tx_collisions = std::stoul(resl[15].str()); ni.stats.tx_carrier_errors = std::stoul(resl[16].str()); ni.stats.tx_compressed = std::stoul(resl[17].str()); nil.push_back(ni); nCntItf++; } } } } return nCntItf; }