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