Solved

c pass string parameter with rpcgen

Posted on 2008-10-18
1
823 Views
Last Modified: 2008-10-18
Hi,

I am wanting to create a basic c program using RPCGEN on the hello.x file below. How do I write my client file to pass the string parameter of print_hello to the server? I can easily pass a void parameter and return a string but not sure how to pass the string.

Cheers
---------- hello.x -------------------
 

program DISPLAY_PRG {

	version DISPLAY_VER {

		string print_hello( string ) = 1;

	} = 1;

} = 0x20000001;
 
 

----------- hello_client.c ---------------

/*

	The CLIENT program: hello_client.c

	This will be the client code executed by the local client process.

*/

#include <stdio.h>

#include "hello.h"	/* Generated by rpcgen from hello.x	*/
 

int main(int argc, char *argv[]) {

	CLIENT	*client;

	char* *return_value;

	int		filler;

	char	*server;

	/*

		We must specify a host on which to run. We will get the host name

		from the command line as argument 1.

	*/
 

	if (argc != 2) {

		fprintf(stderr, "Usage: %s host_name\n", *argv);

		exit(1);

	}

	server = argv[1];

	

	/*

		Generate the client handle to call the server

	*/

	if ((client=clnt_create(server,		DISPLAY_PRG,

							 DISPLAY_VER, "tcp")) == (CLIENT *) NULL) {

		clnt_pcreateerror(server);

		exit(2);						 

	}

	printf("client : Calling function.\n");

	return_value = print_hello_1((void *) &filler, client);

	if (*return_value) {

		printf("server returned message : %s\n", *return_value);

		printf("client : Mission accomplished.\n");

	} else {

		printf("client : Unable to display message.\n");

	}

	return 0;

}

Open in new window

0
Comment
Question by:mstrelan
1 Comment
 
LVL 10

Accepted Solution

by:
mstrelan earned 0 total points
ID: 22751148
mmm solved it.
see code below
/*

	The CLIENT program: hello_client.c

	This will be the client code executed by the local client process.

*/

#include <stdio.h>

#include "hello.h"	/* Generated by rpcgen from hello.x	*/
 

int main(int argc, char *argv[]) {

	CLIENT	*client;

	char* *return_value;

	int		filler;

	char	*server;

	char *message;

	/*

		We must specify a host on which to run. We will get the host name

		from the command line as argument 1.

	*/
 

	if (argc != 3) {

		fprintf(stderr, "Usage: %s host_name message\n", *argv);

		exit(1);

	}

	server = argv[1];

	message = argv[2];

	

	/*

		Generate the client handle to call the server

	*/

	if ((client=clnt_create(server,		DISPLAY_PRG,

							 DISPLAY_VER, "tcp")) == (CLIENT *) NULL) {

		clnt_pcreateerror(server);

		exit(2);						 

	}

	printf("client : Calling function.\n");

/*	return_value = print_hello_1((void *) &filler, client);*/

	return_value = print_hello_1(&message, client);

	if (*return_value) {

		printf("server returned message : %s\n", *return_value);

		printf("client : Mission accomplished.\n");

	} else {

		printf("client : Unable to display message.\n");

	}

	return 0;

}

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Microsoft vcsetup.exe and vcssetup.exe 8 397
Using unmanaged DLL from managed application 14 287
Test against App 49 129
chcp 65001 File encoding 66 218
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

760 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

20 Experts available now in Live!

Get 1:1 Help Now