我想知道你是否知道为什么GetAddrInfo失败了子域名?示例:www.support.hostgator.com
Return value from WSAGetLastError() is 11001
No such host is known
我在MSDN上环顾四周,并没有找到任何关于如何处理这个问题的内容。
以下是简化问题:
#include <string>
#include <WinSock2.h>
#include <WS2tcpip.h>
int main(){
std::wstring Domain = L"www.support.hostgator.com";
std::wstring Port = L"443";
WSADATA WsaData{0};
WSAStartup(MAKEWORD(2,2), &WsaData);
addrinfoW hints{ 0 }, *results = nullptr;
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_socktype = SOCK_STREAM;
if (GetAddrInfoW(Domain.c_str(), Port.c_str(), &hints, &results)) {
return WSAGetLastError();
}
return 0;
}