Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned int ipQuads[4];
- const char *ipAddress = [ipAddressStr cStringUsingEncoding:NSUTF8StringEncoding];
- sscanf(ipAddress, "%u.%u.%u.%u", &ipQuads[0], &ipQuads[1], &ipQuads[2], &ipQuads[3]);
- @try {
- for (int quad = 0; quad < 4; quad++) {
- if ((ipQuads[quad] < 0) || (ipQuads[quad] > 255)) {
- NSException *ipException = [NSException
- exceptionWithName:@"IPNotFormattedCorrectly"
- reason:@"IP range is invalid"
- userInfo:nil];
- @throw ipException;
- }
- }
- }
- @catch (NSException *exc) {
- NSLog(@"ERROR: %@", [exc reason]);
- }
- #include <arpa/inet.h>
- - (BOOL)isIp:(NSString*)string{
- struct in_addr pin;
- int success = inet_aton([string UTF8String],&pin);
- if (success == 1) return TRUE;
- return FALSE;
- }
Add Comment
Please, Sign In to add comment