#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment ( lib, ws2_32.lib )
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we couldn't find a useable */
/* winsock.dll. */
return 1;
}
addrinfo hints;
addrinfo *info = NULL;
int ret;
/* Setup type of address to get */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE ;
/* Get address from the machine */
ret = getaddrinfo("127.0.0.1", "9000", &hints, &info);
addrinfo *info1 = NULL;
ret = getaddrinfo("127.0.0.1", NULL, &hints, &info1);
addrinfo *info2 = NULL;
ret = getaddrinfo(NULL, "9000", &hints, &info2);
0. NULL NULL ai_addr =无
1. 127.0.0.1 9000 ai_addr =#)
2. 127.0.0.1 NULL ai_addr ="空
3. NULL 9000 ai_addr =#)
3. 192.168.1.11 9000 ai_addr =#(括{" }
3. 192.168.1.11 NULL ai_addr =空