ONC+ RPC Developer's Guide

Exit Print View

Updated: July 2014
 
 

Hand-Coded Registration Routine

You can sometimes implement faster or more compact code than can rpcgen. rpcgen handles the generic code-generation cases. The following program is an example of a hand-coded registration routine. It registers a single procedure and enters svc_run() to service requests.

#include <stdio.h>
 #include <rpc/rpc.h>
 #include <rpcsvc/rusers.h>
 void *rusers();
 
 main()
 {
 	if(rpc_reg(RUSERSPROG, RUSERSVERS,
			RUSERSPROC_NUM, rusers,
 			xdr_void, xdr_u_int,
			"visible") == -1) {
 		fprintf(stderr, "Couldn't Register\n");
 		exit(1);
 	}
 	svc_run();     /* Never returns */
 	fprintf(stderr, "Error: svc_run
		returned!\n");
 	exit(1);
}

rpc_reg() can be called as many times as is needed to register different programs, versions, and procedures.