source: rtems/cpukit/librpc/src/rpc/svc_simple.c @ 48b1e29

4.104.114.84.95
Last change on this file since 48b1e29 was 48b1e29, checked in by Joel Sherrill <joel.sherrill@…>, on 08/30/06 at 13:18:40

2006-08-30 Joel Sherrill <joel@…>

  • libcsupport/src/utsname.c, libnetworking/libc/res_debug.c, libnetworking/net/if_media.h, libnetworking/rtems/rtems_mii_ioctl.c, librpc/src/rpc/svc_simple.c: Remove printf format warnings.
  • Property mode set to 100644
File size: 4.4 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#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46#include <inttypes.h>
47#include <rpc/rpc.h>
48#include <rpc/pmap_clnt.h>
49#include <sys/socket.h>
50#include <netdb.h>
51
52#include <inttypes.h> /* for PRIxx printf formats */
53
54struct prog_lst {
55        char *(*p_progname)();
56        rpcprog_t  p_prognum;
57        rpcproc_t  p_procnum;
58        xdrproc_t p_inproc, p_outproc;
59        struct prog_lst *p_nxt;
60};
61static void universal();
62#define proglst (rtems_rpc_task_variables->svc_simple_proglst)
63#define pl (rtems_rpc_task_variables->svc_simple_pl)
64#define transp (rtems_rpc_task_variables->svc_simple_transp)
65
66int
67registerrpc(
68        int prognum,
69        int versnum,
70        int procnum,
71        char *(*progname)(),
72        xdrproc_t inproc,
73        xdrproc_t outproc )
74{
75
76        if (procnum == NULLPROC) {
77                (void) fprintf(stderr,
78                    "can't reassign procedure number %" PRIu32 "\n", NULLPROC);
79                return (-1);
80        }
81        if (transp == 0) {
82                transp = svcudp_create(RPC_ANYSOCK);
83                if (transp == NULL) {
84                        (void) fprintf(stderr, "couldn't create an rpc server\n");
85                        return (-1);
86                }
87        }
88        (void) pmap_unset((u_long)prognum, (u_long)versnum);
89        if (!svc_register(transp, (u_long)prognum, (u_long)versnum,
90            universal, IPPROTO_UDP)) {
91                (void) fprintf(stderr, "couldn't register prog %d vers %d\n",
92                    prognum, versnum);
93                return (-1);
94        }
95        pl = (struct prog_lst *)malloc(sizeof(struct prog_lst));
96        if (pl == NULL) {
97                (void) fprintf(stderr, "registerrpc: out of memory\n");
98                return (-1);
99        }
100        pl->p_progname = progname;
101        pl->p_prognum = prognum;
102        pl->p_procnum = procnum;
103        pl->p_inproc = inproc;
104        pl->p_outproc = outproc;
105        pl->p_nxt = proglst;
106        proglst = pl;
107        return (0);
108}
109
110static void
111universal(
112        struct svc_req *rqstp,
113        SVCXPRT *atransp )
114{
115        int prog, proc;
116        char *outdata;
117        char xdrbuf[UDPMSGSIZE];
118        struct prog_lst *lpl;
119
120        /*
121         * enforce "procnum 0 is echo" convention
122         */
123        if (rqstp->rq_proc == NULLPROC) {
124                if (svc_sendreply(atransp, (xdrproc_t) xdr_void, NULL) == FALSE) {
125                        (void) fprintf(stderr, "xxx\n");
126                        exit(1);
127                }
128                return;
129        }
130        prog = rqstp->rq_prog;
131        proc = rqstp->rq_proc;
132        for (lpl = proglst; lpl != NULL; lpl = lpl->p_nxt)
133                if (lpl->p_prognum == prog && lpl->p_procnum == proc) {
134                        /* decode arguments into a CLEAN buffer */
135                        memset(xdrbuf, 0, sizeof(xdrbuf)); /* required ! */
136                        if (!svc_getargs(atransp, lpl->p_inproc, xdrbuf)) {
137                                svcerr_decode(atransp);
138                                return;
139                        }
140                        outdata = (*(lpl->p_progname))(xdrbuf);
141                        if (outdata == NULL &&
142                            lpl->p_outproc != (xdrproc_t) xdr_void)
143                                /* there was an error */
144                                return;
145                        if (!svc_sendreply(atransp, lpl->p_outproc, outdata)) {
146                                (void) fprintf(stderr,
147                                    "trouble replying to prog %" PRIu32 "\n",
148                                    lpl->p_prognum);
149                                exit(1);
150                        }
151                        /* free the decoded arguments */
152                        (void)svc_freeargs(atransp, lpl->p_inproc, xdrbuf);
153                        return;
154                }
155        (void) fprintf(stderr, "never registered prog %d\n", prog);
156        exit(1);
157}
Note: See TracBrowser for help on using the repository browser.