xref: /freebsd/lib/libc/rpc/pmap_getmaps.c (revision fd8e4ebc8c18caec3eefac6527831f9ee6a92959)
18360efbdSAlfred Perlstein /*	$NetBSD: pmap_getmaps.c,v 1.16 2000/07/06 03:10:34 christos Exp $	*/
28360efbdSAlfred Perlstein 
399064799SGarrett Wollman /*
499064799SGarrett Wollman  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
599064799SGarrett Wollman  * unrestricted use provided that this legend is included on all tape
699064799SGarrett Wollman  * media and as a part of the software program in whole or part.  Users
799064799SGarrett Wollman  * may copy or modify Sun RPC without charge, but are not authorized
899064799SGarrett Wollman  * to license or distribute it to anyone else except as part of a product or
999064799SGarrett Wollman  * program developed by the user.
1099064799SGarrett Wollman  *
1199064799SGarrett Wollman  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
1299064799SGarrett Wollman  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1399064799SGarrett Wollman  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1499064799SGarrett Wollman  *
1599064799SGarrett Wollman  * Sun RPC is provided with no support and without any obligation on the
1699064799SGarrett Wollman  * part of Sun Microsystems, Inc. to assist in its use, correction,
1799064799SGarrett Wollman  * modification or enhancement.
1899064799SGarrett Wollman  *
1999064799SGarrett Wollman  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
2099064799SGarrett Wollman  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
2199064799SGarrett Wollman  * OR ANY PART THEREOF.
2299064799SGarrett Wollman  *
2399064799SGarrett Wollman  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
2499064799SGarrett Wollman  * or profits or other special, indirect and consequential damages, even if
2599064799SGarrett Wollman  * Sun has been advised of the possibility of such damages.
2699064799SGarrett Wollman  *
2799064799SGarrett Wollman  * Sun Microsystems, Inc.
2899064799SGarrett Wollman  * 2550 Garcia Avenue
2999064799SGarrett Wollman  * Mountain View, California  94043
3099064799SGarrett Wollman  */
3199064799SGarrett Wollman 
328360efbdSAlfred Perlstein #include <sys/cdefs.h>
3399064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint)
3499064799SGarrett Wollman /*static char *sccsid = "from: @(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
3599064799SGarrett Wollman /*static char *sccsid = "from: @(#)pmap_getmaps.c	2.2 88/08/01 4.0 RPCSRC";*/
367f3dea24SPeter Wemm static char *rcsid = "$FreeBSD$";
3799064799SGarrett Wollman #endif
3899064799SGarrett Wollman 
3999064799SGarrett Wollman /*
4099064799SGarrett Wollman  * pmap_getmap.c
4199064799SGarrett Wollman  * Client interface to pmap rpc service.
4299064799SGarrett Wollman  * contains pmap_getmaps, which is only tcp service involved
4399064799SGarrett Wollman  *
4499064799SGarrett Wollman  * Copyright (C) 1984, Sun Microsystems, Inc.
4599064799SGarrett Wollman  */
4699064799SGarrett Wollman 
47d201fe46SDaniel Eischen #include "namespace.h"
488360efbdSAlfred Perlstein #include <sys/types.h>
4999064799SGarrett Wollman #include <sys/socket.h>
508360efbdSAlfred Perlstein #include <sys/ioctl.h>
518360efbdSAlfred Perlstein 
52fd8e4ebcSMike Barcroft #include <arpa/inet.h>
538360efbdSAlfred Perlstein #include <net/if.h>
548360efbdSAlfred Perlstein 
558360efbdSAlfred Perlstein #include <assert.h>
568360efbdSAlfred Perlstein #include <errno.h>
5799064799SGarrett Wollman #include <netdb.h>
5899064799SGarrett Wollman #include <stdio.h>
594c3af266SPoul-Henning Kamp #include <unistd.h>
608360efbdSAlfred Perlstein 
618360efbdSAlfred Perlstein #include <rpc/rpc.h>
628360efbdSAlfred Perlstein #include <rpc/pmap_prot.h>
638360efbdSAlfred Perlstein #include <rpc/pmap_clnt.h>
64d201fe46SDaniel Eischen #include "un-namespace.h"
65d201fe46SDaniel Eischen 
6699064799SGarrett Wollman #define NAMELEN 255
6799064799SGarrett Wollman #define MAX_BROADCAST_SIZE 1400
6899064799SGarrett Wollman 
6999064799SGarrett Wollman /*
7099064799SGarrett Wollman  * Get a copy of the current port maps.
7199064799SGarrett Wollman  * Calls the pmap service remotely to do get the maps.
7299064799SGarrett Wollman  */
7399064799SGarrett Wollman struct pmaplist *
7499064799SGarrett Wollman pmap_getmaps(address)
7599064799SGarrett Wollman 	 struct sockaddr_in *address;
7699064799SGarrett Wollman {
778360efbdSAlfred Perlstein 	struct pmaplist *head = NULL;
788360efbdSAlfred Perlstein 	int sock = -1;
7999064799SGarrett Wollman 	struct timeval minutetimeout;
808360efbdSAlfred Perlstein 	CLIENT *client;
818360efbdSAlfred Perlstein 
828360efbdSAlfred Perlstein 	assert(address != NULL);
8399064799SGarrett Wollman 
8499064799SGarrett Wollman 	minutetimeout.tv_sec = 60;
8599064799SGarrett Wollman 	minutetimeout.tv_usec = 0;
8699064799SGarrett Wollman 	address->sin_port = htons(PMAPPORT);
8799064799SGarrett Wollman 	client = clnttcp_create(address, PMAPPROG,
888360efbdSAlfred Perlstein 	    PMAPVERS, &sock, 50, 500);
898360efbdSAlfred Perlstein 	if (client != NULL) {
908360efbdSAlfred Perlstein 		if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_DUMP,
918360efbdSAlfred Perlstein 		    (xdrproc_t)xdr_void, NULL,
928360efbdSAlfred Perlstein 		    (xdrproc_t)xdr_pmaplist, &head, minutetimeout) !=
938360efbdSAlfred Perlstein 		    RPC_SUCCESS) {
9499064799SGarrett Wollman 			clnt_perror(client, "pmap_getmaps rpc problem");
9599064799SGarrett Wollman 		}
9699064799SGarrett Wollman 		CLNT_DESTROY(client);
9799064799SGarrett Wollman 	}
9899064799SGarrett Wollman 	address->sin_port = 0;
9999064799SGarrett Wollman 	return (head);
10099064799SGarrett Wollman }
101