Trusted Solaris Developer's Guide

Remote Procedure

The remote procedure receives the user ID from command line arguments, and multiplies the input by 2, sends the result to the client and prints the response before exiting.

static void
proc_1(struct svc_req *rqstp, SVCXPRT *handlep)
{
	int input;
	int result;
	uid_t *uidp;

	switch(rqstp->rq_proc) {
	case NULLPROC:
			svc_sendreply(handlep, xdr_void, NULL);
			break;
	case RPC_TEST_DOUBLE1:
			if (!svc_getargs(handlep, xdr_int, (caddr_t) &input)) {
				fprintf(stderr, "Error from svc_getargs\n");
				svcerr_systemerr(handlep);
			}
			uidp = (uid_t *) t6get_attr(T6_UID,
				handlep->xp_tsol_incoming_attrsp);
			if (uidp == NULL)
				fprintf(stderr, "Error from t6get_attr.\n");
			else printf("Client's UID is %d\n", *uidp);
			result = 2 * input;
			if (!svc_sendreply(handlep, xdr_int, (caddr_t) &result)) {
				fprintf(stderr, "Error from sendreply\n");
				svcerr_systemerr(handlep);
			}
			svc_freeargs(handlep, xdr_int, (caddr_t) &input);
			break;

	default:
			fprintf(stderr, "Call to unexpected procedure number %d\n",
				rqstp->rq_proc);
		svcerr_noproc(handlep);
		break;
	}
}