int waiting_for_connection(t_info *info) { int b; unsigned int size; b = 1; while (info->accept_connections) { size = sizeof(info->sin_client); info->csock = accept(info->socket, (struct sockaddr *)(&(info->sin_client)), &size); if (info->csock == -1) { b = 0; info->accept_connections = 0; } else if (manage_client(info) == 0) info->accept_connections = 0; close(info->csock); } waiting_for_pid(info->pid_list); close_everything(info); return (b); }
/* * This signal handler is called when the attack program dies. * Note: this handler can only be called in FIFO mode * Do some cleaning. */ void sig_pipe_handler (int sig) { if (current_trace_num >= num_iterations - 1) { /* This is the last iteration so it is normal */ } else { /* The termination of the attack program is not normal at this point */ printf ("\nEE - Attack program terminates unexpectedly!\n"); close_everything (); exit (EXIT_FAILURE); } }
/* * The main function of the program. */ int main (int argc, char **argv) { /* Do some checks to verify the proper alignemnt of data structure */ assert (sizeof (struct attack_partial_result) == 16*256+1); assert (sizeof (struct attack_trace) == TRACE_PLAINTEXT_SIZE_BYTES + TRACE_CIPHERTEXT_SIZE_BYTES + 2 * TRACE_NUM_POINTS); assert (sizeof (struct result_file_header) == 2*TRACE_KEY_SIZE_BYTES+4*4); assert (sizeof (struct result_file_trace_header) == TRACE_PLAINTEXT_SIZE_BYTES + TRACE_CIPHERTEXT_SIZE_BYTES + sizeof(double)); parse_command_line (argc, argv); result_file = fopen (output_filename, "w"); if (result_file == NULL) { perror ("fopen (result file)"); exit (EXIT_FAILURE); } create_communication_pipes (); if (trace_dir == NULL) { db_connect (); db_findkey (); } else { trace_dir_init (); trace_dir_findkey (); } print_result_file_header (); install_sig_handler (); if (fifo_mode == 0) launch_attack (); send_num_iterations (); wait_start_attack_phase (); launch_trace_thread (); for (current_trace_num = 0; current_trace_num < num_iterations; current_trace_num++) { printf ("II - Trace #%hu: ", current_trace_num); get_trace_from_trace_thread (); send_trace (); read_result (); } close_everything (); wait_trace_thread_termination (); if (fifo_mode == 0) { printf ("II - Waiting the end of the attack program...\n"); wait (NULL); /* Wait until the child (attack program) is finished */ } exit (EXIT_SUCCESS); }