I can get the Domain Name easily using 'Environment.UserDomainName' in .NET, but how can I find it out on objective c? I'm developing a small cocoa application for Mac OS using Xcode 6.
My pc will be connected to an Organization's LAN, i need to know the domain name of the network i connected to. I have tried the below method utilising NSHost class to get the hostname when the IP is provided. I passed the IP of pc, but it returned the IP not the hostname with Domain.
-(void)GetHostName: (char*)DNSIP
{
int error;
struct addrinfo hints;
struct addrinfo *results = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_protocol = IPPROTO_TCP;
getaddrinfo(DNSIP, NULL, &hints, &results);
for (struct addrinfo *r = results; r; r = r->ai_next)
{
char hostname[NI_MAXHOST] = {0};
error = getnameinfo(r->ai_addr, r->ai_addrlen, hostname, sizeof hostname, NULL, 0 , 0);
if (error != 0)
{
continue; // try next one
}
else
{
NSLog (@"Found hostname: %s", hostname);
break;
}
}
freeaddrinfo(results);
}
A screenshot is also attached to see what i needed actually through objective c. Any help on this will be greatly appreciated.