Solved

RPC

Posted on 1997-05-01
2
892 Views
Last Modified: 2013-12-26
Dear friends,
I am into RPC (Just) and that's why these simple programs.
I am trying to pass a variable to another server and have
that server increment the value of the variable and return the variable.
The .x compiles with rpcgen and does not generate an XDR.
I know the reason for this. When I compile the client and
the server stubs with cnt.c and cnt_svc_proc.c, I do not seem
to have any compilation errors.
When I rsh the second server and try to run my client program, I get
output as follows:
================================
SERVER=rigel
Segmentation fault
================================

Please find my original code for your kind perusal. Please help.
cnt.x
=====
program COUNTPROG {
        version COUNTVERS {
        int COUNTINCR(int)=1;
        }=1;
}=0x20000001;
========================================
cnt.c
=====
#include<stdio.h>
#include<rpc/rpc.h>
#include"cnt.h"
#include<stdlib.h>
main(argc, argv)
int argc;
char *argv[];
{
CLIENT *cl;
char *server;
static int *counter1,*counter2;
        if (argc != 2) {
                fprintf(stderr,"usage: %s server\n", argv[0]);
                exit(1);
        }
server = argv[1];
printf("SERVER=%s\n",server);
/* *counter1 = atoi(*argv[2]); */
*counter1=15;
printf("counter1 = %p\n",*counter1);
cl=clnt_create(server, COUNTPROG,COUNTVERS,"udp");
        if (cl == NULL) {
                clnt_pcreateerror(server);
             exit(1);
        }
*counter2=*countincr_1(*counter1,cl);
printf("counter1 = %d\n", *counter2);
}
===================================================================
cnt_svc_proc.c
==============
#include<stdio.h>
#include<rpc/rpc.h>
#include "cnt.h"
int *countincr_1(counter1)
{
static int result;
result=counter1+1;
return(&result);
}
===================================================================
Rajesh
arc7292p@uel.ac.uk
0
Comment
Question by:RajAcharya
2 Comments
 
LVL 3

Expert Comment

by:dhm
ID: 1292731
I don't know about the rest of your RPC code (haven't bothered to try it out), but on inspection I can see two serious errors that will cause your client program to crash.

Your two variables, counter1 and counter2, are declared to be pointers to integer.  However, you never initialize the pointers; you just try to stuff the value 15 into the location pointed to by counter1, and the result of the RPC call into the location pointed to by counter2.

If you declare two integer variables, and then make the pointers counter1 and counter2 point to them, perhaps things will work better.

E.g.:

/* ... the first part of your program ... */

static int *counter1, *counter2;
int integer1, integer2;

counter1 = &integer1;
counter2 = &integer2;

/* ... the rest of your program ... */

0
 

Accepted Solution

by:
albertp earned 50 total points
ID: 1292732
The error is not with RPC, it's a basic C mistake:
If you use a counter, first you have to reserve space for it.
For example:

int *a;
a=(int *)malloc(sizeof(int));
*a=23;

Try it and tell me if it works.
See you!!

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 95
Best tools for Backup and restore of Wordpress site 6 57
move a line in eclipse 3 107
fizzArray  challenge 1 96
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question