我应该如何获得“localhost”的完全限定域名?在 c++ (在Ubuntu上)?
我一直在摆弄 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,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...
您可以尝试以下命令:
与 OpenSuse 风格配合良好。不确定Ubuntu。
You can try the following command:
Works well with OpenSuse flavour. Not sure about Ubuntu.