From d0740b66b394b3b421549736343ed6d2424acad5 Mon Sep 17 00:00:00 2001 From: Lejdborg Date: Thu, 9 Feb 2012 15:33:52 +0100 Subject: [PATCH] Connection works with domain names as well as IP addresses --- NMSSH.m | 7 ++++++- README.md | 2 ++ todo.txt | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) delete mode 100644 todo.txt diff --git a/NMSSH.m b/NMSSH.m index a84696d..624fe31 100644 --- a/NMSSH.m +++ b/NMSSH.m @@ -29,8 +29,10 @@ */ #import "NMSSH.h" +#import "NMHostHelper.h" #import "libssh2.h" +#include #include #include @@ -122,7 +124,10 @@ - (id)initWithHost:(NSString *)host username:(NSString *)username password:(NSSt // ----------------------------------------------------------------------------- - (BOOL)connect:(NSError **)error { - hostaddr = inet_addr([_host cStringUsingEncoding:NSUTF8StringEncoding]); + // Determine host address + NSString *host = [NMHostHelper isIp:_host] ? _host : [NMHostHelper ipFromDomainName:_host]; + + hostaddr = inet_addr([host cStringUsingEncoding:NSUTF8StringEncoding]); sock = socket(AF_INET, SOCK_STREAM, 0); soin.sin_family = AF_INET; soin.sin_port = htons([_port intValue]); diff --git a/README.md b/README.md index d078b85..48c4213 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ Drag and drop the project directory and all it's files in to your Xcode project. #include "NMSSH.h" +NMSSH depends on [NMHostHelper](https://github.com/Lejdborg/NMHostHelper). + ## Connect to a server NSError *error; diff --git a/todo.txt b/todo.txt deleted file mode 100644 index 96b2534..0000000 --- a/todo.txt +++ /dev/null @@ -1 +0,0 @@ -- Add support for string hostnames, such as "mydomain.com" \ No newline at end of file