Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#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
You can’t perform that action at this time.