xref: /freebsd/lib/libc/rpc/pmap_getmaps.c (revision d201fe46e355212750b727061e6a7ac005267852)
199064799SGarrett Wollman /*
299064799SGarrett Wollman  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
399064799SGarrett Wollman  * unrestricted use provided that this legend is included on all tape
499064799SGarrett Wollman  * media and as a part of the software program in whole or part.  Users
599064799SGarrett Wollman  * may copy or modify Sun RPC without charge, but are not authorized
699064799SGarrett Wollman  * to license or distribute it to anyone else except as part of a product or
799064799SGarrett Wollman  * program developed by the user.
899064799SGarrett Wollman  *
999064799SGarrett Wollman  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
1099064799SGarrett Wollman  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1199064799SGarrett Wollman  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1299064799SGarrett Wollman  *
1399064799SGarrett Wollman  * Sun RPC is provided with no support and without any obligation on the
1499064799SGarrett Wollman  * part of Sun Microsystems, Inc. to assist in its use, correction,
1599064799SGarrett Wollman  * modification or enhancement.
1699064799SGarrett Wollman  *
1799064799SGarrett Wollman  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
1899064799SGarrett Wollman  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
1999064799SGarrett Wollman  * OR ANY PART THEREOF.
2099064799SGarrett Wollman  *
2199064799SGarrett Wollman  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
2299064799SGarrett Wollman  * or profits or other special, indirect and consequential damages, even if
2399064799SGarrett Wollman  * Sun has been advised of the possibility of such damages.
2499064799SGarrett Wollman  *
2599064799SGarrett Wollman  * Sun Microsystems, Inc.
2699064799SGarrett Wollman  * 2550 Garcia Avenue
2799064799SGarrett Wollman  * Mountain View, California  94043
2899064799SGarrett Wollman  */
2999064799SGarrett Wollman 
3099064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint)
3199064799SGarrett Wollman /*static char *sccsid = "from: @(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
3299064799SGarrett Wollman /*static char *sccsid = "from: @(#)pmap_getmaps.c	2.2 88/08/01 4.0 RPCSRC";*/
337f3dea24SPeter Wemm static char *rcsid = "$FreeBSD$";
3499064799SGarrett Wollman #endif
3599064799SGarrett Wollman 
3699064799SGarrett Wollman /*
3799064799SGarrett Wollman  * pmap_getmap.c
3899064799SGarrett Wollman  * Client interface to pmap rpc service.
3999064799SGarrett Wollman  * contains pmap_getmaps, which is only tcp service involved
4099064799SGarrett Wollman  *
4199064799SGarrett Wollman  * Copyright (C) 1984, Sun Microsystems, Inc.
4299064799SGarrett Wollman  */
4399064799SGarrett Wollman 
44d201fe46SDaniel Eischen #include "namespace.h"
4599064799SGarrett Wollman #include <rpc/rpc.h>
4699064799SGarrett Wollman #include <rpc/pmap_prot.h>
4799064799SGarrett Wollman #include <rpc/pmap_clnt.h>
4899064799SGarrett Wollman #include <sys/socket.h>
4999064799SGarrett Wollman #include <netdb.h>
5099064799SGarrett Wollman #include <stdio.h>
514c3af266SPoul-Henning Kamp #include <unistd.h>
5299064799SGarrett Wollman #include <errno.h>
5399064799SGarrett Wollman #include <net/if.h>
5499064799SGarrett Wollman #include <sys/ioctl.h>
55d201fe46SDaniel Eischen #include "un-namespace.h"
56d201fe46SDaniel Eischen 
5799064799SGarrett Wollman #define NAMELEN 255
5899064799SGarrett Wollman #define MAX_BROADCAST_SIZE 1400
5999064799SGarrett Wollman 
6099064799SGarrett Wollman /*
6199064799SGarrett Wollman  * Get a copy of the current port maps.
6299064799SGarrett Wollman  * Calls the pmap service remotely to do get the maps.
6399064799SGarrett Wollman  */
6499064799SGarrett Wollman struct pmaplist *
6599064799SGarrett Wollman pmap_getmaps(address)
6699064799SGarrett Wollman 	 struct sockaddr_in *address;
6799064799SGarrett Wollman {
6899064799SGarrett Wollman 	struct pmaplist *head = (struct pmaplist *)NULL;
6999064799SGarrett Wollman 	int socket = -1;
7099064799SGarrett Wollman 	struct timeval minutetimeout;
7199064799SGarrett Wollman 	register CLIENT *client;
7299064799SGarrett Wollman 
7399064799SGarrett Wollman 	minutetimeout.tv_sec = 60;
7499064799SGarrett Wollman 	minutetimeout.tv_usec = 0;
7599064799SGarrett Wollman 	address->sin_port = htons(PMAPPORT);
7699064799SGarrett Wollman 	client = clnttcp_create(address, PMAPPROG,
7799064799SGarrett Wollman 	    PMAPVERS, &socket, 50, 500);
7899064799SGarrett Wollman 	if (client != (CLIENT *)NULL) {
7999064799SGarrett Wollman 		if (CLNT_CALL(client, PMAPPROC_DUMP, xdr_void, NULL, xdr_pmaplist,
8099064799SGarrett Wollman 		    &head, minutetimeout) != RPC_SUCCESS) {
8199064799SGarrett Wollman 			clnt_perror(client, "pmap_getmaps rpc problem");
8299064799SGarrett Wollman 		}
8399064799SGarrett Wollman 		CLNT_DESTROY(client);
8499064799SGarrett Wollman 	}
85df7da806SPeter Wemm 	if (socket != -1)
869233c4d9SJason Evans 		(void)_close(socket);
8799064799SGarrett Wollman 	address->sin_port = 0;
8899064799SGarrett Wollman 	return (head);
8999064799SGarrett Wollman }
90