| 253 | } |
| 254 | |
| 255 | int PotatoAPI::startRPCConnection(void) { |
| 256 | |
| 257 | |
| 258 | fflush(stdout); |
| 259 | WSADATA wsaData; |
| 260 | |
| 261 | struct addrinfo *result = NULL, |
| 262 | *ptr = NULL, |
| 263 | hints; |
| 264 | |
| 265 | char *sendbuf; |
| 266 | char recvbuf[DEFAULT_BUFLEN]; |
| 267 | int iResult; |
| 268 | int recvbuflen = DEFAULT_BUFLEN; |
| 269 | |
| 270 | // Initialize Winsock |
| 271 | iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); |
| 272 | if (iResult != 0) { |
| 273 | printf("WSAStartup failed with error: %d\n", iResult); |
| 274 | return 1; |
| 275 | } |
| 276 | |
| 277 | ZeroMemory(&hints, sizeof(hints)); |
| 278 | hints.ai_family = AF_UNSPEC; |
| 279 | hints.ai_socktype = SOCK_STREAM; |
| 280 | hints.ai_protocol = IPPROTO_TCP; |
| 281 | |
| 282 | // Resolve the server address and port |
| 283 | char myhost[24]; |
| 284 | char myport[12]; |
| 285 | |
| 286 | if (rpcserver != NULL) { |
| 287 | memset(myhost, 0, 24); |
| 288 | wcstombs(myhost, rpcserver, 24); |
| 289 | } |
| 290 | else { |
| 291 | strcpy(myhost, "127.0.0.1"); |
| 292 | } |
| 293 | |
| 294 | if (rpcport != NULL) { |
| 295 | memset(myport, 0, 12); |
| 296 | wcstombs(myport, rpcport, 12); |
| 297 | } |
| 298 | else { |
| 299 | strcpy(myport, "135"); |
| 300 | } |
| 301 | |
| 302 | iResult = getaddrinfo(myhost, myport, &hints, &result); |
| 303 | if (iResult != 0) { |
| 304 | printf("getaddrinfo failed with error: %d\n", iResult); |
| 305 | WSACleanup(); |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | // Attempt to connect to an address |
| 310 | for (ptr = result; ptr != NULL; ptr = ptr->ai_next) { |
| 311 | // Create a SOCKET for connecting to server |
| 312 | ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); |
no test coverage detected