// date_client.c - client program for remote date service.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/rpc.h> // standard RPC include file
#include <rpc/auth.h>
#include "date.h" // automatically generated by rpcgen
typedef unsigned int rpc_uint;
int main(int argc, char *argv[])
{
CLIENT *handle; // RPC handle, used in all RPC transactions
char *remote_host;
long *lresult; // return value from bin_date_1()
char **sresult; // return value from str_date_1()
if(argc != 2) {
fprintf(stderr, "Usage: %s hostname\n", argv[0]);
exit(1);
}
remote_host = argv[1];
// CREATE THE CLIENT "HANDLE" TO BE USED IN ALL RPC TRANSACTIONS.
if((handle = clnt_create(remote_host, DATE_PROG ,DATE_VERS, "udp")) == NULL) {
clnt_pcreateerror(remote_host); // no connection with server.
exit(2);
}
// FIRST CALL THE REMOTE PROCEDURE "bin_date"
if((lresult = bin_date_1(NULL, handle)) == NULL) {
clnt_perror(handle, remote_host);
exit(3);
}
printf("time on host %s = %ld\n", remote_host, *lresult);
// NOW CALL THE REMOTE PROCEDURE "str_date"
if( (sresult = str_date_1(lresult, handle)) == NULL) {
clnt_perror(handle, remote_host);
exit(4);
}
printf("time on host %s = %s", remote_host, *sresult);
// CLOSE OUR CONNECTION WITH THE RPC SERVER
clnt_destroy(handle);
return 0;
}
|