#include #include #include #include #include #include "countchar.h" /* Generated by rpcgen */ /* CpSc 824 Date: 2/92 Desc: example of Client program that calls the countchar rpc on a remote nodes using RPC broadcast. Usage: countmain node character-string character where: node is the remote node to execute this on, character_string is the string to be searched, character is the string to be searched for. */ /* Set maximum wait time to one half second (500 milliseconds) */ #define TIMEOUT 500 /* This is the routine that first receives each reply */ bool_t results(int *count, struct netbuf *addr, struct netconfig *netconf) { char *dotaddr, *ch; int i; unsigned long netaddr; struct hostent *hostname; dotaddr = taddr2uaddr(netconf, addr); ch = strchr(dotaddr, '.'); for (i=0;i<3;i++) ch = strchr(ch+1,'.'); *ch = '\0'; printf("Response received: "); printf(" :, count=%d from ", (int) *count); netaddr = inet_addr(dotaddr); if (netaddr == -1) { printf("inet_addr conversion error\n"); } else { if ((hostname = gethostbyaddr((char *)&netaddr, sizeof(netaddr), AF_INET)) == NULL){ printf("gethostbyaddr error\n"); } else { printf("hostname=%s\n", hostname->h_name); } } return(0); } main (argc,argv) int argc; char *argv[]; { enum clnt_stat status; CLIENT *cl; int *numptr; stringdata parms; /* defined in countchar.x */ nextcount *countlist, list; buftype bufptr; if (argc != 3 ) { printf("Usage: countmain character-string character\n"); exit(1); } /* RPC CALL 1 -- invoke countchar via broadcast */ printf("Getting ready to call countchar\n"); parms.findch = *argv[2]; parms.buf = argv[1]; /* Count occurences of given character */ numptr = (int *) malloc(sizeof(int)); *numptr = -1; status=rpc_broadcast_exp(COUNTCHARPROG, COUNTVERS, COUNTCHAR, (xdrproc_t) xdr_stringdata, (caddr_t) &parms, (xdrproc_t) xdr_int, (caddr_t) numptr, (resultproc_t) results, TIMEOUT, TIMEOUT, "netpath"); switch (status) { case RPC_SUCCESS: case RPC_TIMEDOUT: break; default: clnt_perrno(status); exit(1); } printf("Back from countchar\n"); if (*numptr == -1) { printf("No servers found\n"); exit(1); } printf("Returned count=%d\n",*numptr); printf("Done\n");fflush(stdout); exit(0); }