Skip to content

Instantly share code, notes, and snippets.

@icyleaf
Created September 25, 2018 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icyleaf/c52c1675f4e4116ee2810e9fa175cde8 to your computer and use it in GitHub Desktop.
Save icyleaf/c52c1675f4e4116ee2810e9fa175cde8 to your computer and use it in GitHub Desktop.
#include <netdb.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
+ (NSArray *)loopUpIPAddress:(NSURL *)url {
NSMutableArray *ipAddrs = [[NSMutableArray alloc] init];
char **pptr;
struct hostent *_host = gethostbyname([[url host] UTF8String]);
pptr = _host->h_addr_list;
for (; *pptr != NULL; pptr++) {
char ip_addr[32];
inet_ntop(_host->h_addrtype, *pptr, ip_addr, sizeof(ip_addr));
NSString* hostIP = [NSString stringWithUTF8String:ip_addr];
[ipAddrs addObject:hostIP];
}
return [ipAddrs copy];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment