vc++ getaddrinfo error

This drag me mad

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#undef UNICODE
    
    #include "stdafx.h"
    #include <WS2tcpip.h>
    #include <WinSock2.h>
    #include <string>
    #pragma comment(lib,"Ws2_32.lib")
    
    using namespace std;
    
    int _tmain(int argc, char* argv[])
    {
    	
    	WSADATA wsa;
    	int error = WSAStartup(MAKEWORD(2,2),&wsa);
    	if (error != 0)
    	{
    		printf("An error in startup %d\n",WSAGetLastError());
    		system("pause");
    	}
    
    	addrinfo hints,
    		* result = NULL,
    		* ptr = NULL;
    	hints.ai_family = AF_UNSPEC;
    	hints.ai_protocol = IPPROTO_TCP;
    	hints.ai_socktype = SOCK_STREAM;
    	
    	error = getaddrinfo(argv[1],NULL,&hints,&result);
    	if (error != 0)
    	{
    		printf("An error in getaddrinfo %d\n",WSAGetLastError());
    		system("pause");
    	}
    
    	char stringbuffer[2075];
    	int len = sizeof(stringbuffer);
    	for(ptr = result; ptr->ai_next != NULL; ptr = ptr->ai_next)
    	{
    		if(ptr->ai_family == AF_INET)
    		{
    			printf("Address: %s\n",InetNtop(ptr->ai_family,ptr->ai_addr,stringbuffer,len));
    		}
    	}
    
    	return 0;
    }

getaddrinfo throw 11003 error, i've compared a lot of internet source with main but i can't figure out why getaddrinfo fail!
i've read the winsock error code description and it says that 11003 "indicates that some sort of nonrecoverable error occurred during a database lookup" so
thanks in advance !
Topic archived. No new replies allowed.