/*1* rls.c: Remote directory listing client2*/3#include <stdio.h>4#include <rpc/rpc.h> /* always need this */5#include "dir.h" /* need this too: will be generated by rpcgen*/67extern int errno;89main(argc, argv)10int argc;11char *argv[];12{13CLIENT *cl;14char *server;15char *dir;16readdir_res *result;17namelist nl;181920if (argc != 3) {21fprintf(stderr, "usage: %s host directory\n", argv[0]);22exit(1);23}2425/*26* Remember what our command line arguments refer to27*/28server = argv[1];29dir = argv[2];3031/*32* Create client "handle" used for calling DIRPROG on the33* server designated on the command line. We tell the rpc package34* to use the "tcp" protocol when contacting the server.35*/36cl = clnt_create(server, DIRPROG, DIRVERS, "tcp");37if (cl == NULL) {38/*39* Couldn't establish connection with server.40* Print error message and die.41*/42clnt_pcreateerror(server);43exit(1);44}4546/*47* Call the remote procedure "readdir" on the server48*/49result = readdir_1(&dir, cl);50if (result == NULL) {51/*52* An error occurred while calling the server.53* Print error message and die.54*/55clnt_perror(cl, server);56exit(1);57}5859/*60* Okay, we successfully called the remote procedure.61*/62if (result->errno != 0) {63/*64* A remote system error occurred.65* Print error message and die.66*/67errno = result->errno;68perror(dir);69exit(1);70}7172/*73* Successfully got a directory listing.74* Print it out.75*/76for (nl = result->readdir_res_u.list; nl != NULL; nl = nl->next) {77printf("%s\n", nl->name);78}79}808182