⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svc_simple.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
#ifndef lintstatic char *sccsid = "@(#)svc_simple.c	4.2	ULTRIX	9/4/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1986 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* *	Portions of this software have been licensed to  *	Digital Equipment Company, Maynard, MA. *	Copyright (c) 1986 Sun Microsystems, Inc.  ALL RIGHTS RESERVED. *//*  * svc_simple.c * Simplified front end to rpc. * */#include <stdio.h>#include <rpc/rpc.h>#include <sys/socket.h>#include <sys/time.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;int universal();static SVCXPRT *transp;static madetransp;struct proglst *pl;registerrpc(prognum, versnum, procnum, progname, inproc, outproc)	char *(*progname)();	xdrproc_t inproc, outproc;{		if (procnum == NULLPROC) {		fprintf(stderr,		    "can't reassign procedure number %d\n", NULLPROC);		return (-1);	}	if (!madetransp) {		madetransp = 1;		transp = svcudp_create(RPC_ANYSOCK);		if (transp == NULL) {			fprintf(stderr, "couldn't create an rpc server\n");			return (-1);		}	}	pmap_unset(prognum, versnum);	if (!svc_register(transp, prognum, versnum, universal, IPPROTO_UDP)) {	    	fprintf(stderr, "couldn't register prog %d vers %d\n",		    prognum, versnum);		return (-1);	}	pl = (struct proglst *)malloc(sizeof(struct proglst));	if (pl == NULL) {		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);}staticuniversal(rqstp, transp)	struct svc_req *rqstp;	SVCXPRT *transp;{	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, 0) == FALSE) {			fprintf(stderr, "xxx\n");			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 != xdr_void)				/* there was an error */				return;			if (!svc_sendreply(transp, pl->p_outproc, outdata)) {				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;		}	fprintf(stderr, "never registered prog %d\n", prog);	exit(1);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -