[英]how can i get programmaticaly in Objective-C the name of local domain Knowing the ip adress?
嗨,我在2个不同的局域网中有很多iPad,我想以编程方式在Objective-C中了解每个iPad的IP地址中的本地域。 例如,我在本地域“ project.local”中有一个iPad。 在此域中,我们有许多IP地址,如192.168.12.50。 IOS设备会自动获取其IP地址。
现在,我想以编程方式在Objective-C中知道IP地址的域名“ projet.local”?
试试这个(类似于dreamlax的答案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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.