| CFS-48145 IPMT ZUO101084 Akros AG, Severity 3 Reported release: V3.3
17-Jan-1997
~~~~~~~~~~~
The release which you are reporting the problem for is no longer supported.
I have tested it, however, with the currently supported releases and have
found that the program works properly.
I have made a few changes to your source code, as it was not using `sockp'
properly. The routine clnttcp_create() expects to be passed an `int *', not
an `int **', as you have done. See the definitions of `sock' and `sockp'
below. Note that you can probably remove sockp and pass the address of sock
(&sock) instead. That would simplify the variables.
/*
* rls.c: Remote directory listing client
*/
#include <errno.h>
#include <rms.h>
#include <stdio.h>
#include <in.h>
#include <netdb.h>
#include <UCX$INETDEF.H>
#include <UCX$RPCXDR.H>
#include <socket.h>
#include "dir.h"
main(argc, argv)
int argc;
char *argv[];
{
CLIENT *cl;
char *dir;
static struct sockaddr_in sock2_name;
struct hostent hostentstruct;
struct hostent *hostentptr;
namelist nl;
readdir_res *result;
char *server;
int sock = RPC_ANYSOCK;
int *sockp = &sock;
if (argc != 3) {
fprintf(stderr, "usage: %s host directory\n", argv[0]);
exit(1);
}
if ((hostentptr = gethostbyname (argv[1])) == NULL)
{
perror( "gethostbyname");
exit(1);
}
hostentstruct = *hostentptr;
sock2_name.sin_family = hostentstruct.h_addrtype;
sock2_name.sin_port = 0;
sock2_name.sin_addr = * ((struct in_addr *) hostentstruct.h_addr);
server = argv[1];
dir = argv[2];
/*
** Create client "handle" used for calling DIRPROG on
** the server designated on the command line. Use
** the tcp protocol when contacting the server.
*/
cl = clnttcp_create((struct sockaddr_in *)&sock2_name,
DIRPROG, DIRVERS,sockp,0,0);
if (cl == NULL) {
/*
** Couldn't establish connection with server.
** Print error message and stop.
*/
clnt_pcreateerror(server);
exit(1);
}
/*
** Call the remote procedure readdir on the server
*/
result = readdir_1(&dir, cl);
if (result == NULL) {
/*
** An RPC error occurred while calling the server.
** Print error message and stop.
*/
clnt_perror(cl, server);
exit(1);
}
/*
** Okay, we successfully called the remote procedure.
*/
if (result->Errno != 0) {
/*
** A remote system error occurred.
** Print error message and stop.
**/
errno = result->Errno;
perror(dir);
exit(1);
}
/*
** Successfully got a directory listing.
** Print it out.
*/
for (nl = result->readdir_res_u.list;
nl != NULL;
nl = nl->next)
printf("%s\n", nl->name);
exit(0);
}
|