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

后端 未结 5 1698
无人共我
无人共我 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:20

    The easy way, try uname()

    If that does not work, use gethostname() then gethostbyname() and finally gethostbyaddr()

    The h_name of hostent{} should be your FQDN

提交回复
热议问题