How to determine if a string contains a validate IP address in C
Any valid IP address consists of four numbers separated by three period (.) characters and each number ranges from 0-255 inclusive. An example IP address is “184.108.40.206″. The string function sscanf can be used to extract the four numbers and then validate each number for the range 0-255. Then use strcmp to further validate with reconstructed ip string.
The following function returns 0 if the IP address is invalid and 1 if valid.