summaryrefslogtreecommitdiffstats
path: root/share/examples
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1994-08-07 18:50:51 +0000
committerwollman <wollman@FreeBSD.org>1994-08-07 18:50:51 +0000
commitdad3f94d0491bdba4561ad19b0f276fbc4c17a1e (patch)
tree92c835d61705c5c8f210d2e89f4c418a79741936 /share/examples
parent7e6f5f8c5d3c41e980f33f25ccf94129d0eb0106 (diff)
parentda8387f131b31fd09269eb0025ceb4082c11001e (diff)
downloadFreeBSD-src-dad3f94d0491bdba4561ad19b0f276fbc4c17a1e.zip
FreeBSD-src-dad3f94d0491bdba4561ad19b0f276fbc4c17a1e.tar.gz
This commit was generated by cvs2svn to compensate for changes in r1905,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'share/examples')
-rw-r--r--share/examples/sunrpc/Makefile25
-rw-r--r--share/examples/sunrpc/dir/Makefile26
-rw-r--r--share/examples/sunrpc/dir/dir.x37
-rw-r--r--share/examples/sunrpc/dir/dir_proc.c55
-rw-r--r--share/examples/sunrpc/dir/rls.c81
-rw-r--r--share/examples/sunrpc/msg/Makefile36
-rw-r--r--share/examples/sunrpc/msg/msg.x9
-rw-r--r--share/examples/sunrpc/msg/msg_proc.c28
-rw-r--r--share/examples/sunrpc/msg/printmsg.c43
-rw-r--r--share/examples/sunrpc/msg/rprintmsg.c74
-rw-r--r--share/examples/sunrpc/sort/Makefile36
-rw-r--r--share/examples/sunrpc/sort/rsort.c43
-rw-r--r--share/examples/sunrpc/sort/sort.x19
-rw-r--r--share/examples/sunrpc/sort/sort_proc.c27
14 files changed, 539 insertions, 0 deletions
diff --git a/share/examples/sunrpc/Makefile b/share/examples/sunrpc/Makefile
new file mode 100644
index 0000000..05510d6
--- /dev/null
+++ b/share/examples/sunrpc/Makefile
@@ -0,0 +1,25 @@
+#
+# @(#)Makefile 2.1 88/08/02 4.0 RPCSRC
+#
+#
+# Build all demo services
+#
+MAKE = make
+LIB=-lrpclib
+
+SUBDIR= dir msg sort
+
+all: ${SUBDIR}
+
+clean cleanup:
+ cd dir; $(MAKE) ${MFLAGS} cleanup
+ cd msg; $(MAKE) ${MFLAGS} cleanup
+ cd sort; $(MAKE) ${MFLAGS} cleanup
+
+install:
+ @echo "No installations done."
+
+${SUBDIR}: FRC
+ cd $@; $(MAKE) ${MFLAGS} LIB=$(LIB)
+
+FRC:
diff --git a/share/examples/sunrpc/dir/Makefile b/share/examples/sunrpc/dir/Makefile
new file mode 100644
index 0000000..592c9d6
--- /dev/null
+++ b/share/examples/sunrpc/dir/Makefile
@@ -0,0 +1,26 @@
+#
+# @(#)Makefile 2.1 88/08/02 4.0 RPCSRC
+#
+BIN = dir_svc rls
+GEN = dir_clnt.c dir_svc.c dir_xdr.c dir.h
+LIB = -lrpclib
+RPCCOM = rpcgen
+
+all: $(BIN)
+
+$(GEN): dir.x
+ $(RPCCOM) dir.x
+
+dir_svc: dir_proc.o dir_svc.o dir_xdr.o
+ $(CC) -o $@ dir_proc.o dir_svc.o dir_xdr.o $(LIB)
+
+rls: rls.o dir_clnt.o dir_xdr.o
+ $(CC) -o $@ rls.o dir_clnt.o dir_xdr.o $(LIB)
+
+rls.o: rls.c dir.h
+
+dir_proc.o: dir_proc.c dir.h
+
+clean cleanup:
+ rm -f $(GEN) *.o $(BIN)
+
diff --git a/share/examples/sunrpc/dir/dir.x b/share/examples/sunrpc/dir/dir.x
new file mode 100644
index 0000000..db4283c
--- /dev/null
+++ b/share/examples/sunrpc/dir/dir.x
@@ -0,0 +1,37 @@
+/* @(#)dir.x 2.1 88/08/02 4.0 RPCSRC */
+/*
+ * dir.x: Remote directory listing protocol
+ */
+const MAXNAMELEN = 255; /* maximum length of a directory entry */
+
+typedef string nametype<MAXNAMELEN>; /* a directory entry */
+
+typedef struct namenode *namelist; /* a link in the listing */
+
+/*
+ * A node in the directory listing
+ */
+struct namenode {
+ nametype name; /* name of directory entry */
+ namelist next; /* next entry */
+};
+
+/*
+ * The result of a READDIR operation.
+ */
+union readdir_res switch (int errno) {
+case 0:
+ namelist list; /* no error: return directory listing */
+default:
+ void; /* error occurred: nothing else to return */
+};
+
+/*
+ * The directory program definition
+ */
+program DIRPROG {
+ version DIRVERS {
+ readdir_res
+ READDIR(nametype) = 1;
+ } = 1;
+} = 76;
diff --git a/share/examples/sunrpc/dir/dir_proc.c b/share/examples/sunrpc/dir/dir_proc.c
new file mode 100644
index 0000000..9f7522a
--- /dev/null
+++ b/share/examples/sunrpc/dir/dir_proc.c
@@ -0,0 +1,55 @@
+/* @(#)dir_proc.c 2.1 88/08/02 4.0 RPCSRC */
+/*
+ * dir_proc.c: remote readdir implementation
+ */
+#include <rpc/rpc.h>
+#include <sys/dir.h>
+#include "dir.h"
+
+extern int errno;
+extern char *malloc();
+extern char *strcpy();
+
+readdir_res *
+readdir_1(dirname)
+ nametype *dirname;
+{
+ DIR *dirp;
+ struct direct *d;
+ namelist nl;
+ namelist *nlp;
+ static readdir_res res; /* must be static! */
+
+ /*
+ * Open directory
+ */
+ dirp = opendir(*dirname);
+ if (dirp == NULL) {
+ res.errno = errno;
+ return (&res);
+ }
+
+ /*
+ * Free previous result
+ */
+ xdr_free(xdr_readdir_res, &res);
+
+ /*
+ * Collect directory entries
+ */
+ nlp = &res.readdir_res_u.list;
+ while (d = readdir(dirp)) {
+ nl = *nlp = (namenode *) malloc(sizeof(namenode));
+ nl->name = malloc(strlen(d->d_name)+1);
+ strcpy(nl->name, d->d_name);
+ nlp = &nl->next;
+ }
+ *nlp = NULL;
+
+ /*
+ * Return the result
+ */
+ res.errno = 0;
+ closedir(dirp);
+ return (&res);
+}
diff --git a/share/examples/sunrpc/dir/rls.c b/share/examples/sunrpc/dir/rls.c
new file mode 100644
index 0000000..4f2d473
--- /dev/null
+++ b/share/examples/sunrpc/dir/rls.c
@@ -0,0 +1,81 @@
+/* @(#)rls.c 2.2 88/08/12 4.0 RPCSRC */
+/*
+ * rls.c: Remote directory listing client
+ */
+#include <stdio.h>
+#include <rpc/rpc.h> /* always need this */
+#include "dir.h" /* need this too: will be generated by rpcgen*/
+
+extern int errno;
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ CLIENT *cl;
+ char *server;
+ char *dir;
+ readdir_res *result;
+ namelist nl;
+
+
+ if (argc != 3) {
+ fprintf(stderr, "usage: %s host directory\n", argv[0]);
+ exit(1);
+ }
+
+ /*
+ * Remember what our command line arguments refer to
+ */
+ server = argv[1];
+ dir = argv[2];
+
+ /*
+ * Create client "handle" used for calling DIRPROG on the
+ * server designated on the command line. We tell the rpc package
+ * to use the "tcp" protocol when contacting the server.
+ */
+ cl = clnt_create(server, DIRPROG, DIRVERS, "tcp");
+ if (cl == NULL) {
+ /*
+ * Couldn't establish connection with server.
+ * Print error message and die.
+ */
+ clnt_pcreateerror(server);
+ exit(1);
+ }
+
+ /*
+ * Call the remote procedure "readdir" on the server
+ */
+ result = readdir_1(&dir, cl);
+ if (result == NULL) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and die.
+ */
+ 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 die.
+ */
+ errno = result->errno;
+ perror(dir);
+ exit(1);
+ }
+
+ /*
+ * Successfuly got a directory listing.
+ * Print it out.
+ */
+ for (nl = result->readdir_res_u.list; nl != NULL; nl = nl->next) {
+ printf("%s\n", nl->name);
+ }
+}
diff --git a/share/examples/sunrpc/msg/Makefile b/share/examples/sunrpc/msg/Makefile
new file mode 100644
index 0000000..2f3f5dd
--- /dev/null
+++ b/share/examples/sunrpc/msg/Makefile
@@ -0,0 +1,36 @@
+#
+# @(#)Makefile 2.1 88/08/11 4.0 RPCSRC
+#
+BIN = printmsg msg_svc rprintmsg
+GEN = msg_clnt.c msg_svc.c msg.h
+LIB = -lrpclib
+RPCCOM = rpcgen
+
+all: $(BIN)
+
+#
+# This is the non-networked version of the program
+#
+printmsg: printmsg.o
+ $(CC) -o $@ printmsg.o
+
+#
+# note: no xdr routines are generated here, due this service's
+# use of basic data types.
+#
+$(GEN): msg.x
+ $(RPCCOM) msg.x
+
+msg_svc: msg_proc.o msg_svc.o
+ $(CC) -o $@ msg_proc.o msg_svc.o $(LIB)
+
+rprintmsg: rprintmsg.o msg_clnt.o
+ $(CC) -o $@ rprintmsg.o msg_clnt.o $(LIB)
+
+rprintmsg.o: rprintmsg.c msg.h
+
+msg_proc.o: msg_proc.c msg.h
+
+clean cleanup:
+ rm -f $(GEN) *.o $(BIN)
+
diff --git a/share/examples/sunrpc/msg/msg.x b/share/examples/sunrpc/msg/msg.x
new file mode 100644
index 0000000..d311352
--- /dev/null
+++ b/share/examples/sunrpc/msg/msg.x
@@ -0,0 +1,9 @@
+/* @(#)msg.x 2.1 88/08/11 4.0 RPCSRC */
+/*
+ * msg.x: Remote message printing protocol
+ */
+program MESSAGEPROG {
+ version MESSAGEVERS {
+ int PRINTMESSAGE(string) = 1;
+ } = 1;
+} = 99;
diff --git a/share/examples/sunrpc/msg/msg_proc.c b/share/examples/sunrpc/msg/msg_proc.c
new file mode 100644
index 0000000..80e5d95
--- /dev/null
+++ b/share/examples/sunrpc/msg/msg_proc.c
@@ -0,0 +1,28 @@
+/* @(#)msg_proc.c 2.1 88/08/11 4.0 RPCSRC */
+/*
+ * msg_proc.c: implementation of the remote procedure "printmessage"
+ */
+#include <stdio.h>
+#include <rpc/rpc.h> /* always need this here */
+#include "msg.h" /* need this too: msg.h will be generated by rpcgen */
+
+/*
+ * Remote verson of "printmessage"
+ */
+int *
+printmessage_1(msg)
+ char **msg;
+{
+ static int result; /* must be static! */
+ FILE *f;
+
+ f = fopen("/dev/console", "w");
+ if (f == NULL) {
+ result = 0;
+ return (&result);
+ }
+ fprintf(f, "%s\n", *msg);
+ fclose(f);
+ result = 1;
+ return (&result);
+}
diff --git a/share/examples/sunrpc/msg/printmsg.c b/share/examples/sunrpc/msg/printmsg.c
new file mode 100644
index 0000000..dde55dd
--- /dev/null
+++ b/share/examples/sunrpc/msg/printmsg.c
@@ -0,0 +1,43 @@
+/* @(#)printmsg.c 2.1 88/08/11 4.0 RPCSRC */
+/*
+ * printmsg.c: print a message on the console
+ */
+#include <stdio.h>
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ char *message;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <message>\n", argv[0]);
+ exit(1);
+ }
+ message = argv[1];
+
+ if (!printmessage(message)) {
+ fprintf(stderr, "%s: sorry, couldn't print your message\n",
+ argv[0]);
+ exit(1);
+ }
+ printf("Message delivered!\n");
+}
+
+/*
+ * Print a message to the console.
+ * Return a boolean indicating whether the message was actually printed.
+ */
+printmessage(msg)
+ char *msg;
+{
+ FILE *f;
+
+ f = fopen("/dev/console", "w");
+ if (f == NULL) {
+ return (0);
+ }
+ fprintf(f, "%s\n", msg);
+ fclose(f);
+ return(1);
+}
diff --git a/share/examples/sunrpc/msg/rprintmsg.c b/share/examples/sunrpc/msg/rprintmsg.c
new file mode 100644
index 0000000..b9cb1e3
--- /dev/null
+++ b/share/examples/sunrpc/msg/rprintmsg.c
@@ -0,0 +1,74 @@
+/* @(#)rprintmsg.c 2.1 88/08/11 4.0 RPCSRC */
+/*
+ * rprintmsg.c: remote version of "printmsg.c"
+ */
+#include <stdio.h>
+#include <rpc/rpc.h> /* always need this */
+#include "msg.h" /* need this too: will be generated by rpcgen*/
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ CLIENT *cl;
+ int *result;
+ char *server;
+ char *message;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host message\n", argv[0]);
+ exit(1);
+ }
+
+ /*
+ * Remember what our command line arguments refer to
+ */
+ server = argv[1];
+ message = argv[2];
+
+ /*
+ * Create client "handle" used for calling MESSAGEPROG on the
+ * server designated on the command line. We tell the rpc package
+ * to use the "tcp" protocol when contacting the server.
+ */
+ cl = clnt_create(server, MESSAGEPROG, MESSAGEVERS, "tcp");
+ if (cl == NULL) {
+ /*
+ * Couldn't establish connection with server.
+ * Print error message and die.
+ */
+ clnt_pcreateerror(server);
+ exit(1);
+ }
+
+ /*
+ * Call the remote procedure "printmessage" on the server
+ */
+ result = printmessage_1(&message, cl);
+ if (result == NULL) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and die.
+ */
+ clnt_perror(cl, server);
+ exit(1);
+ }
+
+ /*
+ * Okay, we successfully called the remote procedure.
+ */
+ if (*result == 0) {
+ /*
+ * Server was unable to print our message.
+ * Print error message and die.
+ */
+ fprintf(stderr, "%s: sorry, %s couldn't print your message\n",
+ argv[0], server);
+ exit(1);
+ }
+
+ /*
+ * The message got printed on the server's console
+ */
+ printf("Message delivered to %s!\n", server);
+}
diff --git a/share/examples/sunrpc/sort/Makefile b/share/examples/sunrpc/sort/Makefile
new file mode 100644
index 0000000..07627fa
--- /dev/null
+++ b/share/examples/sunrpc/sort/Makefile
@@ -0,0 +1,36 @@
+#
+# @(#)Makefile 2.1 88/08/11 4.0 RPCSRC
+#
+
+BIN = rsort sort_svc
+GEN = sort_clnt.c sort_svc.c sort_xdr.c sort.h
+LIB = -lrpclib
+RPCCOM = rpcgen
+
+all: $(BIN)
+
+rsort: rsort.o sort_clnt.o sort_xdr.o
+ $(CC) $(LDFLAGS) -o $@ rsort.o sort_clnt.o sort_xdr.o $(LIB)
+
+rsort.o: rsort.c sort.h
+
+sort_clnt.c:
+ $(RPCCOM) -l sort.x >$@
+
+sort_svc: sort_proc.o sort_svc.o sort_xdr.o
+ $(CC) $(LDFLAGS) -o $@ sort_proc.o sort_svc.o sort_xdr.o $(LIB)
+
+sort_proc.o: sort_proc.c sort.h
+
+sort_svc.c:
+ $(RPCCOM) -s udp sort.x >$@
+
+sort_xdr.c:
+ $(RPCCOM) -c sort.x >$@
+
+sort.h:
+ $(RPCCOM) -h sort.x >$@
+
+clean cleanup:
+ rm -f $(GEN) *.o $(BIN)
+
diff --git a/share/examples/sunrpc/sort/rsort.c b/share/examples/sunrpc/sort/rsort.c
new file mode 100644
index 0000000..5c05ad7
--- /dev/null
+++ b/share/examples/sunrpc/sort/rsort.c
@@ -0,0 +1,43 @@
+/* @(#)rsort.c 2.1 88/08/11 4.0 RPCSRC */
+/*
+ * rsort.c
+ * Client side application which sorts argc, argv.
+ */
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include "sort.h"
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ char *machinename;
+ struct sortstrings args, res;
+ int i;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s machinename [s1 ...]\n", argv[0]);
+ exit(1);
+ }
+ machinename = argv[1];
+ args.ss.ss_len = argc - 2; /* substract off progname, machinename */
+ args.ss.ss_val = &argv[2];
+ res.ss.ss_val = (char **)NULL;
+
+ if ((i = callrpc(machinename, SORTPROG, SORTVERS, SORT,
+ xdr_sortstrings, &args, xdr_sortstrings, &res)))
+ {
+ fprintf(stderr, "%s: call to sort service failed. ", argv[0]);
+ clnt_perrno(i);
+ fprintf(stderr, "\n");
+ exit(1);
+ }
+
+ for (i = 0; i < res.ss.ss_len; i++) {
+ printf("%s\n", res.ss.ss_val[i]);
+ }
+
+ /* should free res here */
+ exit(0);
+}
+
diff --git a/share/examples/sunrpc/sort/sort.x b/share/examples/sunrpc/sort/sort.x
new file mode 100644
index 0000000..629110c
--- /dev/null
+++ b/share/examples/sunrpc/sort/sort.x
@@ -0,0 +1,19 @@
+/* @(#)sort.x 2.1 88/08/11 4.0 RPCSRC */
+/*
+ * The sort procedure receives an array of strings and returns an array
+ * of strings. This toy service handles a maximum of 64 strings.
+ */
+const MAXSORTSIZE = 64;
+const MAXSTRINGLEN = 64;
+
+typedef string str<MAXSTRINGLEN>; /* the string itself */
+
+struct sortstrings {
+ str ss<MAXSORTSIZE>;
+};
+
+program SORTPROG {
+ version SORTVERS {
+ sortstrings SORT(sortstrings) = 1;
+ } = 1;
+} = 22855;
diff --git a/share/examples/sunrpc/sort/sort_proc.c b/share/examples/sunrpc/sort/sort_proc.c
new file mode 100644
index 0000000..5538faf
--- /dev/null
+++ b/share/examples/sunrpc/sort/sort_proc.c
@@ -0,0 +1,27 @@
+/* @(#)sort_proc.c 2.1 88/08/11 4.0 RPCSRC */
+#include <rpc/rpc.h>
+#include "sort.h"
+
+static int
+comparestrings(sp1, sp2)
+ char **sp1, **sp2;
+{
+ return (strcmp(*sp1, *sp2));
+}
+
+struct sortstrings *
+sort_1(ssp)
+ struct sortstrings *ssp;
+{
+ static struct sortstrings ss_res;
+
+ if (ss_res.ss.ss_val != (str *)NULL)
+ free(ss_res.ss.ss_val);
+
+ qsort(ssp->ss.ss_val, ssp->ss.ss_len, sizeof (char *), comparestrings);
+ ss_res.ss.ss_len = ssp->ss.ss_len;
+ ss_res.ss.ss_val = (str *)malloc(ssp->ss.ss_len * sizeof(str *));
+ bcopy(ssp->ss.ss_val, ss_res.ss.ss_val,
+ ssp->ss.ss_len * sizeof(str *));
+ return(&ss_res);
+}
OpenPOWER on IntegriCloud