Solved

RPC

Posted on 1997-05-01
2
898 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

635 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