Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #undef UNICODE
- #define WIN32_LEAN_AND_MEAN
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <windows.h>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #include <sstream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <iostream>
- #include <sstream>
- #include <time.h>
- #include <fstream>
- #include <cstdio>
- #include <memory>
- #include <stdexcept>
- #include "sqlite3.h"
- #include <vector>
- // Need to link with Ws2_32.lib
- #pragma comment (lib, "Ws2_32.lib")
- // #pragma comment (lib, "Mswsock.lib")
- #define DEFAULT_BUFLEN 1024
- #define DEFAULT_PORT "8888"
- using namespace std;
- std::string exec(const char* cmd) {
- char buffer[128];
- std::string result = "";
- std::shared_ptr<FILE> pipe(_popen(cmd, "r"), _pclose);
- if (!pipe) throw std::runtime_error("popen() failed!");
- while (!feof(pipe.get())) {
- if (fgets(buffer, 128, pipe.get()) != NULL)
- result += buffer;
- }
- return result;
- }
- string getIPv4(string message)
- {
- int size = message.length();
- if ( size != 0)
- {
- char c = 'a';
- int spot = 0;
- int arraySpot = 0;
- string word = "";
- bool found = false;
- do
- {
- if (message[spot] != ' ')
- {
- word += message[spot];
- }
- else
- {
- if (word == "IPv4")
- {
- word = "";
- spot += 32;
- while (message[spot] != '\n')
- {
- word += message[spot];
- spot++;
- }
- found = true;
- }
- else
- {
- word = "";
- }
- }
- spot++;
- } while ((size != spot) && (!found));
- return word;
- }
- return 0;
- }
- vector<string> fromRequestToWords(string message)
- {
- int size = message.length();
- vector < string > words;
- if (size != 0)
- {
- char c = 'a';
- int spot = 0;
- int arraySpot = 0;
- string word = "";
- do
- {
- if (message[spot] != ' ')
- {
- word += message[spot];
- }
- else
- {
- words.push_back(word);
- word = "";
- arraySpot++;
- }
- spot++;
- } while (size != spot);
- }
- return words;
- }
- string getResquest(string message)
- {
- int size = message.length();
- if ( size != 0)
- {
- char c = 'a';
- int spot = 0;
- string word = "";
- do
- {
- if (message[spot] != ' ')
- {
- word += message[spot];
- }
- spot++;
- } while (message[spot] != ' ');
- return word;
- }
- return 0;
- }
- int callbackExistingUsernameOrAddedUsername(void* notUsed, int argc, char** argv, char** azCol) //returns if the command was successful (of sql)
- {
- if (argv[0] == NULL)
- {
- return -1;
- }
- return 1;
- }
- bool isUserExists(sqlite3 *db,string username) //checked
- {
- char** err = NULL;
- string a = "SELECT username FROM users WHERE username = '" + username + "';";
- const char* line = a.c_str();
- int rc2 = sqlite3_exec(db, line, callbackExistingUsernameOrAddedUsername, NULL, err);
- if ((rc2 == 0) || (rc2 == -1))
- {
- return false;
- }
- return true;
- }
- bool usernameAndPasswordMatch(sqlite3* db,string username, string password)
- {
- if (isUserExists(db,username))
- {
- char** err = NULL;
- string a = "SELECT username FROM users WHERE userName = '" + username + "' and password = '" + password + "' ;";
- const char* line = a.c_str();
- int rc2 = sqlite3_exec(db, line, callbackExistingUsernameOrAddedUsername, NULL, err);
- if ((rc2 == 0) || (rc2 == -1))
- {
- return false;
- }
- sqlite3_free(err);
- return true;
- }
- return false;
- }
- string decryption(string message)
- {
- string output = message;
- int size = message.size();
- for (int i = 0; i < size; i++)
- output[i] = message[i] ^ 'K';
- for (int i = 0; i < size; i++)
- output[i] = message[i] ^ 'w';
- for (int i = 0; i < size; i++)
- output[i] = message[i] ^ 'z';
- return output;
- }
- int main(void)
- {
- time_t start = time(0);
- sqlite3 *db;
- int rc;
- try
- {
- rc = sqlite3_open("Users.db", &db);
- if (rc)
- {
- throw sqlite3_errmsg(db);
- }
- }
- catch (std::exception &ex)
- {
- std::cout << ex.what() << std::endl;
- }
- WSADATA wsaData;
- int iResult;
- int closeConnection = 0;
- SOCKET ListenSocket = INVALID_SOCKET;
- SOCKET ClientSocket = INVALID_SOCKET;
- struct addrinfo *result = NULL;
- struct addrinfo hints;
- int iSendResult;
- int recvbuflen = DEFAULT_BUFLEN;
- // Initialize Winsock
- iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (iResult != 0) {
- printf("WSAStartup failed with error: %d\n", iResult);
- return 1;
- }
- ZeroMemory(&hints, sizeof(hints));
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- hints.ai_flags = AI_PASSIVE;
- // Resolve the server address and port
- iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result);
- if (iResult != 0) {
- printf("getaddrinfo failed with error: %d\n", iResult);
- WSACleanup();
- return 1;
- }
- // Create a SOCKET for connecting to server
- ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
- if (ListenSocket == INVALID_SOCKET) {
- printf("socket failed with error: %ld\n", WSAGetLastError());
- freeaddrinfo(result);
- WSACleanup();
- return 1;
- }
- // Setup the TCP listening socket
- iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
- if (iResult == SOCKET_ERROR) {
- printf("bind failed with error: %d\n", WSAGetLastError());
- freeaddrinfo(result);
- closesocket(ListenSocket);
- WSACleanup();
- return 1;
- }
- cout << ListenSocket << endl;
- printf("Im ready\n");
- freeaddrinfo(result);
- iResult = listen(ListenSocket, SOMAXCONN);
- if (iResult == SOCKET_ERROR) {
- printf("listen failed with error: %d\n", WSAGetLastError());
- closesocket(ListenSocket);
- WSACleanup();
- return 1;
- }
- // Accept a client socket
- ClientSocket = accept(ListenSocket, NULL, NULL);
- if (ClientSocket == INVALID_SOCKET) {
- printf("accept failed with error: %d\n", WSAGetLastError());
- closesocket(ListenSocket);
- WSACleanup();
- return 1;
- }
- printf("connected\n");
- // No longer need server socket
- closesocket(ListenSocket);
- // Receive until the peer shuts down the connection
- //********************* login start
- char recvbuf[DEFAULT_BUFLEN] = { 0 };
- char* sendbuf= "Enter Username\n" ;
- iSendResult = send(ClientSocket, sendbuf, (int)strlen(sendbuf), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
- cout << recvbuf << endl;
- string username(recvbuf);
- sendbuf = "Enter password\n";
- for (int i = 0; i < 1024; i++){ recvbuf[i] = 0; }
- iSendResult = send(ClientSocket, sendbuf, (int)strlen(sendbuf), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
- cout << recvbuf << endl;
- string password(recvbuf);
- password = decryption(password);
- username = decryption(username);
- //****************** sent the messages to get username and passwords
- if (usernameAndPasswordMatch(db,username, password))
- {
- sendbuf = "d Access granted.\n";
- iSendResult = send(ClientSocket, sendbuf, (int)strlen(sendbuf), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- do
- {
- sendbuf = "Enter your desired command.\n";
- iSendResult = send(ClientSocket, sendbuf, (int)strlen(sendbuf), 0);
- //taking commands
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
- cout << recvbuf << endl;
- string commandLine(recvbuf);
- commandLine.erase(0, 2);
- if (getResquest(commandLine) == "ECHO")
- {
- commandLine.erase(0, 5);
- string temp = "i " + commandLine;
- const char* string1 = temp.c_str();
- iSendResult = send(ClientSocket, sendbuf, (int)strlen(sendbuf), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (getResquest(commandLine) == "GIVEIP")
- {
- commandLine.erase(0, 7);
- string result = exec("ipconfig");
- result = getIPv4(result);
- string out = "i ";
- out = decryption(out); //PAY ATTENTION THAT ITS ENCRYPTED
- out += result;
- const char *tempOut = out.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (getResquest(commandLine) == "UPTIME")
- {
- double a = difftime(time(0), start);
- ostringstream sstream;
- sstream << a;
- string output = "i "+sstream.str()+" seconds\n";
- const char *tempOut = output.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (getResquest(commandLine) == "WHOAMI")
- {
- string output = "You are the user"+'"' + username + '"'+" that runs the operating system of: ";//needs to be continued
- }
- else if (getResquest(commandLine) == "MOVETO")
- {
- commandLine.erase(0, 7);
- string temp = "cd " + commandLine;
- string result = exec(temp.c_str());
- result = decryption(result); //ENCRYPTION ALERT
- temp = "i "+result;
- const char *tempOut = temp.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (getResquest(commandLine) == "RUN")
- {
- commandLine.erase(0, 4);
- string result = exec(commandLine.c_str());
- result = decryption(result);
- string output = "i " + result;
- output = decryption(output); //ENCRYPTION ALERT
- const char *tempOut = output.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (getResquest(commandLine) == "PRINTF")
- {
- string line = decryption(commandLine); //DECRYPTION ALERT
- line = commandLine.erase(0, 7);
- if ((commandLine[-1] == 't') && (commandLine[-2] == 'x') && (commandLine[-3] == 't') && (commandLine[-4] == '.'))
- {
- string command = "print " + commandLine;
- string result = exec(command.c_str());
- int size = result.length();
- if (size / 1024 > 0)
- {
- string output = result.substr(0, 1025);
- result.erase(0, 1025);
- string temp(sendbuf);
- temp = decryption(temp); //Encryption alert!
- const char *tempOut = temp.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- size -= 1024;
- }
- else
- {
- string temp(sendbuf);
- temp = decryption(temp); //Encryption alert!
- const char *tempOut = temp.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- tempOut = "m";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- }
- else if (getResquest(commandLine) == "GOAWAYF")
- {
- string line = decryption(commandLine); //DECRYPTION ALERT
- line = commandLine.erase(0, 7);
- string temp = "k Are you sure you want to delete " + line + " ?";
- const char *tempOut = temp.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
- if ((recvbuf[2] == 'y') || (recvbuf[2] == 'Y'))
- {
- string command = "DEL /Q" + line;
- string result = exec(command.c_str());
- const char *tempOut = result.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- else if (getResquest(commandLine) == "GOAWAYD")
- {
- string line = decryption(commandLine); //DECRYPTION ALERT
- line = commandLine.erase(0, 7);
- string temp = "k Are you sure you want to delete " + line + " ?";
- const char *tempOut = temp.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
- if ((recvbuf[2] == 'y') || (recvbuf[2] == 'Y'))
- {
- string command = "rmdir /Q /S " + line;
- string result = exec(command.c_str());
- command = "rmdir /Q " + line;
- result = exec(command.c_str());
- const char *tempOut = result.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- else if (getResquest(commandLine) == "MAKEF")
- {
- commandLine.erase(0, 6);
- struct stat info;
- if (stat(commandLine.c_str(), &info) != 0) // cant access
- {
- const char *tempOut = "z can't access directory\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (info.st_mode & S_IFDIR) // there is a directory
- {
- const char *tempOut = "k The folder alright exists would you like to override it?\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
- if ((recvbuf[2] == 'y') || (recvbuf[2] == 'Y'))
- {
- string command1 = "DEL /Q" + commandLine;
- exec(command1.c_str());
- string command = "copy nul " + commandLine + " /Q";
- string result = exec(command.c_str());
- if (result == "")
- {
- const char *tempOut = "i Folder was successfuly overwritten\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else
- {
- const char *tempOut = "z Error while overwriting the Folder\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- }
- else
- {
- string command = "copy nul " + commandLine + " /Q"; // there is no directory
- string result = exec(command.c_str());
- string out = "i " + result;
- const char *tempOut = out.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- else if (getResquest(commandLine) == "MAKED")
- {
- commandLine.erase(0, 6);
- struct stat info;
- if (stat(commandLine.c_str(), &info) != 0)
- {
- const char *tempOut = "z error while trying to execute\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (info.st_mode & S_IFDIR) // S_ISDIR() doesn't exist on my windows
- {
- const char *tempOut = "k The folder alright exists would you like to override it?\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
- if ((recvbuf[2] == 'y') || (recvbuf[2] == 'Y'))
- {
- string command = "DEL /Q" + commandLine;
- string result = exec(command.c_str());
- command = " MKDIR " + commandLine;
- result = exec(command.c_str());
- if (result == "")
- {
- const char *tempOut = "i Folder was successfuly overwritten\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else
- {
- const char *tempOut = "z Errow while overwriting the Folder\n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- }
- else
- {
- string command = " MKDIR " + commandLine; // there is no directory
- string result = exec(command.c_str());
- string out = "i " + result;
- const char *tempOut = out.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- else if (getResquest(commandLine) == "COPYF")
- {
- commandLine.erase(0, 6);
- string src = "";
- string dst = "";
- int spot = 0;
- while (commandLine[spot] != ' ')
- {
- src += commandLine[spot];
- }
- spot++;
- while (commandLine[spot] != ' ')
- {
- dst += commandLine[spot];
- }
- streampos beg, end;
- ofstream copyTo(dst, ios::binary);
- if (copyTo.is_open())
- {
- ifstream copyFrom(src, ios::binary);
- copyFrom.seekg(0, ios::end);
- end = copyFrom.tellg();
- copyFrom.seekg(0, ios::beg);
- int size = end;
- char* file = NULL;
- copyFrom.read(file, size);
- copyFrom.close();
- copyTo.seekp(0, ios::end);
- end = copyTo.tellp();
- int size1 = end;
- copyTo.seekp(0, ios::beg);
- copyTo << file;
- copyTo.close();
- const char *tempOut("i Successfully copied file\n");
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else
- {
- const char *tempOut("i Error while copying'n");
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- else if (getResquest(commandLine) == "EXEC")
- {
- commandLine.erase(0, 5);
- string result = exec(commandLine.c_str());
- result = decryption(result);
- string output = "i " + result;
- output = decryption(output); //ENCRYPTION AND DECRYPTION ALERT
- const char *tempOut = output.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else if (getResquest(commandLine) == "DL")
- {
- commandLine.erase(0, 3);
- streampos begin, end;
- ifstream myfile(commandLine, ios::binary);
- begin = myfile.tellg();
- myfile.seekg(0, ios::end);
- end = myfile.tellg();
- myfile.seekg(0, ios::beg);
- int size = end;
- while (size > 0)
- {
- if (size / 1024 > 0)
- {
- myfile.read(sendbuf, 1024);
- string temp(sendbuf);
- temp = decryption(temp);
- const char *tempOut = temp.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- size -= 1024;
- }
- else
- {
- myfile.read(sendbuf, size);
- string temp(sendbuf);
- temp = decryption(temp);
- const char *tempOut = temp.c_str();
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- }
- myfile.close();
- const char *tempOut = "m /n";
- iSendResult = send(ClientSocket, tempOut, (int)strlen(tempOut), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- else
- {
- sendbuf = "g Not a valid request";
- iSendResult = send(ClientSocket, sendbuf, (int)strlen(sendbuf), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- //closeConnection++;
- } while ((iResult > 0) && (iSendResult >0) && (!closeConnection));
- }
- else
- {
- sendbuf = "f Access Denied, terminating connection.\n";
- iSendResult = send(ClientSocket, sendbuf, (int)strlen(sendbuf), 0);
- if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); exit(1); }
- }
- // shutdown the connection since we're done
- iResult = shutdown(ClientSocket, SD_SEND);
- if (iResult == SOCKET_ERROR) {
- printf("shutdown failed with error: %d\n", WSAGetLastError());
- closesocket(ClientSocket);
- WSACleanup();
- return 1;
- }
- // cleanup
- closesocket(ClientSocket);
- WSACleanup();
- return 0;
- }
- //100 opening connection -e
- //101 closing connection -f
- //102 rawText -g
- //103 request -h
- //104 response-Request -i
- //105 varification question - j
- //106 varification answer - k
- //107 end sending -l
- //107 excecution failed - z
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement