Brief description of class still missing. More...
#include <IpRouteWatch.h>
Public Member Functions | |
virtual bool | exec () |
IpRouteWatch (NetServer *server) | |
~IpRouteWatch () |
Brief description of class still missing.
Full description of class still missing
IpRouteWatch::IpRouteWatch | ( | NetServer * | server | ) |
Description of constructor still missing
References GpCoreTools::Timer::setInterval(), and TRACE.
{ TRACE; _server=server; setInterval(5000); loadHostNames(); }
bool IpRouteWatch::exec | ( | ) | [virtual] |
Performs action after timeout. If it returns true the timer is not single shot, i.e. deleted right after exec().
Implements GpCoreTools::Timer.
References TRACE.
{ TRACE; FILE * f=popen("/sbin/ip route list table 66", "r"); if(!f) { Log::write(0, "cannot execute /sbin/ip\n"); return true; } char * buf=new char[64]; int bufLen=64; char * ptr; std::map<std::string, std::string>::iterator it; std::string directHosts[_hostNames.size()]; int directHostCount=0; while(!feof(f)) { File::readLine(buf, bufLen, f, true); if(buf[0]!='\0') { ptr=strtok(buf, " \t"); if(ptr) { std::string ip=ptr; it=_hostNames.find(ip); if(it==_hostNames.end()) { Log::write(0, "host name not found for ip: %s\n", ip.data()); } else { ptr=strtok(0, " \t"); if(ptr) { if(strcmp(ptr, "dev")==0) { // Direct access, else this is 'via' directHosts[directHostCount]=it->second; directHostCount++; } } else { return parsingError(f, buf); } } } else { return parsingError(f, buf); } } } delete [] buf; fclose(f); showLeds(directHostCount); showLCD(directHostCount, directHosts); send(directHostCount, directHosts); return true; }