0

根据要求,我的目标是不可用的旧旧 Windows 系统(9x 分支getaddrinfo()freeaddrinfo()

我可以用什么代替它?我现在使用的代码是从 MSDN 站点中提取的(我在 Vista 计算机上测试它):

...
/* WinSock data: */
WSADATA wsaData;
/* Initialize the WinSock data: */
short int iResult = 0;
if (iResult = WSAStartup(MAKEWORD(2,0), &wsaData)) {
    printf("Failed to init Winsock library: %d.\n", iResult);
    return -1;
}

printf("\n  Opening connection to server.");
/* Variables for a connection: */
struct addrinfo *result = NULL, *ptr = NULL, hints;
/* Initialize the connection: */
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
/* Resolve the server address and port: */
if (iResult = getaddrinfo("x", "80", &hints, &result)) {
    printf("Server resolution failed: %d.\n", iResult);
    WSACleanup();
    return -2;
}
...
4

1 回答 1

1

旧方法是gethostbynameand getnameinfo。用法在这里解释得很好:

http://beej.us/guide/bgnet/output/html/multipage/gethostbynameman.html

于 2010-03-25T17:26:54.097 回答