How to get Fully qualified domain name in unix

笑着哭i 提交于 2019-12-24 04:15:28

问题


Is there any function(C or C++) which returns FQDN(Fully qualified domain name) in UNIX platforms?


回答1:


Use getifaddrs() to get the interfaces for the box in question, then use the "resolver interface" (man resolver) to query the FQDNs for the ip-addresses return by the former call to getifaddrs().

Do not use gethostname() or the command line tool hostname in this context, as an IXish box's "hostname" does not necessarily correlate with the FQDN's returned by a query issued for the box's interface-addresses via the "resolver interface".



来源:https://stackoverflow.com/questions/30048953/how-to-get-fully-qualified-domain-name-in-unix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!