编译RPC程序时出错

时间:2014-05-18 12:59:51

标签: c rpc

我正在尝试RPC上的示例程序。我创建了一个规范文件,客户端程序和服务器程序。 在执行客户端和服务器程序以及rpc文件时卡住了

规范文件:

/*Specification file for remote procedure*/
/*
Define 2 procedures:
bin_date_1 - returns the binary date and time
str_date_1 - takes binary time and returns human readable string
*/

program DATE_PROG{
        version DATE_VERS{
                long BIN_DATE(void) = 1;        /*Procedure no 1*/
                string STR_DATE(long) = 2;      /*Procedure no 2*/
        }=1;    /*version no*/
}=0x1234567;    /*program no*/

客户计划:

/* Client Program for Remote service */
#include<stdio.h>
#include<rpc/rpc.h>     /*Standard RPC INCLUDE file*/
#include "date.h"       /*The file generated by the rpcgen*/
int main(int argc,char* argv[]){
        CLIENT *cl;
        char* server;
        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);
        }
        server = argv[1];

        /* Create the Client handle */
        if((cl = clnt_create(server,DATE_PROG,DATE_VERS,"udp")) == NULL){
                clnt_pcreate_error(server);
                exit(2);
        }

        /* First call the remote procedure bin_date */
        if((lresult = bin_date_1(NULL,cl)) == NULL){
                clnt_perror(cl,server);
                exit(3);
        }

        printf("\n Time on host : %s = %d \n",server,*lresult);

        /* Now call the remote procedure str_date */
        if((sresult = str_date_1(lresult,cl)) == NULL){
                clnt_perror(cl,server);
                exit(3); 
        }

        printf("\n Time on host : %s = %d \n",server,*sresult);
        clnt_destroy(cl);
        exit(0);
}

服务器程序:

#include<stdio.h>
#include "date.h"       /* this file generated by rpcgen */
#include<time.h>

/* Return the binary date and time */
long* bin_date_1(void* time,CLIENT* cl){
        static long timeval;    //must be static 
        //long time;            //unix sys call

        time(&timeval); //returns time in seconds 00:00:00, 1,January,1970      
        return(&timeval);
}

/* Convert a binary time and return a human readable string */
char** str_date_1(long* bintime,CLIENT* cl){
        static char* ptr;       //must be static
        //char* ctime();                //C standard function
        ptr = ctime(bintime);   //convert to local time
        return(&ptr);           //return address of the pointer
}

如下编译客户端和服务器程序并出错。

angus@ubuntu:~/angus/RPC$ cc -o rdate rdate.c date_clnt.c -lrpclib
rdate.c: In function ‘main’: 
rdate.c:29:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat] 
rdate.c:37:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘char *’ [-Wformat] 
/usr/bin/ld: cannot find -lrpclib collect2: ld returned 1 exit status

angus@ubuntu:~/angus/RPC$ cc -o date_svc dateproc.c date_svc.c -lrpclib 
dateproc.c: In function ‘bin_date_1’: 
dateproc.c:11:6: error: called object ‘time’ is not a function 
angus@ubuntu:~/angus/RPC$

0 个答案:

没有答案