BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / showmount / showmount.c
index e5a3752..2eb07c2 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1989, 1993
+ * Copyright (c) 1989, 1993, 1995
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
 
 #ifndef lint
 static char copyright[] =
 
 #ifndef lint
 static char copyright[] =
-"@(#) Copyright (c) 1989, 1993\n\
+"@(#) Copyright (c) 1989, 1993, 1995\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif not lint
 
 #ifndef lint
        The Regents of the University of California.  All rights reserved.\n";
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)showmount.c        8.1 (Berkeley) 6/6/93";
+static char sccsid[] = "@(#)showmount.c        8.3 (Berkeley) 3/29/95";
 #endif not lint
 
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #endif not lint
 
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
+
 #include <netdb.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_clnt.h>
 #include <rpc/pmap_prot.h>
 #include <nfs/rpcv2.h>
 #include <netdb.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_clnt.h>
 #include <rpc/pmap_prot.h>
 #include <nfs/rpcv2.h>
+
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <string.h>
+#include <unistd.h>
 
 /* Constant defs */
 #define        ALL     1
 
 /* Constant defs */
 #define        ALL     1
@@ -84,29 +88,30 @@ struct exportslist {
 static struct mountlist *mntdump;
 static struct exportslist *exports;
 static int type = 0;
 static struct mountlist *mntdump;
 static struct exportslist *exports;
 static int type = 0;
-int xdr_mntdump(), xdr_exports();
+
+void   print_dump __P((struct mountlist *));
+void   usage __P((void));
+int    xdr_mntdump __P((XDR *, struct mountlist **));
+int    xdr_exports __P((XDR *, struct exportslist **));
 
 /*
  * This command queries the NFS mount daemon for it's mount list and/or
  * it's exports list and prints them out.
  * See "NFS: Network File System Protocol Specification, RFC1094, Appendix A"
 
 /*
  * This command queries the NFS mount daemon for it's mount list and/or
  * it's exports list and prints them out.
  * See "NFS: Network File System Protocol Specification, RFC1094, Appendix A"
+ * and the "Network File System Protocol XXX.."
  * for detailed information on the protocol.
  */
  * for detailed information on the protocol.
  */
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       register struct mountlist *mntp;
-       register struct exportslist *exp;
-       register struct grouplist *grp;
-       extern char *optarg;
-       extern int optind;
-       register int rpcs = 0;
-       char ch;
-       char *host;
-       int estat;
+       struct exportslist *exp;
+       struct grouplist *grp;
+       int estat, rpcs = 0, mntvers = 1;
+       char ch, *host;
 
 
-       while ((ch = getopt(argc, argv, "ade")) != EOF)
+       while ((ch = getopt(argc, argv, "ade3")) != EOF)
                switch((char)ch) {
                case 'a':
                        if (type == 0) {
                switch((char)ch) {
                case 'a':
                        if (type == 0) {
@@ -125,6 +130,9 @@ main(argc, argv)
                case 'e':
                        rpcs |= DOEXPORTS;
                        break;
                case 'e':
                        rpcs |= DOEXPORTS;
                        break;
+               case '3':
+                       mntvers = 3;
+                       break;
                case '?':
                default:
                        usage();
                case '?':
                default:
                        usage();
@@ -141,19 +149,19 @@ main(argc, argv)
                rpcs = DODUMP;
 
        if (rpcs & DODUMP)
                rpcs = DODUMP;
 
        if (rpcs & DODUMP)
-               if ((estat = callrpc(host, RPCPROG_MNT, RPCMNT_VER1,
+               if ((estat = callrpc(host, RPCPROG_MNT, mntvers,
                        RPCMNT_DUMP, xdr_void, (char *)0,
                        xdr_mntdump, (char *)&mntdump)) != 0) {
                        clnt_perrno(estat);
                        RPCMNT_DUMP, xdr_void, (char *)0,
                        xdr_mntdump, (char *)&mntdump)) != 0) {
                        clnt_perrno(estat);
-                       fprintf(stderr, "Can't do Mountdump rpc\n");
+                       fprintf(stderr, "Can't do Mountdump rpc\n");
                        exit(1);
                }
        if (rpcs & DOEXPORTS)
                        exit(1);
                }
        if (rpcs & DOEXPORTS)
-               if ((estat = callrpc(host, RPCPROG_MNT, RPCMNT_VER1,
+               if ((estat = callrpc(host, RPCPROG_MNT, mntvers,
                        RPCMNT_EXPORT, xdr_void, (char *)0,
                        xdr_exports, (char *)&exports)) != 0) {
                        clnt_perrno(estat);
                        RPCMNT_EXPORT, xdr_void, (char *)0,
                        xdr_exports, (char *)&exports)) != 0) {
                        clnt_perrno(estat);
-                       fprintf(stderr, "Can't do Exports rpc\n");
+                       fprintf(stderr, "Can't do Exports rpc\n");
                        exit(1);
                }
 
                        exit(1);
                }
 
@@ -190,20 +198,20 @@ main(argc, argv)
                        exp = exp->ex_next;
                }
        }
                        exp = exp->ex_next;
                }
        }
+
+       exit(0);
 }
 
 /*
  * Xdr routine for retrieving the mount dump list
  */
 }
 
 /*
  * Xdr routine for retrieving the mount dump list
  */
+int
 xdr_mntdump(xdrsp, mlp)
        XDR *xdrsp;
        struct mountlist **mlp;
 {
 xdr_mntdump(xdrsp, mlp)
        XDR *xdrsp;
        struct mountlist **mlp;
 {
-       register struct mountlist *mp;
-       register struct mountlist *tp;
-       register struct mountlist **otp;
-       int val, val2;
-       int bool;
+       struct mountlist *mp, **otp, *tp;
+       int bool, val, val2;
        char *strp;
 
        *mlp = (struct mountlist *)0;
        char *strp;
 
        *mlp = (struct mountlist *)0;
@@ -276,12 +284,13 @@ next:
 /*
  * Xdr routine to retrieve exports list
  */
 /*
  * Xdr routine to retrieve exports list
  */
+int
 xdr_exports(xdrsp, exp)
        XDR *xdrsp;
        struct exportslist **exp;
 {
 xdr_exports(xdrsp, exp)
        XDR *xdrsp;
        struct exportslist **exp;
 {
-       register struct exportslist *ep;
-       register struct grouplist *gp;
+       struct exportslist *ep;
+       struct grouplist *gp;
        int bool, grpbool;
        char *strp;
 
        int bool, grpbool;
        char *strp;
 
@@ -318,8 +327,10 @@ xdr_exports(xdrsp, exp)
        return (1);
 }
 
        return (1);
 }
 
+void
 usage()
 {
 usage()
 {
+
        fprintf(stderr, "usage: showmount [-ade] host\n");
        exit(1);
 }
        fprintf(stderr, "usage: showmount [-ade] host\n");
        exit(1);
 }
@@ -327,6 +338,7 @@ usage()
 /*
  * Print the binary tree in inorder so that output is sorted.
  */
 /*
  * Print the binary tree in inorder so that output is sorted.
  */
+void
 print_dump(mp)
        struct mountlist *mp;
 {
 print_dump(mp)
        struct mountlist *mp;
 {