/* RPC server program for UNIX systems. * * The program supports version 1 and 2 of the server. * Version 1 consists of the function "RetString" and version 2 * of the functions "RetString", "RetSquare", and "ShutDownServer". * * "rpcgen" changes function names, return types, and types of * function parameters. Furthermore it adds a new function parameter * to all functions (compare rpctst.x and rpctst.h). It generates * one set of function prototypes for the client and another one for * the server ("_svc" appended to the function name. NOT IN CYGWIN !). * The implementation must take care of these changes. * * Start "rpctst_server" before you start "rpctst_client. Start the * server and the client in different windows. * * SunOS (Solaris) starts the server automatically as background * procecss, so that you wouldn't see any output from the server. * If you want to test the server you can uncomment RPC_SVC_FG in * GNUmakefile. * * * * File: rpctst_server.c Author: S. Gross * Date: 05.10.2004 * */ #include #include #include #include #include #include "rpctst.h" #define BUF_SIZE 80 #ifdef Cygwin #define retstring_1_svc retstring_1 #define retstring_2_svc retstring_2 #define retsquare_2_svc retsquare_2 #define shutdownserver_2_svc shutdownserver_2 #endif char **retstring_1_svc (void *argp, struct svc_req *rqstp) { static char buffer [BUF_SIZE]; static char *bufPtr; struct utsname sys_info; /* system information */ printf ("RPC server version 1: RetString() called\n"); uname (&sys_info); strcpy (buffer, "Greetings from "); strncpy (buffer + strlen (buffer), sys_info.nodename, BUF_SIZE - strlen (buffer)); strncpy (buffer + strlen (buffer), " (Version 1)", BUF_SIZE - strlen (buffer)); bufPtr = buffer; return &bufPtr; } int rpctest_1_freeresult (SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) { return 0; } char **retstring_2_svc (void *argp, struct svc_req *rqstp) { static char buffer [BUF_SIZE]; static char *bufPtr; struct utsname sys_info; /* system information */ printf ("RPC server version 2: RetString() called\n"); uname (&sys_info); strcpy (buffer, "Greetings from "); strncpy (buffer + strlen (buffer), sys_info.nodename, BUF_SIZE - strlen (buffer)); strncpy (buffer + strlen (buffer), " (Version 2)", BUF_SIZE - strlen (buffer)); bufPtr = buffer; return &bufPtr; } long *retsquare_2_svc (long *val, struct svc_req *rqstp) { static long square; printf ("RPC server version 2: RetSquare() called\n"); square = *val * *val; return □ } void *shutdownserver_2_svc (void *argp, struct svc_req *rqstp) { printf ("RPC server version 2: ShutDownServer() called\n"); raise (SIGHUP); return (void *) NULL; } int rpctest_2_freeresult (SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) { return 0; }