getaddrinfo 错误:不支持 ai_socktype
struct addrinfo *myAddrinfo, *curMyAddrinfo, hint;
memset(&hint, 0, sizeof(struct addrinfo));
hint.ai_family = AF_INET;
hint.ai_protocol = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
const int code = getaddrinfo(NULL, SERVER_PORT, &hint, &myAddrinfo);
if ((code) != 0) {
printf("getaddrinfo error occours: %s ",
gai_strerror(code));
return 1;
}
这给出了错误:“ai_socktype 不支持” 如果我注释掉 hint.ai_protocol = AI_PASSIVE;
它会通过,但我想知道为什么会发生?
谢谢你的时间
struct addrinfo *myAddrinfo, *curMyAddrinfo, hint;
memset(&hint, 0, sizeof(struct addrinfo));
hint.ai_family = AF_INET;
hint.ai_protocol = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
const int code = getaddrinfo(NULL, SERVER_PORT, &hint, &myAddrinfo);
if ((code) != 0) {
printf("getaddrinfo error occours: %s ",
gai_strerror(code));
return 1;
}
this gives the error: "ai_socktype not supported"
if i comment out the hint.ai_protocol = AI_PASSIVE;
it will get through, but i am wondering why it happens?
thanks for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
值得在此处添加,因为这是搜索“ai_socktype not support”时的最佳结果
另一个原因可能是堆栈上的提示未归零;
为此你需要
日产的代码当然已经有了
It's worth just adding here, as this is the top result when searching for "ai_socktype not supported"
an alternative reason for it could be that hints is not zeroed on the stack;
for that you need
Nissan's code of course did have that already
这是因为 AI_PASSIVE 引用了 ai_flags 字段(而不是 ai_protocol)。
尝试:
看看 addrinfo 结构。
That's because AI_PASSIVE is referred to ai_flags field, (not ai_protocol).
Try :
And have a look at addrinfo structure.