/* Assignment #5: Stateless Server Name: Don Southwell Date Due: November 13, 2002 Class: CPS670 Program Description: This is the client portion of the stateless server file copy assignment. Program performs initial addressing structure setup, opens communication with a UDP Datagram socket running on the server, binds the created socket and then calls the client function to handle the copy request. Remote source and local destination file names are passed as command line arguments along with the server IP address, server port, alarm time for retries and sleep if server is unavailable. Execution syntax is as follows: copy \ Problem Description: Write a structured modular program that utilizes command line arguments to process a remote character string (file). Using sockets, the udpclient program connects to the server and initiates a client call that processes the file copy request. In this case, we have written the client program to track the transfer process and are not maintaining the state of the transfer on the server machine. This utilization of a 'stateless' server allows us the ability to resume stuck transfers and recover the file copy process without reinitializing and restarting the file transfer from the beginning. This is particularly desirable when moving large files. Error messages are written to stderr (via the serr module) and "BSD" style programming is adhered to. Some Code fragments/sections copied from Dr. Rattan's provided sources. Errors Handled: a) Incorrect number of arguments. b) Port creation failure. c) Socket creation failure. d) Bind failure. e) Socket close failure. Functions Used: (encapsulated within their own source files) a) void client(int, SA *, int, char *, char *) b) int checkargs(char *, char *) c) void serr(char *) */ #include "inet.h" void serr(char *); void client(int, int, char *, char *, int, int); int checkargs(int, char*[]); struct sockaddr_in fservaddr; /* file server address */ int main(int argc, char *argv[]) { struct sockaddr_in fromaddr; int sock; /* Socket descriptor */ short sport; /* request server port */ if (checkargs(argc, argv) == -1) exit(-1); if ((sport = atoi(argv[2])) <= 0) serr("client: bad port"); memset(&fservaddr, 0, sizeof(fservaddr)); fservaddr.sin_family = AF_INET; if ((fservaddr.sin_addr.s_addr = inet_addr(argv[1])) == -1) serr("Error:client: invalid server ip address..."); fservaddr.sin_port = htons(sport); if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) serr("socket() failed"); bzero((char *) &fromaddr, sizeof(fromaddr)); fromaddr.sin_family = AF_INET; fromaddr.sin_addr.s_addr = htonl(INADDR_ANY); fromaddr.sin_port = htons(0); if (bind(sock, (SA *) &fromaddr, sizeof(fromaddr)) < 0) serr("udpclient: cannot bind local address"); client(sock, sizeof(fservaddr), argv[3], argv[4], (int) argv[5], (int) argv[6]); if (close(sock) < 0) serr("udpclient: socket close error"); exit(0); }