1

Hi have many iPad in 2 differents local networks and I want to know programatically in Objective-C the local domain based in the IP address in each iPad. for example I have an iPad in local domain "project.local". In this domain we have many IP address as 192.168.12.50. The IOS device get automaticaly their ip address.

Now I want to get programmaticaly in objective-C the domain name "projet.local" knowing the ip address??

Franky
  • 902
  • 2
  • 11
  • 28

1 Answers1

2

Try this (similar to dreamlax's answer https://stackoverflow.com/a/3575383/1758762):

struct addrinfo *results = NULL;
char hostname[NI_MAXHOST] = {0};

if ( getaddrinfo("192.168.12.50", NULL, NULL, &results) != 0 )
    return;

for (struct addrinfo *r = results; r; r = r->ai_next)
{
    if (getnameinfo(r->ai_addr, r->ai_addrlen, hostname, sizeof hostname, NULL, 0 , 0) != 0)
        continue; // try next one
    else
    {
        NSLog (@"Found hostname: %s", hostname);
        break;
    }
}

freeaddrinfo(results);
Community
  • 1
  • 1
Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92