void stdinCallback(int fd,short int revent, short int* gotEvents, void* dummy) { /* this function gets triggered by the ncurses library upon *any* keystroke from user (for handling of Ctrl-C and Ctrl-\ see function finish()) */ static int t; unsigned char c; char buffer[MAX_BUFFER_LENGTH]; /* call ncurses function wgetch() to read in one user keystroke. Did not use the wgetstr() function because it blocks until the user# terminates with a end-of-line (return) key. This prevents the SCTP library from sending out heartbeats, as well as queuing other callbacks waiting for this potentially long function to terminate. */ c=wgetch(selfWin); switch (c) { case ERR: sctp_shutdown(associationID); endwin(); break; /* ascii code for return key is 13 */ case 13: buf[bufCount++]='\n'; buf[bufCount++]=0; strcpy(buffer,usrid); /* adds the user ID into buffer */ buffer[usrid_len] = '\0'; strcat(buffer,"# "); strcat(buffer, (char *)buf); /* adds the contents of buf into buffer */ sctp_send(associationID, 0, (unsigned char *)buffer, strlen(buffer), SCTP_GENERIC_PAYLOAD_PROTOCOL_ID, SCTP_USE_PRIMARY, SCTP_NO_CONTEXT, SCTP_INFINITE_LIFETIME, SCTP_ORDERED_DELIVERY, SCTP_BUNDLING_DISABLED); bufCount=0; waddch(selfWin,'\n'); wrefresh(selfWin); t=0; break; default: if (bufCount<MAX_BUFFER_LENGTH); { buf[bufCount++]=c; waddch(selfWin,c); wrefresh(selfWin); } } }
int SCTP_shutdown(unsigned int associationID) { int result; if ((result = sctp_shutdown(associationID))!= SCTP_SUCCESS) { if (result == SCTP_LIBRARY_NOT_INITIALIZED) { fprintf(stderr, "sctp_shutdown: library not initialized.\n"); } else if (result == SCTP_ASSOC_NOT_FOUND) { fprintf(stderr, "sctp_shutdown: association not found.\n"); } fflush(stderr); } return result; }
static void finish(int sig) { waddstr(statusWin," Terminating Monitoring tool..."); /* calls sctp_shutdown() to close the association. waits for the receipt of the shutdown notification before terminating the program */ if (sctp_shutdown(associationID)==0) waddstr(statusWin,"successful\n"); else { waddstr(statusWin,"failed\n"); /* the program should exit here as the shutdownComplete notification will not be produced in this case */ endwin(); exit(0); } wrefresh(statusWin); }
void stdinCallback(int fd, short int revents, short int* gotEvents, void* dummy) { /* This function gets triggered by the ncurses library upon *any* keystroke from user (for handling of Ctrl-C, see function finish()) */ int key; static unsigned short outstreamID = 0; SCTP_AssociationStatus assocStatus; /* call ncurses function wgetch() to read in one user keystroke. Did not use the wgetstr() function because it blocks until the user# terminates with a end-of-line (return) key. This prevents the SCTP library from sending out heartbeats, as well as queuing other callbacks waiting for this potentially long function to terminate. */ key = wgetch(textWin); switch (key) { case ERR: sctp_shutdown(associationID); endwin(); break; /* ascii code for return key is 13 */ case 13: case KEY_ENTER: buffer[bufCount++]='\n'; buffer[bufCount++]=0; /* Increment the Stream ID by 1 everytime data is sent, if stream ID = largest stream ID assigned, reset stream ID to 0 */ if (outstreamID == statusUpdate.noOfOutStreams) outstreamID = 0; sctp_send(associationID, outstreamID, (unsigned char *)buffer, strlen(buffer), SCTP_GENERIC_PAYLOAD_PROTOCOL_ID, SCTP_USE_PRIMARY, SCTP_NO_CONTEXT, SCTP_INFINITE_LIFETIME, SCTP_ORDERED_DELIVERY, SCTP_BUNDLING_DISABLED); /* Update the Outstream ID list in Monitor tool structure */ if (statusUpdate.OutstreamIDList[outstreamID] == -1) statusUpdate.OutstreamIDList[outstreamID] = outstreamID; /* Update the current position of OutstreamIDList array */ currOutstreamID = outstreamID; /* update the display */ ncurses_display_AssocStatus(associationID); outstreamID ++; waddch(textWin,'\n'); wrefresh(textWin); bufCount=0; break; case KEY_BACKSPACE: displayPathDetails = 0; ncurses_display_PathStatus(associationID); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* ascii code for key '0' is 48, key '1' is 49 and so fro..... therefore, key - 48 will return the value of the Path ID chosen */ chosenPath = key - 48; displayPathDetails = 1; sctp_getAssocStatus(associationID,&assocStatus); if (chosenPath < assocStatus.numberOfAddresses) ncurses_display_PathStatus(associationID); break; case KEY_RESIZE: endwin(); initializecurses(); wrefresh(statusWin); /* Display Functions*/ ncurses_display_AssocStatus(associationID); ncurses_display_PathStatus(associationID); break; default: if (bufCount<SCTP_MAXIMUM_DATA_LENGTH); { buffer[bufCount++]= key; waddch(textWin, key); wrefresh(textWin); } } }