Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / int / net / rpc / clnt.c
1 #include <stdio.h>
2 #include <rpc/rpc.h>
3 #include "srvr.h"
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include <sys/time.h>
7 #include <netdb.h>
8
9 main(argc,argv) int argc; char **argv; {
10    struct hostent *hp;
11    struct timeval pertry_timeout,total_timeout;
12    struct sockaddr_in server_addr;
13    int addrlen;
14    int sock=RPC_ANYSOCK;
15    CLIENT *client;
16    enum clnt_stat clnt_stat;
17    char *s;
18    int pid=getpid();
19    int vers;
20
21    if(argc < 3) fprintf(stderr,"usage:%s hostname version\n",argv[0]),exit(-1);
22
23    vers=(int)atol(argv[2]);
24
25    if((hp=gethostbyname(argv[1]))==NULL)
26       fprintf(stderr,"cannot get addr for %s\n",argv[1]),exit(-1);
27
28    pertry_timeout.tv_sec  = 60;
29    pertry_timeout.tv_usec = 0;
30
31    addrlen = sizeof( struct sockaddr_in );
32    {
33       int i;
34       for( i=0; i<hp->h_length ; i++ )
35          ((char *)(&server_addr.sin_addr))[i] = hp->h_addr[i];
36    }
37
38    server_addr.sin_family = AF_INET;
39    server_addr.sin_port   = 0;
40
41    total_timeout.tv_sec  = 2000;
42    total_timeout.tv_usec = 0;
43
44    if((client=clntudp_create(&server_addr,SRVRPROG,SRVRVERS+vers,total_timeout,&sock))==NULL){
45       perror("clntudp_create");
46       exit(-1);
47    }
48
49    clnt_stat=clnt_call(client,NULLPROC, xdr_void,NULL, xdr_void,NULL,
50                        total_timeout);
51
52    if( clnt_stat != RPC_SUCCESS ){
53       clnt_perror( client, "rpc clnt call" );
54       exit(-1);
55    }
56
57    {
58       int i;
59       for( i=0; i<500; i++ ){
60
61          s=malloc(40);
62          sprintf(s,"client %d version %d",pid,vers);
63
64          clnt_stat = clnt_call( client, RENDERSTR,
65                                 xdr_wrapstring, &s, xdr_void, NULL,
66                                 total_timeout );
67
68          if( clnt_stat != RPC_SUCCESS ){
69             clnt_perror(client,"rpc");
70             exit(-1);
71          }
72
73       }
74    }
75
76    clnt_destroy( client );
77 }