I don\'t need to validate that the IP address is reachable or anything like that. I just want to validate that the string is in dotted-quad (xxx.xxx.xxx.xxx) IPv4 format, w
vector &split(const string &s, char delim, vector &elems) {
stringstream ss(s);
string item;
while(getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
vector split(const string &s, char delim) {
vector elems;
return split(s, delim, elems);
}
bool isIPAddress(string ipaddr){
if (ipaddr.length()){
vector _ip=split(ipaddr,'.');
if (_ip.size()==4){
for (int i=0; i < 4; i++){
for (int j=0; j < _ip[i].length(); j++)
if (!isdigit(_ip[i][j])) return false;
if ((atoi(_ip[i].c_str()) < 0) || (atoi(_ip[i].c_str()) > 255)) return false;
}
return true;
}
}
return false;
}