From 01a2853032809459a8f1fb48758778aed2909833 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 21 Oct 2014 14:31:03 -0400 Subject: [PATCH] Display a dialog if DNS resolution fails --- Limelight/Utility/Utils.m | 2 +- .../ViewControllers/MainFrameViewController.m | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Limelight/Utility/Utils.m b/Limelight/Utility/Utils.m index f0302952..96d678a6 100644 --- a/Limelight/Utility/Utils.m +++ b/Limelight/Utility/Utils.m @@ -67,7 +67,7 @@ return addr; } else { NSLog(@"Failed to resolve host: %d", h_errno); - return -1; + return 0; } } } diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 06a234ab..6c1dd614 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -44,6 +44,11 @@ static StreamConfiguration* streamConfig; NSString* uniqueId = [CryptoManager getUniqueID]; NSData* cert = [CryptoManager readCertFromFile]; + if ([Utils resolveHost:_selectedHost.hostName] == 0) { + [self displayDnsFailedDialog]; + return; + } + HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.hostName uniqueId:uniqueId deviceName:@"roth" cert:cert]; PairManager* pMan = [[PairManager alloc] initWithManager:hMan andCert:cert callback:self]; @@ -73,6 +78,14 @@ static StreamConfiguration* streamConfig; }); } +- (void)displayDnsFailedDialog { + UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Network Error" + message:@"Failed to resolve host." + preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]]; + [self presentViewController:alert animated:YES completion:nil]; +} + - (void)StreamButton:(UIButton *)sender { NSLog(@"Stream Button Pressed!"); @@ -89,6 +102,10 @@ static StreamConfiguration* streamConfig; streamConfig = [[StreamConfiguration alloc] init]; streamConfig.host = _selectedHost.hostName; streamConfig.hostAddr = [Utils resolveHost:_selectedHost.hostName]; + if (streamConfig.hostAddr == 0) { + [self displayDnsFailedDialog]; + return; + } unsigned long selectedConf = [self.StreamConfigs selectedRowInComponent:0]; NSLog(@"selectedConf: %ld", selectedConf);