summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuller, Alexander (A.) <amulle19@ford.com>2016-02-18 14:14:23 -0800
committerMuller, Alexander (A.) <amulle19@ford.com>2016-02-18 14:14:23 -0800
commitdbe8d8da4aa319b2d62d1eecbb0794d072066d0c (patch)
treed4e93a59f16867afdf9779538559bdab4a74867d
parent14d5fb93d60372936953bc67a0a5727e1a12fcfc (diff)
downloadsdl_ios-dbe8d8da4aa319b2d62d1eecbb0794d072066d0c.tar.gz
Added ability for SDLTCPTransport to check hostname before we attempt to connect, and correctly errors out if the hostname is invalid/unreachable.
-rw-r--r--SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m11
1 files changed, 10 insertions, 1 deletions
diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m
index 9a2501a1e..b80bf93dd 100644
--- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m
+++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m
@@ -14,6 +14,7 @@
#import <sys/wait.h>
#import <netinet/in.h>
#import <netdb.h>
+#import <SystemConfiguration/SystemConfiguration.h>
// C function forward declarations.
@@ -127,7 +128,15 @@ int call_socket(const char *hostname, const char *port) {
gethostname(localhost, sizeof localhost);
hostname = (const char *)&localhost;
}
-
+
+ // check if hostname address is valid before we attempt to connect.
+ SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)hostname);
+ if (reachability == NULL) {
+ return (-1);
+ } else {
+ CFRelease(reachability);
+ }
+
//getaddrinfo setup
if ((status = getaddrinfo(hostname, port, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));