Solved

RPC

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 54
sum28 challenge 31 111
fizzArray2 challenge 1 78
Message not shown 5 49
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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