我正在编写一个RPC字典程序。该程序已成功编译,但运行时出现以下错误:
call failed: RPC: Can't encode arguments
Segmentation fault (core dumped)
这是我的文件:
dict.x
program DICT_PROG{
version DICT_VER{
string SEARCH_DICT(string)=1; /*procedure number 1*/
string INSERT_DICT(string)=2; /*procedure number 2*/
string DELETE_DICT(string)=3; /*procedure number 3*/
}=1; /*version number 1*/
}=0x34343434; /*program number 1*/
client.c
#include "dic.h"
#include <stdio.h>
void
dict_prog_1(char *host)
{
CLIENT *clnt;
char * *result_1;
char * search_dict_1_arg;
char * *result_2;
char * insert_dict_1_arg;
char * *result_3;
char * delete_dict_1_arg;
int opt;
int leave=0;
#ifndef DEBUG
clnt = clnt_create (host, DICT_PROG, DICT_VER, "tcp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
printf("DICTIONARY RPC PROGRAM");
puts("");
do{
printf("CHOOSE AN OPERATION:\n");
printf("1) INSERT \n2) SEARCH \n3) DELETE \n4) EXIT \n");
printf("YOUR CHOICE:");
scanf("%d",&opt);
switch(opt){
case 1:
result_1 = search_dict_1(&search_dict_1_arg, clnt);
if (result_1 == (char **) NULL) {
clnt_perror (clnt, "call failed");
}
printf("%s",*result_1);
break;
case 2:
result_2 = insert_dict_1(&insert_dict_1_arg, clnt);
if (result_2 == (char **) NULL) {
clnt_perror (clnt, "call failed");
}
printf("%s",*result_2);
break;
case 3:
result_3 = delete_dict_1(&delete_dict_1_arg, clnt);
if (result_3 == (char **) NULL) {
clnt_perror (clnt, "call failed");
}
printf("%s",*result_3);
break;
default:
printf("\nINVALID OPERATION");
}
}while(leave != 1) ;
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
}
int
main (int argc, char *argv[])
{
char *host;
if (argc < 2) {
printf ("usage: %s server_host\n", argv[0]);
exit (1);
}
host = argv[1];
dict_prog_1 (host);
exit (0);
}
我用 rpcgen 从 dict.x 生成了其他文件。由于我在 dict.x 中使用的所有数据类型(字符串)都是原始数据,因此未生成XDR文件。我不知道为什么会收到此错误。如果您需要更多信息,请随时询问。