Last active
October 1, 2018 13:09
-
-
Save ziggi/72bed27353ed037cdc45 to your computer and use it in GitHub Desktop.
Return 1 if string is ip address else 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if !defined IS_IN_RANGE | |
#define IS_IN_RANGE(%0,%1,%2) (((%0) - ((%1) + cellmin)) < (((%2) + 1) - ((%1) + cellmin))) | |
#endif | |
stock IsIpAddress(const string[]) | |
{ | |
new | |
octet, | |
j = 100; | |
for (new i = 0; string[i] != '\0'; i++) { | |
if (j != 0 && IS_IN_RANGE(string[i], '0', '9')) { | |
octet += (string[i] - '0') * j; | |
j /= 10; | |
} else if (string[i] == '.') { | |
if (IS_IN_RANGE(octet, 0, 255)) { | |
j = 100; | |
octet = 0; | |
} else { | |
return 0; | |
} | |
} else { | |
return 0; | |
} | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment