Example 4-11 shows the corresponding server. The command line that starts the service must specify the transport over which the service is provided.
/*
* This program supplies Greenwich mean
* time to the client that invokes it.
* The call format is: server netid
*/
#include <stdio.h>
#include <rpc/rpc.h>
#include <netconfig.h> /* For netconfig structure */
#include "time_prot.h"
static void time_prog();
main(argc, argv)
int argc;
char *argv[];
{
SVCXPRT *transp;
struct netconfig *nconf;
if (argc != 2) {
fprintf(stderr, "usage: %s netid\n",
argv[0]);
exit(1);
}
if ((nconf = getnetconfigent( argv[1])) ==
(struct netconfig *) NULL) {
fprintf(stderr, "Could not find info on %s\n",
argv[1]);
exit(1);
}
transp = svc_tp_create(time_prog, TIME_PROG,
TIME_VERS, nconf);
if (transp == (SVCXPRT *) NULL) {
fprintf(stderr, "%s: cannot create
%s service\n", argv[0], argv[1]);
exit(1)
}
freenetconfigent(nconf);
svc_run();
}
static
void time_prog(rqstp, transp)
struct svc_req *rqstp;
SVCXPRT *transp;
{
/* Code identical to Top Level version */
|