Created
September 25, 2018 08:39
-
-
Save icyleaf/c52c1675f4e4116ee2810e9fa175cde8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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