Is there any function(C or C++) which returns FQDN(Fully qualified domain name) in UNIX platforms?
Asked
Active
Viewed 1,667 times
2
-
1man 3 getnameinfo, example in the man page – sivann May 05 '15 at 09:26
-
possible duplicate of [How do I find the current machine's full hostname in C (hostname and domain information)?](http://stackoverflow.com/questions/504810/how-do-i-find-the-current-machines-full-hostname-in-c-hostname-and-domain-info) – lihudi May 05 '15 at 10:40
1 Answers
2
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".

alk
- 69,737
- 10
- 105
- 255