Nis*_*911 1 c sockets network-programming getaddrinfo
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;
}
Run Code Online (Sandbox Code Playgroud)
这给出了错误:如果我注释掉hint.ai_protocol = AI_PASSIVE;它,它将通过:“不支持ai_socktype” ,但是我想知道为什么会发生?
谢谢你的时间
只需在此处添加,因为这是搜索“不支持ai_socktype”时的最佳结果,另一个原因可能是提示未在堆栈上清零。为此,您需要
memset(&hints, 0, sizeof hints);
Run Code Online (Sandbox Code Playgroud)
日产的代码当然已经做到了