24{
25 WSADATA wsaData;
26 SOCKET ConnectSocket = INVALID_SOCKET;
28 int iResult;
29
30
31
32
33 iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
34 if (iResult != 0)
35 {
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 {
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 {
90 WSACleanup();
91 return 1;
92 }
93
94
95
96
97 *ConnectSocketArg = ConnectSocket;
98
99 return 0;
100}
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
result
Definition modelsim.py:117
NULL()
Definition test-case-generator.py:530