Jun 9, 2009

Write code to verify if an IP address taken as an input string is valid or not.

Write code to verify if an IP address taken as an input string is valid or not.
bool check_ip(char * IP)
{
//char IP[16] = "255.255.255.255";
if(strlen(IP) > 16)
return false;
char * range = strtok(IP, ".");
short c = 0;
while ((range != NULL) && (c < 4)) {
if((atoi(const_castrange) >= 0) && (atoi(const_castrange) <= 255))
++c;
else break;

range = strtok(NULL, ".");
}
return (c == 4);
}

No comments:

Post a Comment