Hello I am trying to run rpc program to query an entry from a file at the server side that is in the form of
<mm> <dd> <event>
. I get the proper result at the server. I have verified it by printf statements just before return statement of the result at server side. But somehow I am unable to catch the result at the client side. I get the following error at the client side:
$ ./client localhost query 01 01
call failed: RPC: Can't decode result
Segmentation fault (core dumped)
Server side:
$ ./server
result.event = The Epoch (Time 0 for UNIX systems, Midnight GMT) (1970)
^C
Client:
#include "hist.h"
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
void
historyprog_1(char *host, char *month, char *day)
{
CLIENT *clnt;
data *result_1;
data query_event_1_arg;
clnt = clnt_create(host, HISTORYPROG, HISTORYVERS_QUERY, "tcp");
if (clnt == (CLIENT *) NULL) {
clnt_pcreateerror(host);
exit(1);
}
query_event_1_arg.month=month;
query_event_1_arg.day=day;
query_event_1_arg.event="hello";// If this line is removed I get another seg fault here
result_1 = query_event_1(&query_event_1_arg, clnt);
if (result_1 == (data *) NULL) {
clnt_perror(clnt, "call failed");
}
printf("result_1->event = %s\n", result_1->event);
clnt_destroy(clnt);
}
int main(int argc, char *argv[])
{
char *host;
char *month;
char *day;
char *event;
if (argc < 2) {
printf("usage: %s server_host\n", argv[0]);
exit(1);
}
host = argv[1];
month = argv[3];
day=argv[4];
historyprog_1(host,month,day);
return 0;
}
Server:
#include "hist.h"
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <signal.h>
#include <string.h>
data *
query_event_1_svc(data *argp, struct svc_req *rqstp)
{
static data result;
FILE *f;
char *month;
char *day;
char *event;
int len;
int j;
char line[265];
char temp[265];
f = fopen("in.dat", "r");
if (f==NULL)
{
printf("cannot open");
}
while(fgets(line,265,f)!=NULL)
{
for(j=0;j<265;j++)
{
temp[j] = '\0';
}
len = strlen(line);
for(j=0;j<2;j++)
temp[j] = line[j];
month=strdup(temp);
for(j=0;j<2;j++)
temp[j] = line[j+3];
day=strdup(temp);
for(j=0;j<len-7;j++)
temp[j] = line[j+6];
event=strdup(temp);
if ((strcmp(argp->month, month) == 0)&&(strcmp(argp->day, day) == 0))
{
result.event = strdup(event);
fclose(f);
printf("result.event = %s\n", result.event);
return (&result);
}
free(month);
free(event);
free(day);
}
fclose(f);
return (&result);
}
hist.x
struct data
{
string month<2>;
string day<2> ;
string event<80>;
};
program HISTORYPROG {
version HISTORYVERS_QUERY {
data QUERY_EVENT(data) = 1;
} = 1;
} = 0x20000001;
Where is it going wrong?