/* ** File name: GETSYI_SVC.C ** ** Copyright (c) 1991, by ** Process Software Corporation ** Framingham, Massachusetts */ /* ** Except for the comments and the line that enables the use of normal ports, ** this file is the output of RPCGEN. ** It is created by any of these commands: ** rpcgen -m -o getsyi_svc.c getsyi.x ** rpcgen -s udp -s tcp -o getsyi_svc.c getsyi.x ** rpcgen getsyi */ #include #include "TCPWARE_INCLUDE:RPC.H" #include "GETSYI.H" static void getsyi_prog_1(); /******************** main program ********************/ main() { SVCXPRT *transp; /* ** The server will use non-privileged ports. RPCGEN does not create this line. */ oncrpc_set_char( RPCCHAR__DEFPORTS, &RPCPORTS__NORMAL); /* ** Remove any previous mapping of our program and version numbers to a port. ** This is done for each version. */ pmap_unset( GETSYI_PROG, GETSYI_VERS_1); /* ** Create the transports and register them with the Port Mapper. RPCGEN can ** not enable the XID cache for UDP. svcudp_create is called with RPC_ANYSOCK ** so that the server will use a port that the RPC library assigns to it. To ** use only the UDP transport, run RPCGEN with: ** rpcgen -s udp -o getsyi_svc.c getsyi.x ** The same may be done for the TCP transport. RPCGEN does not support the ** UDPA or TCPA transports. */ transp = svcudp_create( RPC_ANYSOCK); if( transp == NULL) { fprintf( stderr, "cannot create udp service.\n"); exit( 724); /* error SS$_OPINCOMPL */ } /* ** Each version of the server must be registered with the Port Mapper. Each ** version would typically have its own dispatch routine. */ if( !svc_register( transp, GETSYI_PROG, GETSYI_VERS_1, getsyi_prog_1, IPPROTO_UDP)) { fprintf( stderr, "unable to register (GETSYI_PROG, GETSYI_VERS_1, udp).\n"); exit( 724); } /* ** The TCP transport is handled like the UDP transport above. */ transp = svctcp_create( RPC_ANYSOCK, 0, 0); if( transp == NULL) { fprintf( stderr, "cannot create tcp service.\n"); exit( 724); } if( !svc_register( transp, GETSYI_PROG, GETSYI_VERS_1, getsyi_prog_1, IPPROTO_TCP)) { fprintf( stderr, "unable to register (GETSYI_PROG, GETSYI_VERS_1, tcp).\n"); exit( 724); } /* ** Wait for clients to send requests. svc_run should never return. */ svc_run(); fprintf( stderr, "svc_run returned\n"); exit( 44); /* SS$_ABORT */ } /* ** This is the dispatch routine for version 1 of the getsyi server. Generally, ** each version of the server would have its own dispatch routine. */ /******************** getsyi_prog_1() ********************/ static void getsyi_prog_1( rqstp, transp) struct svc_req *rqstp; SVCXPRT *transp; { union { getsyi_args getsyi_proc_1_1_arg; } argument; char *result; bool_t (*xdr_argument)(), (*xdr_result)(); char *(*local)(); switch( rqstp->rq_proc) { /* ** RPCGEN automatically sets the null procedure (NULLPROC) up to do nothing ** and return a void. */ case NULLPROC: svc_sendreply( transp, xdr_void, NULL); return; /* ** For each supported procedure, save the XDR functions for the arguments and ** the results for later use. Also, save the address of the function that will ** implement the procedure. */ case GETSYI_PROC_1: xdr_argument = xdr_getsyi_args; xdr_result = xdr_getsyi_res; local = (char *(*)()) getsyi_proc_1_1; break; /* ** The client specified a procedure that the server doesn't support. */ default: svcerr_noproc( transp); return; } /* ** Zero the arguments structure so that memory will be allocated if needed. ** (See GETSYI_CLNT.C) */ bzero( &argument, sizeof(argument)); if( !svc_getargs( transp, xdr_argument, &argument)) { svcerr_decode( transp); return; } /* ** Call the function to implement the procedure. This function is located in ** GETSYI_PROC_S.C. A return value of 0 means that a reply should not be sent ** to the client. */ result = (*local)(&argument, rqstp); if( result != NULL && !svc_sendreply( transp, xdr_result, result)) svcerr_systemerr( transp); /* ** Free the memory that was allocated when the arguments were decoded. */ if( !svc_freeargs( transp, xdr_argument, &argument)) { fprintf( stderr, "unable to free arguments\n"); exit( 44); } } /* end file GETSYI_SVC.C */