Skip to content

Commit

Permalink
Connection works with domain names as well as IP addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Lejdborg committed Feb 9, 2012
1 parent 228e3ce commit d0740b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion NMSSH.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
*/

#import "NMSSH.h"
#import "NMHostHelper.h"

#import "libssh2.h"
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>

Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion todo.txt

This file was deleted.

0 comments on commit d0740b6

Please sign in to comment.