gethostname 函数始终返回 nullptr
我正在尝试在Windows中解决C中的主机名。无论我输入什么地址,它总是返回nullptr。我在Python解释器中尝试了相同的功能,并且它可以正常运行,因此此功能之外没有错,这会导致其无法解析DNS。甚至“ Localhost”也失败了。尝试访问主机变量中的任何内容会导致崩溃。
struct hostent* host = gethostbyname("google.com");
if (host) {
printf("Yes\n");
}
else {
printf("No\n"); // Always gets here
}
I am attempting to resolve a hostname in C in windows. No matter what I enter in as the address it always returns a nullptr. I have tried the same function in a python interpreter and it works fine, so there is nothing wrong outside of this function that would cause it to be unable to resolve a DNS. Even "localhost" fails aswell. Attempting to access anything in the host variables causes a crash.
struct hostent* host = gethostbyname("google.com");
if (host) {
printf("Yes\n");
}
else {
printf("No\n"); // Always gets here
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论