How can I find the full hostname (FQDN) of the system I am running on?



How can I find the full hostname (FQDN) of the system I am running on?..

Answer / chaitanya

Some systems set the hostname to the FQDN and others set it to just the unqualified host name. I know the current BIND FAQ recommends the FQDN, but most Solaris systems, for example, tend to use only the unqualified host name.

Regardless, the way around this is to first get the host's name (perhaps an FQDN, perhaps unaualified). Most systems support the Posix way to do this using uname(), but older BSD systems only provide gethostname(). Call gethostbyname() to find your IP address. Then take the IP address and call gethostbyaddr(). The h_name member of the hostent{} should then be your FQDN.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Unix Socket Programming Interview Questions

What is the difference between SO_REUSEADDR and SO_REUSEPORT?

0 Answers  


What is socket programming in java?

0 Answers  


When will my application receive SIGPIPE?

1 Answers  


What exactly does SO_REUSEADDR do?

1 Answers  


How do I convert a string into an internet address?

0 Answers  


What is the purpose of socket?

0 Answers  


If bind() fails, what should I do with the socket descriptor?

1 Answers  


Why do not my sockets close?

1 Answers  


Why does connect() succeed even before my server did an accept()?

1 Answers  


Why does it take so long to detect that the peer died?

0 Answers  


What's the difference between a socket and a port?

0 Answers  


How do Sockets Work?

1 Answers  


Categories