Solved

RPC

Posted on 1997-05-01
2
888 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now