source: rtems-libbsd/services/librpc/src/rpc/svc_simple.c @ cd450d2

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since cd450d2 was cd450d2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/06/12 at 00:10:35

librpc: now compiles

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part.  Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";*/
32/*static char *sccsid = "from: @(#)svc_simple.c 2.2 88/08/01 4.0 RPCSRC";*/
33static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc_simple.c,v 1.9 1999/08/28 00:00:50 peter Exp $";
34#endif
35
36/*
37 * svc_simple.c
38 * Simplified front end to rpc.
39 *
40 * Copyright (C) 1984, Sun Microsystems, Inc.
41 */
42
43#ifdef HAVE_CONFIG_H
44#include "config.h"
45#endif
46
47#include <freebsd/bsd.h>
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51#include <inttypes.h>
52#include <rpc/rpc.h>
53#include <rpc/pmap_clnt.h>
54#include <sys/socket.h>
55#include <netdb.h>
56
57#include <inttypes.h> /* for PRIxx printf formats */
58#ifdef __rtems__
59#include <rpc/rpc_rtems.h>
60#endif
61
62struct prog_lst {
63        char *(*p_progname)(char *);
64        rpcprog_t  p_prognum;
65        rpcproc_t  p_procnum;
66        xdrproc_t p_inproc, p_outproc;
67        struct prog_lst *p_nxt;
68};
69static void universal(struct svc_req *, SVCXPRT *);
70#define proglst (rtems_rpc_task_variables->svc_simple_proglst)
71#define pl (rtems_rpc_task_variables->svc_simple_pl)
72#define transp (rtems_rpc_task_variables->svc_simple_transp)
73
74int
75registerrpc(
76        int prognum,
77        int versnum,
78        int procnum,
79        char *(*progname)(char *),
80        xdrproc_t inproc,
81        xdrproc_t outproc )
82{
83
84        if (procnum == NULLPROC) {
85                (void) fprintf(stderr,
86                    "can't reassign procedure number %" PRIu32 "\n", NULLPROC);
87                return (-1);
88        }
89        if (transp == 0) {
90                transp = svcudp_create(RPC_ANYSOCK);
91                if (transp == NULL) {
92                        (void) fprintf(stderr, "couldn't create an rpc server\n");
93                        return (-1);
94                }
95        }
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)) {
99                (void) fprintf(stderr, "couldn't register prog %d vers %d\n",
100                    prognum, versnum);
101                return (-1);
102        }
103        pl = (struct prog_lst *)malloc(sizeof(struct prog_lst));
104        if (pl == NULL) {
105                (void) fprintf(stderr, "registerrpc: out of memory\n");
106                return (-1);
107        }
108        pl->p_progname = progname;
109        pl->p_prognum = prognum;
110        pl->p_procnum = procnum;
111        pl->p_inproc = inproc;
112        pl->p_outproc = outproc;
113        pl->p_nxt = proglst;
114        proglst = pl;
115        return (0);
116}
117
118static void
119universal(
120        struct svc_req *rqstp,
121        SVCXPRT *atransp )
122{
123        int prog, proc;
124        char *outdata;
125        char xdrbuf[UDPMSGSIZE];
126        struct prog_lst *lpl;
127
128        /*
129         * enforce "procnum 0 is echo" convention
130         */
131        if (rqstp->rq_proc == NULLPROC) {
132                if (svc_sendreply(atransp, (xdrproc_t) xdr_void, NULL) == FALSE) {
133                        (void) fprintf(stderr, "xxx\n");
134                        exit(1);
135                }
136                return;
137        }
138        prog = rqstp->rq_prog;
139        proc = rqstp->rq_proc;
140        for (lpl = proglst; lpl != NULL; lpl = lpl->p_nxt)
141                if (lpl->p_prognum == prog && lpl->p_procnum == proc) {
142                        /* decode arguments into a CLEAN buffer */
143                        memset(xdrbuf, 0, sizeof(xdrbuf)); /* required ! */
144                        if (!svc_getargs(atransp, lpl->p_inproc, xdrbuf)) {
145                                svcerr_decode(atransp);
146                                return;
147                        }
148                        outdata = (*(lpl->p_progname))(xdrbuf);
149                        if (outdata == NULL &&
150                            lpl->p_outproc != (xdrproc_t) xdr_void)
151                                /* there was an error */
152                                return;
153                        if (!svc_sendreply(atransp, lpl->p_outproc, outdata)) {
154                                (void) fprintf(stderr,
155                                    "trouble replying to prog %" PRIu32 "\n",
156                                    lpl->p_prognum);
157                                exit(1);
158                        }
159                        /* free the decoded arguments */
160                        (void)svc_freeargs(atransp, lpl->p_inproc, xdrbuf);
161                        return;
162                }
163        (void) fprintf(stderr, "never registered prog %d\n", prog);
164        exit(1);
165}
Note: See TracBrowser for help on using the repository browser.