fixes monitor crash when hostnames are not qualified
Status: Alpha
Brought to you by:
vic_norman
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);
}