【问题标题】:getaddrinfo error: ai_socktype not supportedgetaddrinfo 错误:不支持 ai_socktype
【发布时间】:2011-05-11 03:11:56
【问题描述】:
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 not supported” 如果我注释掉hint.ai_protocol = AI_PASSIVE; 它会通过,但我想知道为什么会这样?

感谢您的宝贵时间

【问题讨论】:

    标签: c sockets network-programming getaddrinfo


    【解决方案1】:

    值得在这里添加,因为这是搜索“ai_socktype not supported”时的最高结果 另一个原因可能是提示没有在堆栈上归零; 为此你需要

    memset(&hints, 0, sizeof hints);
    

    Nissan 的代码当然已经有了这个

    【讨论】:

      【解决方案2】:

      那是因为 AI_PASSIVE 是指 ai_flags 字段,(不是 ai_protocol)。 试试看:

      hint.ai_flags = AI_PASSIVE;
      

      看看addrinfo structure

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-29
        • 1970-01-01
        • 2016-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多