diff --git a/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate b/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate index 711b07564860..37b6d9677f57 100644 Binary files a/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate and b/ios/iosremote/iosremote.xcodeproj/project.xcworkspace/xcuserdata/siqi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ios/iosremote/iosremote/Communication/Server.h b/ios/iosremote/iosremote/Communication/Server.h index 0fb6c9df0c74..0e499bd96102 100644 --- a/ios/iosremote/iosremote/Communication/Server.h +++ b/ios/iosremote/iosremote/Communication/Server.h @@ -21,3 +21,9 @@ typedef enum protocol {NETWORK} Protocol_t; ofName:(NSString*) name; @end + +@interface NSString (IPValidation) + +- (BOOL)isValidIPAddress; + +@end \ No newline at end of file diff --git a/ios/iosremote/iosremote/Communication/Server.m b/ios/iosremote/iosremote/Communication/Server.m index 71547c77108e..2e2c0a403b8b 100644 --- a/ios/iosremote/iosremote/Communication/Server.m +++ b/ios/iosremote/iosremote/Communication/Server.m @@ -7,13 +7,12 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #import "Server.h" +#import @interface Server() @end - - @implementation Server @@ -54,3 +53,23 @@ } @end + + +@implementation NSString (IPValidation) + +- (BOOL)isValidIPAddress +{ + const char *utf8 = [self UTF8String]; + int success; + + struct in_addr dst; + success = inet_pton(AF_INET, utf8, &dst); + if (success != 1) { + struct in6_addr dst6; + success = inet_pton(AF_INET6, utf8, &dst6); + } + + return success; +} + +@end diff --git a/ios/iosremote/iosremote/newServer_vc.m b/ios/iosremote/iosremote/newServer_vc.m index 22ed5a26317d..9681638ebc22 100644 --- a/ios/iosremote/iosremote/newServer_vc.m +++ b/ios/iosremote/iosremote/newServer_vc.m @@ -22,12 +22,20 @@ - (IBAction)save:(id)sender { NSString *serverName = [self.nameCell.textField text]; NSString *serverAddr = [self.addrCell.textField text]; - if (!serverName) { - serverName = @"Computer"; + if ([serverAddr isValidIPAddress]) { + if (!serverName) + serverName = @"Computer"; + NSLog(@"New server name:%@ ip:%@", serverName, serverAddr); + [self.comManager addServersWithName:serverName AtAddress:serverAddr]; + [self.navigationController popViewControllerAnimated:YES]; + } else { + UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Invalid IP Address" + message:@"A valid IP address should be like this: \"192.168.1.1\"" + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil]; + [message show]; } - NSLog(@"New server name:%@ ip:%@", serverName, serverAddr); - [self.comManager addServersWithName:serverName AtAddress:serverAddr]; - [self.navigationController popViewControllerAnimated:YES]; } - (BOOL)isModal