2 * Copyright (c) 1989, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static const char copyright[] =
39 "@(#) Copyright (c) 1989, 1993, 1995\n\
40 The Regents of the University of California. All rights reserved.\n";
45 static char sccsid[] = "@(#)showmount.c 8.3 (Berkeley) 3/29/95";
47 static const char rcsid[] =
51 #include <sys/types.h>
52 #include <sys/queue.h>
54 #include <sys/socket.h>
55 #include <sys/socketvar.h>
60 #include <rpc/pmap_clnt.h>
61 #include <rpc/pmap_prot.h>
62 #include <nfs/rpcv2.h>
77 struct mountlist *ml_left;
78 struct mountlist *ml_right;
79 char ml_host[RPCMNT_NAMELEN+1];
80 char ml_dirp[RPCMNT_PATHLEN+1];
84 struct grouplist *gr_next;
85 char gr_name[RPCMNT_NAMELEN+1];
89 struct exportslist *ex_next;
90 struct grouplist *ex_groups;
91 char ex_dirp[RPCMNT_PATHLEN+1];
94 static struct mountlist *mntdump;
95 static struct exportslist *exports;
98 void print_dump __P((struct mountlist *));
99 static void usage __P((void));
100 int xdr_mntdump __P((XDR *, struct mountlist **));
101 int xdr_exports __P((XDR *, struct exportslist **));
102 int tcp_callrpc __P((char *host,
103 int prognum, int versnum, int procnum,
104 xdrproc_t inproc, char *in,
105 xdrproc_t outproc, char *out));
108 * This command queries the NFS mount daemon for it's mount list and/or
109 * it's exports list and prints them out.
110 * See "NFS: Network File System Protocol Specification, RFC1094, Appendix A"
111 * and the "Network File System Protocol XXX.."
112 * for detailed information on the protocol.
119 register struct exportslist *exp;
120 register struct grouplist *grp;
121 register int rpcs = 0, mntvers = 1;
126 while ((ch = getopt(argc, argv, "ade3")) != -1)
164 if ((estat = tcp_callrpc(host, RPCPROG_MNT, mntvers,
165 RPCMNT_DUMP, xdr_void, (char *)0,
166 xdr_mntdump, (char *)&mntdump)) != 0) {
168 errx(1, "can't do mountdump rpc");
170 if (rpcs & DOEXPORTS)
171 if ((estat = tcp_callrpc(host, RPCPROG_MNT, mntvers,
172 RPCMNT_EXPORT, xdr_void, (char *)0,
173 xdr_exports, (char *)&exports)) != 0) {
175 errx(1, "can't do exports rpc");
178 /* Now just print out the results */
182 printf("All mount points on %s:\n", host);
185 printf("Directories on %s:\n", host);
188 printf("Hosts on %s:\n", host);
193 if (rpcs & DOEXPORTS) {
194 printf("Exports list on %s:\n", host);
197 printf("%-35s", exp->ex_dirp);
198 grp = exp->ex_groups;
200 printf("Everyone\n");
203 printf("%s ", grp->gr_name);
215 * tcp_callrpc has the same interface as callrpc, but tries to
216 * use tcp as transport method in order to handle large replies.
220 tcp_callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
231 struct sockaddr_in server_addr;
234 struct timeval timeout;
237 hp = gethostbyname(host);
240 return ((int) RPC_UNKNOWNHOST);
242 memset(&server_addr,0,sizeof(server_addr));
243 memcpy((char *) &server_addr.sin_addr,
246 server_addr.sin_len = sizeof(struct sockaddr_in);
247 server_addr.sin_family =AF_INET;
248 server_addr.sin_port = 0;
252 client = clnttcp_create(&server_addr,
254 (u_long) versnum, &sock, 0, 0);
258 server_addr.sin_port = 0;
260 client = clntudp_create(&server_addr,
267 return ((int) rpc_createerr.cf_stat);
271 rval = (int) clnt_call(client, procnum,
275 clnt_destroy(client);
280 * Xdr routine for retrieving the mount dump list
283 xdr_mntdump(xdrsp, mlp)
285 struct mountlist **mlp;
287 register struct mountlist *mp;
288 register struct mountlist *tp;
289 register struct mountlist **otp;
294 *mlp = (struct mountlist *)0;
295 if (!xdr_bool(xdrsp, &bool))
298 mp = (struct mountlist *)malloc(sizeof(struct mountlist));
301 mp->ml_left = mp->ml_right = (struct mountlist *)0;
303 if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN))
306 if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN))
310 * Build a binary tree on sorted order of either host or dirp.
311 * Drop any duplications.
318 val = strcmp(mp->ml_host, tp->ml_host);
319 val2 = strcmp(mp->ml_dirp, tp->ml_dirp);
355 if (!xdr_bool(xdrsp, &bool))
362 * Xdr routine to retrieve exports list
365 xdr_exports(xdrsp, exp)
367 struct exportslist **exp;
369 register struct exportslist *ep;
370 register struct grouplist *gp;
374 *exp = (struct exportslist *)0;
375 if (!xdr_bool(xdrsp, &bool))
378 ep = (struct exportslist *)malloc(sizeof(struct exportslist));
381 ep->ex_groups = (struct grouplist *)0;
383 if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN))
385 if (!xdr_bool(xdrsp, &grpbool))
388 gp = (struct grouplist *)malloc(sizeof(struct grouplist));
392 if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN))
394 gp->gr_next = ep->ex_groups;
396 if (!xdr_bool(xdrsp, &grpbool))
401 if (!xdr_bool(xdrsp, &bool))
410 fprintf(stderr, "usage: showmount [-ade3] host\n");
415 * Print the binary tree in inorder so that output is sorted.
419 struct mountlist *mp;
425 print_dump(mp->ml_left);
428 printf("%s:%s\n", mp->ml_host, mp->ml_dirp);
431 printf("%s\n", mp->ml_dirp);
434 printf("%s\n", mp->ml_host);
438 print_dump(mp->ml_right);