24{
25 WSADATA wsaData;
26 SOCKET ConnectSocket = INVALID_SOCKET;
29
30
31
32
33 IResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
34 if (IResult != 0)
35 {
36 ShowMessages("err, WSAStartup failed (%x)\n", IResult);
37 return 1;
38 }
39
40 ZeroMemory(&hints, sizeof(hints));
41 hints.ai_family = AF_UNSPEC;
42 hints.ai_socktype = SOCK_STREAM;
43 hints.ai_protocol = IPPROTO_TCP;
44
45
46
47
48 IResult = getaddrinfo(Ip, Port, &hints, &result);
49 if (IResult != 0)
50 {
51 ShowMessages("getaddrinfo failed (%x)\n", IResult);
52 WSACleanup();
53 return 1;
54 }
55
56
57
58
59 for (ptr = result; ptr !=
NULL; ptr = ptr->ai_next)
60 {
61
62
63
64 ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
65 if (ConnectSocket == INVALID_SOCKET)
66 {
67 ShowMessages("socket failed with error: %ld\n", WSAGetLastError());
68 WSACleanup();
69 return 1;
70 }
71
72
73
74
75 IResult = connect(ConnectSocket, ptr->ai_addr, (
INT)ptr->ai_addrlen);
76 if (IResult == SOCKET_ERROR)
77 {
78 closesocket(ConnectSocket);
79 ConnectSocket = INVALID_SOCKET;
80 continue;
81 }
82 break;
83 }
84
85 freeaddrinfo(result);
86
87 if (ConnectSocket == INVALID_SOCKET)
88 {
89 ShowMessages("unable to connect to the server\n");
90 WSACleanup();
91 return 1;
92 }
93
94
95
96
97 *ConnectSocketArg = ConnectSocket;
98
99 return 0;
100}
result
Definition modelsim.py:117
NULL()
Definition test-case-generator.py:530