summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2016-02-25 14:07:10 -0500
committerJoel Fischer <joeljfischer@gmail.com>2016-02-25 14:07:10 -0500
commit12741520edbe2877a59c4ab4520dbaa53897929d (patch)
tree859f5d498c539bff250523e67fc13940081f9631
parentca00a9d0dabf997e2f1866489146bb5afce3c0c2 (diff)
parentdbe8d8da4aa319b2d62d1eecbb0794d072066d0c (diff)
downloadsdl_ios-12741520edbe2877a59c4ab4520dbaa53897929d.tar.gz
Merge branch 'pr/357'
-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));