Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve and IP Address from a Host Name on iOS

I need to resolve an IP address from a hostname in iOS. I know this is trivial using NSHost, however NSHost resolution capability seems to only work on OSX.

Thanks in advance.

like image 787
Slappy Avatar asked Dec 08 '22 22:12

Slappy


1 Answers

Like this:

struct hostent *host_entry = gethostbyname("stackoverflow.com");
char *buff;
buff = inet_ntoa(*((struct in_addr *)host_entry->h_addr_list[0]));

buff variable now contain an ip address...

like image 178
Tutankhamen Avatar answered Dec 28 '22 15:12

Tutankhamen