Menu

#3 fixes monitor crash when hostnames are not qualified

open
nobody
None
5
2008-11-19
2008-11-19
Anonymous
No

This change stops monitor from crashing when hostnames do not have '.' in them:

replace code under "case 'H':" in monitor.cc with this:

case 'H': {
std::string ipstr;
int state;
/* Read in ': <ip-address> <state>' */
instr.ignore(); // eat ':'
instr >> ipstr >> state;
std::string hostname = ipstr;

unsigned int addr = inet_addr(ipstr.c_str());
struct hostent *he = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
if (he)
{
/* Remove everything from the first . onward -- so we don't see
the long domain name in the output. */

hostname = he->h_name;
size_t pos = hostname.find_first_of('.');
if (pos != std::string::npos)
hostname.erase(pos);
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.