RPCGEN and Remote Procedure Programming

Guy Harris guy at auspex.UUCP
Sat Nov 26 17:51:27 AEST 1988


>Their are several problems : first, the docs I have refer to a function
>called clnt_create.  The function is supposed to set up or create
>the client handle to the server.  This function does not seem to exist
>when I compile the program.

It exists in SunOS 4.0.  The document version number and date you gave
is that of "Network Programming" in the 4.0 DocuC5-A(TM).  It may not
exist in 3.5.  Is the documentation you're using 3.5 documentation, 4.0
documentation, or something else?

>When I substituted this function with clnttcp_create(), it compiled but
>then proceeded to crash.

The calling sequences of "clnt_create" and "clnttcp_create" are different.
"clnt_create" is a wrapper that takes a host name, RPC program number,
RPC version number, and protocol name and calls the appropriate "create"
routine to create a client handle.

"clnttcp_create" takes an Internet address, rather than a host name. 
What you have to do is get the Internet address of the host in question
(using "gethostbyname" - make sure it's an Internet address that you get
back), fill in a "sockaddr_in" structure (if you're not familiar with
it, this is probably explained in some part of the networking tutorial
documentation) by:

	setting the "sin_family" to the "h_addrtype" of what
	"gethostbyname" gave you (although you already checked to make
	sure it was AF_INET);

	setting the "sin_port" to zero;

	zeroing the "sin_zero" with "bzero";

	copying "h_addr" of what "gethostbyname" gave you to the
	"sin_addr".

Then pass a pointer to that "sockaddr_in" structure as the first
argument to "clnttcp_create", pass the program and version number as the
second and third arguments, pass a pointer to an "int" variable
initialized to RPC_ANYSOCK as the fourth argument, and pass 0 as the
fifth and sixth arguments.

At least that's what "clnt_create" does; I presume that, or something
similar, will do the right thing.  (Now you know why "clnt_create" was
provided!). 



More information about the Comp.unix.wizards mailing list