Specifications

Page 26 Remote Procedure Call Programming Guide
4.6. Using Inetd
An RPC server can be started from inetd The only difference from the usual code is that the service creation
routine should be called in the following form:
transp = svcudp_create(0); /* For UDP */
transp = svctcp_create(0,0,0); /* For listener TCP sockets */
transp = svcfd_create(0,0,0); /* For connected TCP sockets */
since inet passes a socket as file descriptor 0. Also, svc_register() should be called as
svc_register(transp, PROGNUM, VERSNUM, service, 0);
with the final flag as 0, since the program would already be registered by inetd Remember that if you want
to exit from the server process and return control to inet you need to explicitly exit, since svc_run() never
returns.
The format of entries in /etc/inetd.conf for RPC services is in one of the following two forms:
p_name/version dgram rpc/udp wait/nowait user server args
p_name/version stream rpc/tcp wait/nowait user server args
where p_name is the symbolic name of the program as it appears in rpc(5), server is the program imple-
menting the server, and program and version are the program and version numbers of the service. For more
information, see inetd.conf(5).
If the same program handles multiple versions, then the version number can be a range, as in this example:
rstatd/1-2 dgram rpc/udp wait root /usr/etc/rpc.rstatd
5. More Examples
5.1. Versions
By convention, the first version number of program PROG is PROGVERS_ORIG and the most recent ver-
sion is PROGVERS Suppose there is a new version of the user program that returns an unsigned short
rather than a long. If we name this version RUSERSVERS_SHORT then a server that wants to support both
versions would do a double register.
if (!svc_register(transp, RUSERSPROG, RUSERSVERS_ORIG,
nuser, IPPROTO_TCP)) {
fprintf(stderr, "can’t register RUSER service\n");
exit(1);
}
if (!svc_register(transp, RUSERSPROG, RUSERSVERS_SHORT,
nuser, IPPROTO_TCP)) {
fprintf(stderr, "can’t register RUSER service\n");
exit(1);
}
Both versions can be handled by the same C procedure: