/* Assignment #5: stateless server Name: Don Southwell Date Due: November 13th, 2002 Class: CPS670 Program Description: This program is the client portion of the filecopy with sockets assignment. Program utilizes the passed UDP Datagram socket to request a file from a remote source server. Protocol utilized will send a request that contains: offset bytes in file, the number of bytes to read, and the absolute filepath of the file to read from. Server will respond to request by returning the number of bytes read and a 1494 byte data packet or (-1) for bytes read value if the file does not exist. A value of bytes read less than the packet size will determine end of file. The program will retry a request three times and then sleep for a specified duration if server response is still not received. If after two sleep cycles there is still no response from the server, the program will cleanup and exit. Some code snipets/sections used are copied from class examples per Dr. Rattan's cps670 class. Errors Handled: a) Error in setting up signal handler. b) Error in creation of local destination file. c) Error in sending file buffer request remote server. d) Error in receiving server response to file request. e) Error in server request timing out (alarm and sleep). f) Error in receipt from packet from incorrect server. Functions Used: (encapsulated within their own source files) void serr(char *) void copybyte(char *, char *, int) void sighandc(int) */ #include "inet.h" #define BUFSIZE 1496 #define PMODE 0755 void serr(char *); void sighandc(int); int initrcon(char *, char *); int checkargs(int, char *[]); struct sockaddr_in fservaddr; struct files { char filepath[1025]; char operation[5]; long offset; char *usage; char *eoflg; } filetab[30]; int main(int argc, char *argv[]) { struct sigaction act, oact; int sock; short sport; act.sa_handler = sighandc; sigemptyset(&act.sa_mask); act.sa_flags = 0; if (sigaction(SIGINT, &act, &oact) < 0) serr("Sigaction failed..."); /* check command line args */ if (checkargs(argc, argv) == -1) exit(-1); if ((sport = atoi(argv[2])) <= 0) serr("client: bad port..."); /* initialize the file table */ printf("this is where I would initialize the file table.."); /* initialize the socket connection */ if ((sock = initrcon(argv[1], argv[2])) == -1) serr("problem with socket.."); printf("sock = %d\n", sock); /* call doreads to process file reads from table */ printf("stub: doread"); close(sock); exit(0); }