How do I find the current machine's full hostname in C (hostname and domain information)?

后端 未结 5 1696
无人共我
无人共我 2020-11-30 23:33

In a C project (POSIX), how do I get the fully qualified name for the current system?

For example, I can get just the hostname of my machine by doing gethostna

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 00:12

    gethostname() is POSIX way to get local host name. Check out man.

    BSD function getdomainname() can give you domain name so you can build fully qualified hostname. There is no POSIX way to get a domain I'm afraid.

提交回复
热议问题