1 /*********************************************************************
2 * RPC for the Windows NT Operating System
3 * 1993 by Martin F. Gergeleit
4 * Users may use, copy or modify Sun RPC for the Windows NT Operating
5 * System according to the Sun copyright below.
7 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
8 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
9 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10 *********************************************************************/
12 /* @(#)svc_simple.c 2.2 88/08/01 4.0 RPCSRC */
14 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
15 * unrestricted use provided that this legend is included on all tape
16 * media and as a part of the software program in whole or part. Users
17 * may copy or modify Sun RPC without charge, but are not authorized
18 * to license or distribute it to anyone else except as part of a product or
19 * program developed by the user.
21 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
22 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
25 * Sun RPC is provided with no support and without any obligation on the
26 * part of Sun Microsystems, Inc. to assist in its use, correction,
27 * modification or enhancement.
29 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
30 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
31 * OR ANY PART THEREOF.
33 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
34 * or profits or other special, indirect and consequential damages, even if
35 * Sun has been advised of the possibility of such damages.
37 * Sun Microsystems, Inc.
39 * Mountain View, California 94043
41 #if !defined(lint) && defined(SCCSIDS)
42 static char sccsid[] = "@(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";
47 * Simplified front end to rpc.
49 * Copyright (C) 1984, Sun Microsystems, Inc.
55 #include <sys/socket.h>
59 static struct proglst {
60 char *(*p_progname)();
63 xdrproc_t p_inproc, p_outproc;
64 struct proglst *p_nxt;
66 static void universal();
67 static SVCXPRT *transp;
70 registerrpc(prognum, versnum, procnum, progname, inproc, outproc)
72 xdrproc_t inproc, outproc;
75 if (procnum == NULLPROC) {
78 "can't reassign procedure number 0\n");
80 (void) fprintf(stderr,
81 "can't reassign procedure number %d\n", NULLPROC);
86 transp = svcudp_create(RPC_ANYSOCK);
89 nt_rpc_report("couldn't create an rpc server\n");
91 (void) fprintf(stderr, "couldn't create an rpc server\n");
96 (void) pmap_unset((u_long)prognum, (u_long)versnum);
97 if (!svc_register(transp, (u_long)prognum, (u_long)versnum,
98 universal, IPPROTO_UDP)) {
100 nt_rpc_report("couldn't register prog");
102 (void) fprintf(stderr, "couldn't register prog %d vers %d\n",
107 pl = (struct proglst *)malloc(sizeof(struct proglst));
110 nt_rpc_report("registerrpc: out of memory\n");
112 (void) fprintf(stderr, "registerrpc: out of memory\n");
116 pl->p_progname = progname;
117 pl->p_prognum = prognum;
118 pl->p_procnum = procnum;
119 pl->p_inproc = inproc;
120 pl->p_outproc = outproc;
127 universal(rqstp, transp)
128 struct svc_req *rqstp;
133 char xdrbuf[UDPMSGSIZE];
137 * enforce "procnum 0 is echo" convention
139 if (rqstp->rq_proc == NULLPROC) {
140 if (svc_sendreply(transp, xdr_void, (char *)NULL) == FALSE) {
142 nt_rpc_report(stderr, "xxx\n");
144 (void) fprintf(stderr, "xxx\n");
150 prog = rqstp->rq_prog;
151 proc = rqstp->rq_proc;
152 for (pl = proglst; pl != NULL; pl = pl->p_nxt)
153 if (pl->p_prognum == prog && pl->p_procnum == proc) {
154 /* decode arguments into a CLEAN buffer */
155 bzero(xdrbuf, sizeof(xdrbuf)); /* required ! */
156 if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
157 svcerr_decode(transp);
160 outdata = (*(pl->p_progname))(xdrbuf);
161 if (outdata == NULL && pl->p_outproc != xdr_void)
162 /* there was an error */
164 if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
167 "trouble replying to prog\n"
168 /*, pl->p_prognum*/);
170 (void) fprintf(stderr,
171 "trouble replying to prog %d\n",
176 /* free the decoded arguments */
177 (void)svc_freeargs(transp, pl->p_inproc, xdrbuf);
181 nt_rpc_report("never registered prog %d\n"/*, prog*/);
183 (void) fprintf(stderr, "never registered prog %d\n", prog);