/************************************************************************ * Boston University * CS 555 -- Fall 2003 * * The interfaces for the SRMP sender (you get to implement them), and a * simple application-level routine to drive the sender. * * This routine reads the data to be transferred over the connection * from a file specified and invokes the SRMP send functionality to * deliver the packets as an ordered sequence of datagrams. * * Version 1.0 * * *************************************************************************/ #include #include #include #include #include "srmp.h" #define SRMP_ERROR -1 typedef struct{ int DELETE_ME; /* used only to make this compile */ /* YOUR CODE HERE */ }srmp_send_ctrl_blk; /* YOUR CODE HERE (if needed) */ /* * Send a message using SRMP. * The main entry point to the (not yet implemented) sender-side of the protocol. */ int srmp_send (srmp_send_ctrl_blk *srmp_CB, char* data, int len) { /* YOUR CODE HERE */ } /* * Open the sender side of the SRMP connection. * */ int srmp_open(srmp_send_ctrl_blk * srmp_CB, char *dst, int sport, int rport) { /* YOUR CODE HERE */ } /* * Close the sender side of the SRMP connection after all data transmitted. * */ int srmp_close(srmp_send_ctrl_blk *srmp_CB) { /* YOUR CODE HERE */ } /***************************************************************/ /* This application is to invoke the send-side functionality. */ /* Feel free to rewrite or write your own application to */ /* test your code. */ /* */ /***************************************************************/ int main(int argc, char **argv) { srmp_send_ctrl_blk *srmp_CB; char * dst; int recv_port, send_port; int file; int ret_val; /* Verify that the arguments are right*/ if (argc != 5) { fprintf(stderr, "usage: SendApp receiver-IP-address recv-port send-port filename \n"); exit(1); } /************************************************************/ /* */ /* Open connection to destination. If srmp_open succeeds */ /* the srmp_CB should be correctly initialized */ /* */ /************************************************************/ srmp_CB = (srmp_send_ctrl_blk *) malloc (sizeof( *srmp_CB)); dst = argv[1]; recv_port = atoi(argv[2]); send_port = atoi(argv[3]); ret_val = srmp_open(srmp_CB, dst, send_port, recv_port); if( ret_val == SRMP_ERROR ) { /* YOUR CODE HERE */ } /************************************************************/ /* */ /* Open file for transfer */ /* */ /************************************************************/ file = open(argv[4], O_RDONLY); if (file < 0) { perror(argv[4]); exit(1); } /************************************************************/ /* */ /* Start to send data in file via SRMP to remote receiver */ /* */ /************************************************************/ /************************************************************/ /* */ /* Chop up the file into pieces half as large as max */ /* packet size ... and transmit those pieces. */ /* */ /************************************************************/ while(1) { char wrk[SRMP_MAXPKT / 2]; int cc = read(file, wrk, sizeof(wrk)); /* Break when EOF is reached */ if(cc <= 0) break; if(srmp_send(srmp_CB, wrk, cc) == SRMP_ERROR) { /* YOUR CODE HERE */ } } /************************************************************/ /* */ /* Close the connection to remote receiver */ /* */ /************************************************************/ if (srmp_close(srmp_CB) == SRMP_ERROR) { /* YOUR CODE HERE */ } return 0; }