rendered paste body//Client to Aaron's fileserver//Author $ Dylan Johnston#include <cstdlib>#include <iostream>#include <string>#include <windows.h>#include <winsock2.h>#include <ws2tcpip.h>using namespace std;const string DEBUG = "[debug]: "; //just to make things clear* in the console :)char serverAddress[128];int main(){ int iResult; WSADATA wsaData; //start winsock iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != 0) { cout << DEBUG << "failed" << iResult << "\n"; } else { if (iResult == 0) { cout << DEBUG << "success" << "\n"; cout << DEBUG << "starting up winsock\n"; // Create a SOCKET for connecting to server SOCKET ConnectSocket; ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ConnectSocket == INVALID_SOCKET) { cout << DEBUG << "error " << WSAGetLastError(); WSACleanup(); } // The sockaddr_in structure specifies the address family, // IP address, and port of the server to be connected to. //sockaddr_in clientService; //clientService.sin_family = AF_INET; //clientService.sin_addr.s_addr = inet_addr( "209.85.135.103" ); //clientService.sin_port = htons( 80 ); addrinfo *aiList = 0; addrinfo aiHints = {0}; aiHints.ai_family = AF_UNSPEC; aiHints.ai_socktype = SOCK_STREAM; aiHints.ai_protocol = IPPROTO_TCP; cout << "address: "; cin >> serverAddress; if (getaddrinfo( serverAddress, "404", &aiHints, &aiList ) != 0 ) { cout << DEBUG << "closing socket getaddrinfo != 0 :(\n"; closesocket( ConnectSocket ); WSACleanup(); return 0; } // if all went well.. Connect to server. //if ( connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) //{ // cout << DEBUG << "failed connection " << WSAGetLastError() << "\n"; // closesocket( ConnectSocket ); // WSACleanup(); // system("Pause"); // return 0; // } int result; //for ( addrinfo * ptr = aiList; ptr != 0; ptr = ptr->ai_next ) { //result = connect( ConnectSocket, ptr->ai_addr , (int)ptr->ai_addrlen ); //if ( result == SOCKET_ERROR ) // closesocket( ConnectSocket ); // } cout << DEBUG << "connected!\n"; //we need to do our dns loop here i think? addrinfo * current = aiList; while ( current != 0 ) { result = connect( ConnectSocket, current->ai_addr, (int)current->ai_addrlen ); if ( result == SOCKET_ERROR ){ closesocket( ConnectSocket ); current = current->ai_next; } else { cout << DEBUG << "lez connection\n"; } break; } closesocket( ConnectSocket ); WSACleanup(); cout << DEBUG << "while-finished\n"; } } cout << DEBUG << "program termination\n"; system("Pause"); //closesocket( ConnectSocket ); WSACleanup(); return 0;}