joining stream works

This commit is contained in:
Diego Waxemberg
2014-10-20 11:31:40 -04:00
parent f909371a90
commit 44a7494823
6 changed files with 57 additions and 21 deletions
+29
View File
@@ -8,6 +8,10 @@
#import "Computer.h"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
@implementation Computer
- (id) initWithHost:(NSNetService *)host {
@@ -19,4 +23,29 @@
return self;
}
- (int) resolveHost
{
struct hostent *hostent;
if (inet_addr([self.hostName UTF8String]) != INADDR_NONE)
{
// Already an IP address
return inet_addr([self.hostName UTF8String]);
}
else
{
hostent = gethostbyname([self.hostName UTF8String]);
if (hostent != NULL)
{
char* ipstr = inet_ntoa(*(struct in_addr*)hostent->h_addr_list[0]);
NSLog(@"Resolved %@ -> %s", self.hostName, ipstr);
return inet_addr(ipstr);
}
else
{
NSLog(@"Failed to resolve host: %d", h_errno);
return -1;
}
}
}
@end