文字列を引数として取り、その長さを呼び出しプログラムに返す単純な RPC プログラムを作成しようとしています。必要なスタブを生成するために RPCGEN を使用しています。コードは次のとおりです。 prog.x ファイル:
program PROGRAM_PROG {
version PROGRAM_VERS {
int fun(string) = 1; /* procedure number = 1 */
} = 1; /* version number = 1 */
} = 0x31234567; /* program number = 0x31234567 */
client.c ファイル:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <rpc/rpc.h> /* standard RPC include file */
#include "prog.h" /* this file is generated by rpcgen */
#include "math.h"
main(int argc, char *argv[])
{
CLIENT *cl; /* RPC handle */
char *server;
char *word;
int *lresult; /* return value from bin_date_1() */
if (argc != 3) {
fprintf(stderr, "usage: %s hostname\n", argv[0]);
exit(1);
}
server = argv[1];
word = argv[2];
printf("%s======\n", server);
printf("%s======\n", word);
/*
* Create client handle
*/
if ((cl = clnt_create(server, PROGRAM_PROG, PROGRAM_VERS, "udp")) == NULL) {
/*
* can't establish connection with server
*/
clnt_pcreateerror(server);
exit(2);
}
/*
* First call the remote procedure "bin_date".
*/
printf("123\n");
if ( (lresult = fun_1(&word, cl)) == NULL) {
clnt_perror(cl, server);
exit(3);
}
printf("456\n");
printf("time on host %s = %d and look, word: %s\n",server, *lresult, word);
clnt_destroy(cl); /* done with the handle */
exit(0);
}
最後に serverproc.c ファイル:
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include "prog.h"
int *fun_1(char **p, CLIENT *cl)
{
int len;
int t;
t = strlen(*p);
return &t;
}
int * fun_1_svc(char **p, struct svc_req *cl){
CLIENT *client;
return(fun_1(0, client));
}
コードは正常にコンパイルされますが、実行するとハングするだけで、終了するには Ctrl-C を使用する必要があります。問題はおそらく serverproc.c ファイルにあります。私は何を間違っていますか?