Pipes and socket pairs

Requirements: the code should fully complie PURPOSE:To go over multiprocessing on a single machine:pipes/socket pairsfork()/execl()OVERVIEW:Cryptographic hash functions are hash functions that are designed to be relatively easy to compute but hard to figure out which sequences of bytes yields a given hash value. (Computation in reverse.)On Linux systems the command-line tool openssl does several things including computing some common hash functions. For example if we make a little file:$ cat > print.txtGreetings how are you? (press Enter)(press Ctrl-D)$ cat print.txtGreetings how are you?$ We can use openssl to compute the SHA-224 hash of it:$ openssl sha224 -hex < print.txt(stdin)= 2bf96f28acc7c224180c36f241abb9f36a1ab95fe8f3737d312abcd4$ We will finish a program that acts like a simple word-processor and that sends its text to openssl to compute the hashes SHA-224 and SHA-256. It then prints them for the user.Esc to quit. Ctrl-P to compute hashes. Greetings how are you? Hashes: sha224= 2bf96f28acc7c224180c36f241abb9f36a1ab95fe8f3737d312abcd4 sha256= 77a710abf0b87330026b1530fd062049fd923f0170fdc2dd786004601659218e COMPUTINGPlease ssh into one of the following:cdmcscjpprd01.dpu.depaul.eduyour own Unix machine with openssl and ncurses installedPlease submit your finished programPLEASE COPY-AND-PASTE THE FOLLOWING FILE (0 POINTS):wordProc_hash.c/*————————————————————————-* *— —* *— wordProc_hash.c —* *— —* *— A rudimentary word processor that prints the hash values of —* *— saved files. —* *— —* *— —- —- —- —- —- —- —- —- —* *— —* *— Version 1a 2020 January 1 Joseph Phillips —* *— —* *————————————————————————-*///// Compile with:// $ g++ wordProc_hash.c -o wordProc_hash -lncurses -g//// NOTE:// If this program crashes then you may not see what you type.// If that happens just type://// stty sane//// to your terminal even though you cannot even see it.//— —////— Header file inclusions: —////— —//#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h> // For alarm()#include <sys/socket.h>#include <sys/types.h> // For creat()#include <sys/wait.h> // For creat() wait()#include <sys/stat.h> // For creat()#include <fcntl.h> // For creat()#include <signal.h>#include <ncurses.h>//— —////— Definitions of constants: —////— —//#define HASH_PROGRAM “/usr/bin/openssl”#define HASH_ARG “-hex”#define STOP_CHARS “*+-#&”const char* HASH_TYPE_ARRAY[] = {“sha224″”sha256″};const int NUM_HASH_TYPES = sizeof(HASH_TYPE_ARRAY)/sizeof(char*);const int HEIGHT = 5;const int WIDTH = 72;const int INIT_TEXT_LEN = 1024;const int MAX_TEXT_LEN = 65536;const char STOP_CHAR = (char)27;const char PRINT_CHAR = (char)0x10;const int BUFFER_LEN = 64 * 16;const int TYPING_WINDOW_BAR_Y = 0;const int CHECKING_WINDOW_BAR_Y = TYPING_WINDOW_BAR_Y + HEIGHT + 1;const int MESSAGE_WINDOW_BAR_Y = CHECKING_WINDOW_BAR_Y + 1;const int NUM_MESSAGE_SECS = 6;//— —////— Definitions of global vars: —////— —//WINDOW* typingWindow;WINDOW* checkingWindow;WINDOW* messageWindow;pid_t childPid;int shouldRun = 1;//— —////— Definitions of global fncs: —////— —//// PURPOSE: To turn ncurses on. No parameters. No return value.void onNCurses (){ // I. Application validity check: // II. Turn ncurses on: initscr(); cbreak(); noecho(); nonl();//intrflush(stdscr FALSE);//keypad(stdscr TRUE); typingWindow = newwin(HEIGHTWIDTHTYPING_WINDOW_BAR_Y+11); checkingWindow = newwin(HEIGHTWIDTHCHECKING_WINDOW_BAR_Y+11); messageWindow = newwin( 2WIDTHMESSAGE_WINDOW_BAR_Y1); scrollok(typingWindowTRUE); scrollok(checkingWindowTRUE); mvaddstr(TYPING_WINDOW_BAR_Y0″Esc to quit. Ctrl-P to compute hashes.”); mvaddstr(CHECKING_WINDOW_BAR_Y0″Hashes:”); refresh(); wrefresh(typingWindow); // moves cursor back to typingWindow: // III. Finished:}// PURPOSE: To handle SIGALRM signals. Ignores sig (which will be// SIGALRM). No return value.void sigAlarmHandler (int sig ){ mvwaddstr (messageWindow00 ” ” ” ” ); mvwaddstr (messageWindow10 ” ” ” ” ); wrefresh(messageWindow); wrefresh(typingWindow); // moves cursor back to typingWindow:}// PURPOSE: To save the lineIndex chars at the beginning of line to// to position *endTextPtrPtr in buffer *bufferPtrPtr of length// *bufferLenPtr and with end *endBufferPtrPtr. If there is not// enough space in *bufferPtrPtr then *bufferLenPtr will be doubled// and *bufferPtrPtr will be realloc()-ed to this new length.// No return value.void saveLine (size_t* bufferLenPtr char** bufferPtrPtr char** endTextPtrPtr char** endBufferPtrPtr const char* line int lineIndex ){ // I. Application validity check: // II. Save line to *bufferPtrPtr: // II.A. Allocate more space if needed: if (lineIndex >= (*endBufferPtrPtr – *endTextPtrPtr + 1) ) { size_t textLen = *endTextPtrPtr – *bufferPtrPtr; (*bufferLenPtr) *= 2; (*bufferPtrPtr) = (char*)realloc(*bufferPtrPtr*bufferLenPtr); (*endTextPtrPtr) = *bufferPtrPtr + textLen; (*endBufferPtrPtr) = *bufferPtrPtr + *bufferLenPtr; } // II.B. Save line to *bufferPtrPtr: memcpy(*endTextPtrPtrlinelineIndex); (*endTextPtrPtr) += lineIndex; // III. Finished:}// PURPOSE: To attempt to compute the hashes of the text pointed to by// bufferPtr using the hash functions in HASH_TYPE_ARRAY[].// endTextPtr points to one char beyond the end of the text to print// in bufferPtr. No return value.//// SIDE EFFECT: Prints to messageWindow and sets process to receive// SIGALRM NUM_MESSAGE_SECS seconds in the future.// This will invoke sigAlarmHandler() which erases the// text in messageWindow.void computeHashes (const char* bufferPtr const char* endTextPtr ){ // I. Application validity check: // II. Compute hashes: // II.A. Each iteration computes one hash: int hashIndex; for (hashIndex = 0; hashIndex < NUM_HASH_TYPES; hashIndex++) { // II.A.1. Create pipes: int toChild[2]; int fromChild[2]; // YOUR CODE HERE to make 2 pipes // II.A.2. Do openssl process work: if (/* YOUR CODE HERE to make a child */ == 0) { // YOUR CODE HERE to handle child case exit(EXIT_FAILURE); } // II.A.3. Do parent work: int numBytes; int status; char text[INIT_TEXT_LEN]; const char* msgCPtr; // YOUR CODE HERE to handle parent case mvwaddstr(messageWindowhashIndex0HASH_TYPE_ARRAY[hashIndex]); waddstr(messageWindowmsgCPtr); wrefresh(messageWindow); } wrefresh(typingWindow); // moves cursor back to typingWindow: // YOUR CODE HERE to do one last thing // III. Finished:}// PURPOSE: To allow the user to type display what they type in// &apostypingWindow and to compute the hash upon pressing PRINT_CHAR.// vPtr comes in perhaps pointing to something. Returns NULL.void* type (void* vPtr ){ // I. Application validity check: // II. Handle user typing: unsigned int c; char line[WIDTH+1]; int index = 0; size_t bufferLen = INIT_TEXT_LEN; char* bufferPtr = (char*)malloc(bufferLen); char* endTextPtr = bufferPtr; char* endBufferPtr = bufferPtr + bufferLen; // II.A. Each iteration handles another typed char: while ( (c = getch()) != STOP_CHAR ) { // II.A.1. Handle special chars: if (c == \r) { // II.A.1.a. Treat carriage return like newline: c = \n; } else if ( (c == 0x7) || (c == 127) ) { // II.A.1.b. Handle backspace: int col = getcurx(typingWindow); if (col > 0) { index–; wmove(typingWindowgetcury(typingWindow)col-1); wrefresh(typingWindow); } continue; } else if (c == PRINT_CHAR) { size_t textLen = endTextPtr – bufferPtr; saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex); computeHashes(bufferPtrendTextPtr); endTextPtr = bufferPtr + textLen; continue; } else if (c == ERR) { continue; } // II.A.2. Print and record the char: waddch(typingWindowc); wrefresh(typingWindow); line[index++] = c; // II.A.3. Handle when save line: if (c == \n) { // II.A.3.a. Save line when user types newline: saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex); index = 0; } else if (index == WIDTH-1) { // II.A.3.b. Save line when at last column: line[index] = \n; index++; saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex); index = 0; waddch(typingWindow\n); wrefresh(typingWindow); } } // III. Finished: saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex);//int inFd = creat(TEXT_FILENAME0640);//write(inFdbufferPtrendTextPtr-bufferPtr);//close(inFd); free(bufferPtr); return(NULL);}// PURPOSE: To turn off ncurses. No parameters. No return value.void offNCurses (){ sleep(1); nl(); echo(); refresh(); delwin(messageWindow); delwin(typingWindow); delwin(checkingWindow); endwin();}// PURPOSE: To do the spell-checking word-processor. Ignores command line// arguments. Return EXIT_SUCCESS to OS.int main (){ struct sigaction act; // (2) YOUR CODE HERE to install sigAlarmHandler as the handler for SIGALRM onNCurses(); type(NULL); offNCurses(); return(EXIT_SUCCESS);} The action starts of course in main(). The first thing that main() should do is to install a simple signal handler:Signal: Handler to run:SIGALRM sigAlarmHandler()After that mainy-main:turns the windowing on (onNCurses() already done)lets the user type expressions (type() is done but it calls computeHashes() which you must finish)turns the windowing off (offNCurses() already done)You must finish computeHashes(). It has a loop because it calls openssl twice once for SHA-224 and once for SHA-256. Both iterations use pipes to send the endTextPtr-outputBufferPtr bytes pointed to by outputBufferPtr to a child process running openssl.(Section II.A.1.) First create two pipes. We will use one for the parent to talk to the child and the other for the child to talk to the parent.(Section II.A.2.) Now make a child process. If we are the child process then be sure to:close() unnecessary pipe file descriptorsRedirect STDIN_FILENO to the input end of the appropriate pipe and redirect STDOUT_FILENO to the output end of the appropriate pipe.Run the hash program. The execl() program must specify the string constantsHASH_PROGRAM: The path of opensslHASH_TYPE_ARRAY[hashIndex]: Tells which hash to compute (SHA-224 or SHA-256)HASH_ARG: tells to give output in hexadecimalRemember:How many times do we specify the program name?What should the last argument to execl() be?Have exit(EXIT_FAILURE) after the execl() line. Why?(Section II.A.3.) Now handle the parent. If we are the parent process then be sure to:close() unnecessary pipe file descriptorsSend the endTextPtr-bufferPtr bytes of text pointed to by bufferPtr to the child. Then close() that file descriptor.Get the response from the child into text and wait() for the child to end (getting its return status).If the child successfully finished and read()ing its response was successful thenAdd a null-char just after the last byteSet msgCPtr to the occurence of “= ” in the text you read() (HINT Use strstr().)IF YOU HAVE A MAC: then just say this instead:msgCPtr = text;If the child did not successfully finish or read()ing the response was not successful then set msgCPtr = “Compute hash failed”The very last thing the function should do is alarm(NUM_MESSAGE_SECS) This tells it run sigAlarmHandler() NUM_MESSAGE_SECS seconds in the future. That function erases the hash-values.Add whatever variables you want (within reason).Now run the bad boy! Type something and press Ctrl-P to compute the hash. Press Esc to quit.SAMPLE OUTPUT: Esc to quit. Ctrl-P to compute hashes. Greetings how are you? Hashes: sha224= 2bf96f28acc7c224180c36f241abb9f36a1ab95fe8f3737d312abcd4 sha256= 77a710abf0b87330026b1530fd062049fd923f0170fdc2dd786004601659218e SEQUENCE DIAGRAM: parentprocess | | | fork() | /execl() openssl +—————————————>| | | | | | | | | |write(“Greetings how are you?\n”) | +—————————————>|read() | | | | |<—————————————+ write(“(stdin)= 2bf96f28acc7c224180c36f241abb9f36a1ab95fe8f3737d312abcd4”) | stops | | | | | fork() | /execl() openssl +—————————————>| | | | | | | | | | write(“Greetings how are you?\n”) | +—————————————>|read() | | | | |<—————————————+ write(“(stdin)= 77a710abf0b87330026b1530fd062049fd923f0170fdc2dd786004601659218e”) | | | stops | pipes/socket pairs fork()/execl() cdmcscjpprd01.dpu.depaul.edu your own Unix machine with openssl and ncurses installed PLEASE COPY-AND-PASTE THE FOLLOWING FILE (0 POINTS):wordProc_hash.c/*————————————————————————-* *— —* *— wordProc_hash.c —* *— —* *— A rudimentary word processor that prints the hash values of —* *— saved files. —* *— —* *— —- —- —- —- —- —- —- —- —* *— —* *— Version 1a 2020 January 1 Joseph Phillips —* *— —* *————————————————————————-*///// Compile with:// $ g++ wordProc_hash.c -o wordProc_hash -lncurses -g//// NOTE:// If this program crashes then you may not see what you type.// If that happens just type://// stty sane//// to your terminal even though you cannot even see it.//— —////— Header file inclusions: —////— —//#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h> // For alarm()#include <sys/socket.h>#include <sys/types.h> // For creat()#include <sys/wait.h> // For creat() wait()#include <sys/stat.h> // For creat()#include <fcntl.h> // For creat()#include <signal.h>#include <ncurses.h>//— —////— Definitions of constants: —////— —//#define HASH_PROGRAM “/usr/bin/openssl”#define HASH_ARG “-hex”#define STOP_CHARS “*+-#&”const char* HASH_TYPE_ARRAY[] = {“sha224″”sha256″};const int NUM_HASH_TYPES = sizeof(HASH_TYPE_ARRAY)/sizeof(char*);const int HEIGHT = 5;const int WIDTH = 72;const int INIT_TEXT_LEN = 1024;const int MAX_TEXT_LEN = 65536;const char STOP_CHAR = (char)27;const char PRINT_CHAR = (char)0x10;const int BUFFER_LEN = 64 * 16;const int TYPING_WINDOW_BAR_Y = 0;const int CHECKING_WINDOW_BAR_Y = TYPING_WINDOW_BAR_Y + HEIGHT + 1;const int MESSAGE_WINDOW_BAR_Y = CHECKING_WINDOW_BAR_Y + 1;const int NUM_MESSAGE_SECS = 6;//— —////— Definitions of global vars: —////— —//WINDOW* typingWindow;WINDOW* checkingWindow;WINDOW* messageWindow;pid_t childPid;int shouldRun = 1;//— —////— Definitions of global fncs: —////— —//// PURPOSE: To turn ncurses on. No parameters. No return value.void onNCurses (){ // I. Application validity check: // II. Turn ncurses on: initscr(); cbreak(); noecho(); nonl();//intrflush(stdscr FALSE);//keypad(stdscr TRUE); typingWindow = newwin(HEIGHTWIDTHTYPING_WINDOW_BAR_Y+11); checkingWindow = newwin(HEIGHTWIDTHCHECKING_WINDOW_BAR_Y+11); messageWindow = newwin( 2WIDTHMESSAGE_WINDOW_BAR_Y1); scrollok(typingWindowTRUE); scrollok(checkingWindowTRUE); mvaddstr(TYPING_WINDOW_BAR_Y0″Esc to quit. Ctrl-P to compute hashes.”); mvaddstr(CHECKING_WINDOW_BAR_Y0″Hashes:”); refresh(); wrefresh(typingWindow); // moves cursor back to typingWindow: // III. Finished:}// PURPOSE: To handle SIGALRM signals. Ignores sig (which will be// SIGALRM). No return value.void sigAlarmHandler (int sig ){ mvwaddstr (messageWindow00 ” ” ” ” ); mvwaddstr (messageWindow10 ” ” ” ” ); wrefresh(messageWindow); wrefresh(typingWindow); // moves cursor back to typingWindow:}// PURPOSE: To save the lineIndex chars at the beginning of line to// to position *endTextPtrPtr in buffer *bufferPtrPtr of length// *bufferLenPtr and with end *endBufferPtrPtr. If there is not// enough space in *bufferPtrPtr then *bufferLenPtr will be doubled// and *bufferPtrPtr will be realloc()-ed to this new length.// No return value.void saveLine (size_t* bufferLenPtr char** bufferPtrPtr char** endTextPtrPtr char** endBufferPtrPtr const char* line int lineIndex ){ // I. Application validity check: // II. Save line to *bufferPtrPtr: // II.A. Allocate more space if needed: if (lineIndex >= (*endBufferPtrPtr – *endTextPtrPtr + 1) ) { size_t textLen = *endTextPtrPtr – *bufferPtrPtr; (*bufferLenPtr) *= 2; (*bufferPtrPtr) = (char*)realloc(*bufferPtrPtr*bufferLenPtr); (*endTextPtrPtr) = *bufferPtrPtr + textLen; (*endBufferPtrPtr) = *bufferPtrPtr + *bufferLenPtr; } // II.B. Save line to *bufferPtrPtr: memcpy(*endTextPtrPtrlinelineIndex); (*endTextPtrPtr) += lineIndex; // III. Finished:}// PURPOSE: To attempt to compute the hashes of the text pointed to by// bufferPtr using the hash functions in HASH_TYPE_ARRAY[].// endTextPtr points to one char beyond the end of the text to print// in bufferPtr. No return value.//// SIDE EFFECT: Prints to messageWindow and sets process to receive// SIGALRM NUM_MESSAGE_SECS seconds in the future.// This will invoke sigAlarmHandler() which erases the// text in messageWindow.void computeHashes (const char* bufferPtr const char* endTextPtr ){ // I. Application validity check: // II. Compute hashes: // II.A. Each iteration computes one hash: int hashIndex; for (hashIndex = 0; hashIndex < NUM_HASH_TYPES; hashIndex++) { // II.A.1. Create pipes: int toChild[2]; int fromChild[2]; // YOUR CODE HERE to make 2 pipes // II.A.2. Do openssl process work: if (/* YOUR CODE HERE to make a child */ == 0) { // YOUR CODE HERE to handle child case exit(EXIT_FAILURE); } // II.A.3. Do parent work: int numBytes; int status; char text[INIT_TEXT_LEN]; const char* msgCPtr; // YOUR CODE HERE to handle parent case mvwaddstr(messageWindowhashIndex0HASH_TYPE_ARRAY[hashIndex]); waddstr(messageWindowmsgCPtr); wrefresh(messageWindow); } wrefresh(typingWindow); // moves cursor back to typingWindow: // YOUR CODE HERE to do one last thing // III. Finished:}// PURPOSE: To allow the user to type display what they type in// &apostypingWindow and to compute the hash upon pressing PRINT_CHAR.// vPtr comes in perhaps pointing to something. Returns NULL.void* type (void* vPtr ){ // I. Application validity check: // II. Handle user typing: unsigned int c; char line[WIDTH+1]; int index = 0; size_t bufferLen = INIT_TEXT_LEN; char* bufferPtr = (char*)malloc(bufferLen); char* endTextPtr = bufferPtr; char* endBufferPtr = bufferPtr + bufferLen; // II.A. Each iteration handles another typed char: while ( (c = getch()) != STOP_CHAR ) { // II.A.1. Handle special chars: if (c == \r) { // II.A.1.a. Treat carriage return like newline: c = \n; } else if ( (c == 0x7) || (c == 127) ) { // II.A.1.b. Handle backspace: int col = getcurx(typingWindow); if (col > 0) { index–; wmove(typingWindowgetcury(typingWindow)col-1); wrefresh(typingWindow); } continue; } else if (c == PRINT_CHAR) { size_t textLen = endTextPtr – bufferPtr; saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex); computeHashes(bufferPtrendTextPtr); endTextPtr = bufferPtr + textLen; continue; } else if (c == ERR) { continue; } // II.A.2. Print and record the char: waddch(typingWindowc); wrefresh(typingWindow); line[index++] = c; // II.A.3. Handle when save line: if (c == \n) { // II.A.3.a. Save line when user types newline: saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex); index = 0; } else if (index == WIDTH-1) { // II.A.3.b. Save line when at last column: line[index] = \n; index++; saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex); index = 0; waddch(typingWindow\n); wrefresh(typingWindow); } } // III. Finished: saveLine(&bufferLen&bufferPtr&endTextPtr&endBufferPtrlineindex);//int inFd = creat(TEXT_FILENAME0640);//write(inFdbufferPtrendTextPtr-bufferPtr);//close(inFd); free(bufferPtr); return(NULL);}// PURPOSE: To turn off ncurses. No parameters. No return value.void offNCurses (){ sleep(1); nl(); echo(); refresh(); delwin(messageWindow); delwin(typingWindow); delwin(checkingWindow); endwin();}// PURPOSE: To do the spell-checking word-processor. Ignores command line// arguments. Return EXIT_SUCCESS to OS.int main (){ struct sigaction act; // (2) YOUR CODE HERE to install sigAlarmHandler as the handler for SIGALRM onNCurses(); type(NULL); offNCurses(); return(EXIT_SUCCESS);} The action starts of course in main(). The first thing that main() should do is to install a simple signal handler:Signal: Handler to run:SIGALRM sigAlarmHandler()After that mainy-main:turns the windowing on (onNCurses() already done)lets the user type expressions (type() is done but it calls computeHashes() which you must finish)turns the windowing off (offNCurses() already done) turns the windowing on (onNCurses() already done) lets the user type expressions (type() is done but it calls computeHashes() which you must finish) turns the windowing off (offNCurses() already done) You must finish computeHashes(). It has a loop because it calls openssl twice once for SHA-224 and once for SHA-256. Both iterations use pipes to send the endTextPtr-outputBufferPtr bytes pointed to by outputBufferPtr to a child process running openssl.(Section II.A.1.) First create two pipes. We will use one for the parent to talk to the child and the other for the child to talk to the parent.(Section II.A.2.) Now make a child process. If we are the child process then be sure to:close() unnecessary pipe file descriptorsRedirect STDIN_FILENO to the input end of the appropriate pipe and redirect STDOUT_FILENO to the output end of the appropriate pipe.Run the hash program. The execl() program must specify the string constantsHASH_PROGRAM: The path of opensslHASH_TYPE_ARRAY[hashIndex]: Tells which hash to compute (SHA-224 or SHA-256)HASH_ARG: tells to give output in hexadecimalRemember:How many times do we specify the program name?What should the last argument to execl() be?Have exit(EXIT_FAILURE) after the execl() line. Why?(Section II.A.3.) Now handle the parent. If we are the parent process then be sure to:close() unnecessary pipe file descriptorsSend the endTextPtr-bufferPtr bytes of text pointed to by bufferPtr to the child. Then close() that file descriptor.Get the response from the child into text and wait() for the child to end (getting its return status).If the child successfully finished and read()ing its response was successful thenAdd a null-char just after the last byteSet msgCPtr to the occurence of “= ” in the text you read() (HINT Use strstr().)IF YOU HAVE A MAC: then just say this instead:msgCPtr = text;If the child did not successfully finish or read()ing the response was not successful then set msgCPtr = “Compute hash failed”The very last thing the function should do is alarm(NUM_MESSAGE_SECS) This tells it run sigAlarmHandler() NUM_MESSAGE_SECS seconds in the future. That function erases the hash-values. (Section II.A.1.) First create two pipes. We will use one for the parent to talk to the child and the other for the child to talk to the parent. (Section II.A.2.) Now make a child process. If we are the child process then be sure to:close() unnecessary pipe file descriptorsRedirect STDIN_FILENO to the input end of the appropriate pipe and redirect STDOUT_FILENO to the output end of the appropriate pipe.Run the hash program. The execl() program must specify the string constantsHASH_PROGRAM: The path of opensslHASH_TYPE_ARRAY[hashIndex]: Tells which hash to compute (SHA-224 or SHA-256)HASH_ARG: tells to give output in hexadecimalRemember:How many times do we specify the program name?What should the last argument to execl() be?Have exit(EXIT_FAILURE) after the execl() line. Why? close() unnecessary pipe file descriptors Redirect STDIN_FILENO to the input end of the appropriate pipe and redirect STDOUT_FILENO to the output end of the appropriate pipe. Run the hash program. The execl() program must specify the string constantsHASH_PROGRAM: The path of opensslHASH_TYPE_ARRAY[hashIndex]: Tells which hash to compute (SHA-224 or SHA-256)HASH_ARG: tells to give output in hexadecimalRemember:How many times do we specify the program name?What should the last argument to execl() be? HASH_PROGRAM: The path of openssl HASH_TYPE_ARRAY[hashIndex]: Tells which hash to compute (SHA-224 or SHA-256) HASH_ARG: tells to give output in hexadecimal How many times do we specify the program name? What should the last argument to execl() be? Have exit(EXIT_FAILURE) after the execl() line. Why? (Section II.A.3.) Now handle the parent. If we are the parent process then be sure to:close() unnecessary pipe file descriptorsSend the endTextPtr-bufferPtr bytes of text pointed to by bufferPtr to the child. Then close() that file descriptor.Get the response from the child into text and wait() for the child to end (getting its return status).If the child successfully finished and read()ing its response was successful thenAdd a null-char just after the last byteSet msgCPtr to the occurence of “= ” in the text you read() (HINT Use strstr().)IF YOU HAVE A MAC: then just say this instead:msgCPtr = text;If the child did not successfully finish or read()ing the response was not successful then set msgCPtr = “Compute hash failed” close() unnecessary pipe file descriptors Send the endTextPtr-bufferPtr bytes of text pointed to by bufferPtr to the child. Then close() that file descriptor. Get the response from the child into text and wait() for the child to end (getting its return status). If the child successfully finished and read()ing its response was successful thenAdd a null-char just after the last byteSet msgCPtr to the occurence of “= ” in the text you read() (HINT Use strstr().)IF YOU HAVE A MAC: then just say this instead:msgCPtr = text;If the child did not successfully finish or read()ing the response was not successful then set msgCPtr = “Compute hash failed” Add a null-char just after the last byte Set msgCPtr to the occurence of “= ” in the text you read() (HINT Use strstr().)IF YOU HAVE A MAC: then just say this instead:msgCPtr = text; The very last thing the function should do is alarm(NUM_MESSAGE_SECS) This tells it run sigAlarmHandler() NUM_MESSAGE_SECS seconds in the future. That function erases the hash-values. Add whatever variables you want (within reason). Now run the bad boy! Type something and press Ctrl-P to compute the hash. Press Esc to quit. PLEASE COPY-AND-PASTE THE FOLLOWING FILE (0 POINTS):wordProc_hash.c/*————————————————————————-* *— —* *— wordProc_hash.c —* *— —* *— A rudimentary word processor that prints the hash values of —* *— saved files. —* *— —* *— —- —- —- —- —- —- —- —- —* *— —* *— Version 1a 2020 January 1 Joseph Phillips —* *— —* *————————————————————————-*///// Compile with:// $ g++ wordProc_hash.c -o wordProc_hash -lncurses -g//// NOTE:// If this program crashes then you may not see what you type.// If that happens just type://// stty sane//// to your terminal even though you cannot even see it.//— —////— Header file inclusions: —////— —//#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h> // For alarm()#include <sys/socket.h>#include <sys/types.h> // For creat()#include <sys/wait.h> // For creat() wait()#include <sys/stat.h> // For creat()#include <fcntl.h> // For creat()#include <signal.h>#include <ncurses.h>//— —////— Definitions of constants: —////— —//#define HASH_PROGRAM “/usr/bin/openssl”#define HASH_ARG “-hex”#define STOP_CHARS “*+-#&”const char* HASH_TYPE_ARRAY[] = {“sha224″”sha256″};const int NUM_HASH_TYPES = sizeof(HASH_TYPE_ARRAY)/sizeof(char*);const int HEIGHT = 5;const int WIDTH = 72;const int INIT_TEXT_LEN = 1024;const int MAX_TEXT_LEN = 65536;const char STOP_CHAR = (char)27;const char PRINT_CHAR = (char)0x10;const int BUFFER_LEN = 64 * 16;const int TYPING_WINDOW_BAR_Y = 0;const int CHECKING_WINDOW_BAR_Y = TYPING_WINDOW_BAR_Y + HEIGHT + 1;const int MESSAGE_WINDOW_BAR_Y = CHECKING_WINDOW_BAR_Y + 1;const int NUM_MESSAGE_SECS = 6;//— —////— Definitions of global vars: —////— —//WINDOW* typingWindow;WINDOW* checkingWindow;WINDOW* messageWindow;pid_t childPid;int shouldRun = 1;//— —////— Definitions of global fncs: —////— —//// PURPOSE: To turn ncurses on. No parameters. No return value.void onNCurses (){ // I. Application validity check: // II. Turn ncurses on: initscr(); cbreak(); noecho(); nonl();//intrflush(stdscr FALSE);//keypad(stdscr TRUE); typingWindow = newwin(HEIGHTWIDTHTYPING_WINDOW_BAR_Y+11); checkingWindow = newwin(HEIGHTWIDTHCHECKING_WINDOW_BAR_Y+11); messageWindow = newwin( 2WIDTHMESSAGE_WINDOW_BAR_Y1); scrollok(typingWindowTRUE); scrollok(checkingWindowTRUE); mvaddstr(TYPING_WINDOW_BAR_Y0″Esc to quit. Ctrl-P to compute hashes.”); mvaddstr(CHECKING_WINDOW_BAR_Y0″Hashes:”); refresh(); wrefresh(typingWindow); // moves cursor back to typingWindow: // III. Finished:}// PURPOSE: To handle SIGALRM signals. Ignores sig (which will be// SIGALRM). No return value.void sigAlarmHandler (int sig ){ mvwaddstr (messageWindow00 ” ” ” ” ); mvwaddstr (messageWindow10 ” ” ” ” ); wrefresh(messageWindow); wrefresh(typingWindow); // moves cursor back to typingWindow:}// PURPOSE: To save the lineIndex chars at the beginning of line to// to position *endTextPtrPtr in buffer *bufferPtrPtr of length// *bufferLenPtr and with end *endBufferPtrPtr. If there is not// enough space in *bufferPtrPtr then *bufferLenPtr will be doubled// and *bufferPtrPtr will be realloc()-ed to this new length.// No return value.void saveLine (size_t* bufferLenPtr char** bufferPtrPtr char** endTextPtrPtr char** endBufferPtrPtr const char* line int lineIndex ){ // I. Application validity check: // II. Save line to *bufferPtrPtr: // II.A. Allocate more space if needed: if (lineIndex >= (*endBufferPtrPtr – *endTextPtrPtr + 1) ) { size_t textLen = *endTextPtrPtr – *bufferPtrPtr; (*bufferLenPtr) *= 2; (*bufferPtrPtr) = (char*)realloc(*bufferPtrPtr*bufferLenPtr); (*endTextPtrPtr) = *bufferPtrPtr + textLen; (*endBufferPtrPtr) = *bufferPtrPtr + *bufferLenPtr; } // II.B. Save line to *bufferPtrPtr: memcpy(*endTextPtrPtrlinelineIndex); (*endTextPtrPtr) += lineIndex; // III. Finished:}// PURPOSE: To attempt to compute the hashes of the text pointed to by// bufferPtr using the hash functions in HASH_TYPE_ARRAY[].// endTextPtr points to one char beyond the end of the text to print// in bufferPtr. No return value.//// SIDE EFFECT: Prints to messageWindow and sets process to receive// SIGALRM NUM_MESSAGE_SECS seconds in the future.// This will invoke sigAlarmHandler() which erases the// text in messageWindow.voi

Order a unique copy of this paper
(550 words)

Approximate price: $22

Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

We value our customers and so we ensure that what we do is 100% original..
With us you are guaranteed of quality work done by our qualified experts.Your information and everything that you do with us is kept completely confidential.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

The Product ordered is guaranteed to be original. Orders are checked by the most advanced anti-plagiarism software in the market to assure that the Product is 100% original. The Company has a zero tolerance policy for plagiarism.

Read more

Free-revision policy

The Free Revision policy is a courtesy service that the Company provides to help ensure Customer’s total satisfaction with the completed Order. To receive free revision the Company requires that the Customer provide the request within fourteen (14) days from the first completion date and within a period of thirty (30) days for dissertations.

Read more

Privacy policy

The Company is committed to protect the privacy of the Customer and it will never resell or share any of Customer’s personal information, including credit card data, with any third party. All the online transactions are processed through the secure and reliable online payment systems.

Read more

Fair-cooperation guarantee

By placing an order with us, you agree to the service we provide. We will endear to do all that it takes to deliver a comprehensive paper as per your requirements. We also count on your cooperation to ensure that we deliver on this mandate.

Read more

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency

Order your paper today and save 30% with the discount code HAPPY

X
error: Content is protected !!
Open chat
1
You can contact our live agent via WhatsApp! Via + 1 323 412 5597

Feel free to ask questions, clarifications, or discounts available when placing an order.