Skip to content

Instantly share code, notes, and snippets.

@blankyao
Last active December 10, 2015 20:58
Show Gist options
  • Save blankyao/4491470 to your computer and use it in GitHub Desktop.
Save blankyao/4491470 to your computer and use it in GitHub Desktop.
get ip address by hostname from iOS
struct hostent *host = gethostbyname(@"localhost".UTF8String);
char addr[32];
inet_ntop(host->h_addrtype, host->h_addr, addr, sizeof(addr));
NSString *result=[[NSString alloc] initWithUTF8String:addr];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment