我观察到,这是因为端口。端口是 C++ 字符串。当我硬编码端口号说“4091”时,我没有看到这个问题。有什么建议么?
int sockfd;
struct addrinfo hints, *servinfo, *p;
int rv;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE;
cout << "port: " << port << endl;
const char * por = port.c_str();
if ((rv = getaddrinfo(NULL, por, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
}