我应该如何获得“localhost”的完全限定域名?在 c++ (在Ubuntu上)?

发布于 2024-08-19 16:05:19 字数 124 浏览 1 评论 0原文

我一直在摆弄 getaddrinfo 和 getnameinfo 但最接近有用的输出是“localhost.localdomain”。我不确定要为 getaddrinfo 的“节点”或“服务”参数传递什么,尽管我认为这是我想要的功能。

I've been messing around with getaddrinfo and getnameinfo but the closest I got to useful output was "localhost.localdomain". I'm not sure what to pass in for the "node" or "service" args of getaddrinfo, although I think it's the function I want.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

权谋诡计 2024-08-26 16:05:19

实际上,Zxaos在这里的答案几乎就是我一直在寻找的答案(尽管它是针对C的,而我的是针对C++的,但它在两者中都适用):

如何在 C 中查找当前计算机的完整主机名(主机名和域信息)?

所以我想我的问题是重复的......

Actually, Zxaos's answer here is pretty much the answer I was looking for (even though it's for C and mine was for C++, it works in both):

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

So I guess my question was a duplicate...

阳光的暖冬 2024-08-26 16:05:19

您可以尝试以下命令:

#hostname --fqdn

与 OpenSuse 风格配合良好。不确定Ubuntu。

You can try the following command:

#hostname --fqdn

Works well with OpenSuse flavour. Not sure about Ubuntu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文