void *runBitcoin(void *lparam) { printf("Hello runBitcoin!\n"); char *myIP = getGlobalIPAddress(); initiateServer(1, myIP); }
int main(int argc, char *argv[]) { // Instantiate variables char buffer[8192]; pid_t pid; int clientLength; int socketFD; int newSocketFD; // Enable port reuse int yes = true; setsockopt(socketFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); // Check user arguments if (argc != 2) { printf("Use Format - otp_enc_d listening_port\n"); exit(1); } else if ((socketFD = socket(AF_INET, SOCK_STREAM, 0)) == -1) { // Check socket connection printf("Server Failure - Cannot open socket!\n"); exit(1); } // Instantiate port number and sockets int port = atoi(argv[1]); struct sockaddr_in serverAddress; struct sockaddr_in clientAddress; // Set server strcut bzero((char *)&serverAddress, sizeof(serverAddress)); // Boilerplate server structs serverAddress.sin_family = AF_INET; serverAddress.sin_port = htons(port); serverAddress.sin_addr.s_addr = INADDR_ANY; // Start it up! initiateServer(socketFD, serverAddress); // Connection iteration while (true) { // Accept any connection clients clientLength = sizeof(clientAddress); newSocketFD = accept(socketFD,(struct sockaddr *)&clientAddress, &clientLength); // Check for connection issues if (newSocketFD < 0) { printf("Server Failure - Cannot accept client!\n"); continue; } // Fork! pid = fork(); // Child process if (pid == 0) { childHelper(socketFD, newSocketFD, buffer); } else if (pid < 0) { // Fork error close(newSocketFD); printf("Server Failure: Fork error!\n"); } else { // Parent - End process for new client close(newSocketFD); // Wait for child wait(NULL); } } // Cleanup close(socketFD); return 0; }