/* ** File name: GETSYI_CLNT_RMTCALL.C ** ** Copyright (c) 1991, by ** Process Software Corporation ** Framingham, Massachusetts ** ** This file along with GETSYI_CLNT_SUBS.C implement a client for the getsyi ** protocol. This particular client uses the RPC pmap_rmtcall function. */ /* ** Include files */ #include #include "TCPWARE_INCLUDE:RPC.H" #include "TCPWARE_INCLUDE:SOCKET.H" #include "TCPWARE_INCLUDE:NETDB.H" #include "GETSYI.H" #include "GETSYI_DEF.H" /* ** Declare Functions */ longw parse_command_line(); void write_output(); /* ** Variables ** ** The transport that the client will use to contact the server. Since the ** pmap_rmtcall RPC function must use UDP, do not allow the user to specify a ** transport. This is done by initially setting transport to the string "UDP". */ globaldef char transport[4] = {"UDP"}; /* ** The name of the server's host. An initial value of 0 allows the user to ** specify any host. */ globaldef char *host = 0; /* user may give host name */ static readonly char usage[] = "Command format: getsyi [-d#] [-hhost] [-nnode] code [code...]\n"; /* **************************************** ** ** Main program ** ** Abstract: ** This client program demonstrates the use of the pmap_rmtcall function. */ main( argc, argv) int argc; char *argv[]; { longw status, /* status returned by functions */ rmt_port; /* port that the server is listening ** on. Returned by pmap_rmtcall */ int rpc_status; /* pmap_rmtcall status code */ getsyi_args args; /* request sent to server */ getsyi_res results; /* reply received from server */ struct sockaddr_in addr; /* Address of the server's host */ struct hostent *he; /* used to get the server's address */ struct timeval timeout = {25, 0}; /* RPC call timeout (25 sec) */ /* ** Parse the command line that the user entered. After this function call, the ** variable host points the name of the server's host and args contains all of ** the information that will be sent to the server. */ _error( status = parse_command_line( argc, argv, &args)) { if( status == SS$_BADPARAM) printf( usage); exit( status); } /* ** The hostname must be converted into an address since pmap_rmtcall requires ** the remote host to be specified as an address, not as a string. */ if( (he = gethostbyname( host)) == 0) { printf( "Unknown host name\n"); exit( SS$_NOSUCHNODE); } bcopy( he->h_addr, &addr.sin_addr, he->h_length); addr.sin_family = AF_INET; addr.sin_port = 0; /* ** results must be zeroed so that xdr_getsyi_res will allocate the memory. ** Otherwise, xdr_getsyi_res assumes that results contains the addresses of ** valid buffers. */ bzero( &results, sizeof( results)); if( rpc_status = pmap_rmtcall( &addr, GETSYI_PROG, GETSYI_VERS_1, GETSYI_PROC_1, xdr_getsyi_args, &args, xdr_getsyi_res, &results, timeout, &rmt_port) != 0) { printf( "Unable to call server\n"); clnt_perrno( rpc_status); /* print why pmap_rmtcall failed */ exit( SS$_OPINCOMPL); } /* ** Display the output for the user to see. */ write_output( &args, &results); exit( SS$_NORMAL); } /* end file GETSYI_CLNT_RMTCALL.C */