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".