about summary refs log tree commit diff
path: root/sunrpc/svc_simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'sunrpc/svc_simple.c')
-rw-r--r--sunrpc/svc_simple.c184
1 files changed, 98 insertions, 86 deletions
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index 0a30c45b42..cc28f6a7e3 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -39,105 +39,117 @@ static char sccsid[] = "@(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
 #include <sys/socket.h>
 #include <netdb.h>
 
-static struct proglst {
-	char *(*p_progname)();
-	int  p_prognum;
-	int  p_procnum;
-	xdrproc_t p_inproc, p_outproc;
-	struct proglst *p_nxt;
-} *proglst;
-static void universal();
+static struct proglst
+  {
+    char *(*p_progname) (char *);
+    int p_prognum;
+    int p_procnum;
+    xdrproc_t p_inproc, p_outproc;
+    struct proglst *p_nxt;
+  }
+ *proglst;
+
+static void universal (struct svc_req *rqstp, SVCXPRT *transp);
 static SVCXPRT *transp;
 
-registerrpc(prognum, versnum, procnum, progname, inproc, outproc)
-	char *(*progname)();
-	xdrproc_t inproc, outproc;
+int
+registerrpc (u_long prognum, u_long versnum, u_long procnum,
+	     char *(*progname) (char *), xdrproc_t inproc, xdrproc_t outproc)
 {
-	struct proglst *pl;
+  struct proglst *pl;
 
-	if (procnum == NULLPROC) {
-		(void) fprintf(stderr,
-		    _("can't reassign procedure number %d\n"), NULLPROC);
-		return (-1);
-	}
-	if (transp == 0) {
-		transp = svcudp_create(RPC_ANYSOCK);
-		if (transp == NULL) {
-			(void) fprintf(stderr, _("couldn't create an rpc server\n"));
-			return (-1);
-		}
-	}
-	(void) pmap_unset((u_long)prognum, (u_long)versnum);
-	if (!svc_register(transp, (u_long)prognum, (u_long)versnum,
-	    universal, IPPROTO_UDP)) {
-	    	(void) fprintf(stderr, _("couldn't register prog %d vers %d\n"),
-		    prognum, versnum);
-		return (-1);
+  if (procnum == NULLPROC)
+    {
+      (void) fprintf (stderr,
+		      _("can't reassign procedure number %d\n"), NULLPROC);
+      return -1;
+    }
+  if (transp == 0)
+    {
+      transp = svcudp_create (RPC_ANYSOCK);
+      if (transp == NULL)
+	{
+	  (void) fputs (_("couldn't create an rpc server\n"), stderr);
+	  return -1;
 	}
-	pl = (struct proglst *)malloc(sizeof(struct proglst));
-	if (pl == NULL) {
-		(void) fprintf(stderr, _("registerrpc: out of memory\n"));
-		return (-1);
-	}
-	pl->p_progname = progname;
-	pl->p_prognum = prognum;
-	pl->p_procnum = procnum;
-	pl->p_inproc = inproc;
-	pl->p_outproc = outproc;
-	pl->p_nxt = proglst;
-	proglst = pl;
-	return (0);
+    }
+  (void) pmap_unset ((u_long) prognum, (u_long) versnum);
+  if (!svc_register (transp, (u_long) prognum, (u_long) versnum,
+		     universal, IPPROTO_UDP))
+    {
+      (void) fprintf (stderr, _("couldn't register prog %d vers %d\n"),
+		      prognum, versnum);
+      return -1;
+    }
+  pl = (struct proglst *) malloc (sizeof (struct proglst));
+  if (pl == NULL)
+    {
+      (void) fprintf (stderr, _("registerrpc: out of memory\n"));
+      return -1;
+    }
+  pl->p_progname = progname;
+  pl->p_prognum = prognum;
+  pl->p_procnum = procnum;
+  pl->p_inproc = inproc;
+  pl->p_outproc = outproc;
+  pl->p_nxt = proglst;
+  proglst = pl;
+  return 0;
 }
 
 static void
-universal(rqstp, transp)
-	struct svc_req *rqstp;
-	SVCXPRT *transp;
+universal (struct svc_req *rqstp, SVCXPRT *transp)
 {
-	int prog, proc;
-	char *outdata;
-	char xdrbuf[UDPMSGSIZE];
-	struct proglst *pl;
+  int prog, proc;
+  char *outdata;
+  char xdrbuf[UDPMSGSIZE];
+  struct proglst *pl;
 
-	/*
-	 * enforce "procnum 0 is echo" convention
-	 */
-	if (rqstp->rq_proc == NULLPROC) {
-		if (svc_sendreply(transp, xdr_void, (char *)NULL) == FALSE) {
-			(void) fprintf(stderr, "xxx\n");
-			exit(1);
-		}
-		return;
+  /*
+   * enforce "procnum 0 is echo" convention
+   */
+  if (rqstp->rq_proc == NULLPROC)
+    {
+      if (svc_sendreply (transp, (xdrproc_t)xdr_void, (char *) NULL) == FALSE)
+	{
+	  (void) fprintf (stderr, "xxx\n");
+	  exit (1);
 	}
-	prog = rqstp->rq_prog;
-	proc = rqstp->rq_proc;
-	for (pl = proglst; pl != NULL; pl = pl->p_nxt)
-		if (pl->p_prognum == prog && pl->p_procnum == proc) {
-			/* decode arguments into a CLEAN buffer */
-			bzero(xdrbuf, sizeof(xdrbuf)); /* required ! */
-			if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
-				svcerr_decode(transp);
-				return;
-			}
-			outdata = (*(pl->p_progname))(xdrbuf);
-			if (outdata == NULL && pl->p_outproc != xdr_void)
-				/* there was an error */
-				return;
-			if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
-				(void) fprintf(stderr,
-				    _("trouble replying to prog %d\n"),
-				    pl->p_prognum);
-				exit(1);
-			}
-			/* free the decoded arguments */
-			(void)svc_freeargs(transp, pl->p_inproc, xdrbuf);
-			return;
-		}
-	(void) fprintf(stderr, _("never registered prog %d\n"), prog);
-	exit(1);
+      return;
+    }
+  prog = rqstp->rq_prog;
+  proc = rqstp->rq_proc;
+  for (pl = proglst; pl != NULL; pl = pl->p_nxt)
+    if (pl->p_prognum == prog && pl->p_procnum == proc)
+      {
+	/* decode arguments into a CLEAN buffer */
+	bzero (xdrbuf, sizeof (xdrbuf));	/* required ! */
+	if (!svc_getargs (transp, pl->p_inproc, xdrbuf))
+	  {
+	    svcerr_decode (transp);
+	    return;
+	  }
+	outdata = (*(pl->p_progname)) (xdrbuf);
+	if (outdata == NULL && pl->p_outproc != (xdrproc_t)xdr_void)
+	  /* there was an error */
+	  return;
+	if (!svc_sendreply (transp, pl->p_outproc, outdata))
+	  {
+	    (void) fprintf (stderr,
+			    _ ("trouble replying to prog %d\n"),
+			    pl->p_prognum);
+	    exit (1);
+	  }
+	/* free the decoded arguments */
+	(void) svc_freeargs (transp, pl->p_inproc, xdrbuf);
+	return;
+      }
+  (void) fprintf (stderr, _ ("never registered prog %d\n"), prog);
+  exit (1);
 }
-