Guest User

Untitled

a guest
Apr 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. unsigned int ipQuads[4];
  2. const char *ipAddress = [ipAddressStr cStringUsingEncoding:NSUTF8StringEncoding];
  3.  
  4. sscanf(ipAddress, "%u.%u.%u.%u", &ipQuads[0], &ipQuads[1], &ipQuads[2], &ipQuads[3]);
  5.  
  6. @try {
  7. for (int quad = 0; quad < 4; quad++) {
  8. if ((ipQuads[quad] < 0) || (ipQuads[quad] > 255)) {
  9. NSException *ipException = [NSException
  10. exceptionWithName:@"IPNotFormattedCorrectly"
  11. reason:@"IP range is invalid"
  12. userInfo:nil];
  13. @throw ipException;
  14. }
  15. }
  16. }
  17. @catch (NSException *exc) {
  18. NSLog(@"ERROR: %@", [exc reason]);
  19. }
  20.  
  21. #include <arpa/inet.h>
  22.  
  23. - (BOOL)isIp:(NSString*)string{
  24. struct in_addr pin;
  25. int success = inet_aton([string UTF8String],&pin);
  26. if (success == 1) return TRUE;
  27. return FALSE;
  28. }
Add Comment
Please, Sign In to add comment