xref: /freebsd/lib/libc/rpc/pmap_getmaps.c (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
18360efbdSAlfred Perlstein /*	$NetBSD: pmap_getmaps.c,v 1.16 2000/07/06 03:10:34 christos Exp $	*/
28360efbdSAlfred Perlstein 
32e322d37SHiroki Sato /*-
4*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
5*8a16b7a1SPedro F. Giffuni  *
62e322d37SHiroki Sato  * Copyright (c) 2009, Sun Microsystems, Inc.
72e322d37SHiroki Sato  * All rights reserved.
899064799SGarrett Wollman  *
92e322d37SHiroki Sato  * Redistribution and use in source and binary forms, with or without
102e322d37SHiroki Sato  * modification, are permitted provided that the following conditions are met:
112e322d37SHiroki Sato  * - Redistributions of source code must retain the above copyright notice,
122e322d37SHiroki Sato  *   this list of conditions and the following disclaimer.
132e322d37SHiroki Sato  * - Redistributions in binary form must reproduce the above copyright notice,
142e322d37SHiroki Sato  *   this list of conditions and the following disclaimer in the documentation
152e322d37SHiroki Sato  *   and/or other materials provided with the distribution.
162e322d37SHiroki Sato  * - Neither the name of Sun Microsystems, Inc. nor the names of its
172e322d37SHiroki Sato  *   contributors may be used to endorse or promote products derived
182e322d37SHiroki Sato  *   from this software without specific prior written permission.
1999064799SGarrett Wollman  *
202e322d37SHiroki Sato  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
212e322d37SHiroki Sato  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
222e322d37SHiroki Sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
232e322d37SHiroki Sato  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
242e322d37SHiroki Sato  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
252e322d37SHiroki Sato  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
262e322d37SHiroki Sato  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
272e322d37SHiroki Sato  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
282e322d37SHiroki Sato  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
292e322d37SHiroki Sato  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
302e322d37SHiroki Sato  * POSSIBILITY OF SUCH DAMAGE.
3199064799SGarrett Wollman  */
3299064799SGarrett Wollman 
3399064799SGarrett Wollman /*
3499064799SGarrett Wollman  * pmap_getmap.c
3599064799SGarrett Wollman  * Client interface to pmap rpc service.
3699064799SGarrett Wollman  * contains pmap_getmaps, which is only tcp service involved
3799064799SGarrett Wollman  *
3899064799SGarrett Wollman  * Copyright (C) 1984, Sun Microsystems, Inc.
3999064799SGarrett Wollman  */
4099064799SGarrett Wollman 
41d201fe46SDaniel Eischen #include "namespace.h"
428360efbdSAlfred Perlstein #include <sys/types.h>
4399064799SGarrett Wollman #include <sys/socket.h>
448360efbdSAlfred Perlstein #include <sys/ioctl.h>
458360efbdSAlfred Perlstein 
46fd8e4ebcSMike Barcroft #include <arpa/inet.h>
478360efbdSAlfred Perlstein #include <net/if.h>
488360efbdSAlfred Perlstein 
498360efbdSAlfred Perlstein #include <assert.h>
508360efbdSAlfred Perlstein #include <errno.h>
5199064799SGarrett Wollman #include <netdb.h>
5299064799SGarrett Wollman #include <stdio.h>
534c3af266SPoul-Henning Kamp #include <unistd.h>
548360efbdSAlfred Perlstein 
558360efbdSAlfred Perlstein #include <rpc/rpc.h>
568360efbdSAlfred Perlstein #include <rpc/pmap_prot.h>
578360efbdSAlfred Perlstein #include <rpc/pmap_clnt.h>
58d201fe46SDaniel Eischen #include "un-namespace.h"
59d201fe46SDaniel Eischen 
6099064799SGarrett Wollman #define NAMELEN 255
6199064799SGarrett Wollman #define MAX_BROADCAST_SIZE 1400
6299064799SGarrett Wollman 
6399064799SGarrett Wollman /*
6499064799SGarrett Wollman  * Get a copy of the current port maps.
6599064799SGarrett Wollman  * Calls the pmap service remotely to do get the maps.
6699064799SGarrett Wollman  */
6799064799SGarrett Wollman struct pmaplist *
pmap_getmaps(struct sockaddr_in * address)68587cf682SCraig Rodrigues pmap_getmaps(struct sockaddr_in *address)
6999064799SGarrett Wollman {
708360efbdSAlfred Perlstein 	struct pmaplist *head = NULL;
718360efbdSAlfred Perlstein 	int sock = -1;
7299064799SGarrett Wollman 	struct timeval minutetimeout;
738360efbdSAlfred Perlstein 	CLIENT *client;
748360efbdSAlfred Perlstein 
758360efbdSAlfred Perlstein 	assert(address != NULL);
7699064799SGarrett Wollman 
7799064799SGarrett Wollman 	minutetimeout.tv_sec = 60;
7899064799SGarrett Wollman 	minutetimeout.tv_usec = 0;
7999064799SGarrett Wollman 	address->sin_port = htons(PMAPPORT);
8099064799SGarrett Wollman 	client = clnttcp_create(address, PMAPPROG,
818360efbdSAlfred Perlstein 	    PMAPVERS, &sock, 50, 500);
828360efbdSAlfred Perlstein 	if (client != NULL) {
838360efbdSAlfred Perlstein 		if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_DUMP,
848360efbdSAlfred Perlstein 		    (xdrproc_t)xdr_void, NULL,
858360efbdSAlfred Perlstein 		    (xdrproc_t)xdr_pmaplist, &head, minutetimeout) !=
868360efbdSAlfred Perlstein 		    RPC_SUCCESS) {
8799064799SGarrett Wollman 			clnt_perror(client, "pmap_getmaps rpc problem");
8899064799SGarrett Wollman 		}
8999064799SGarrett Wollman 		CLNT_DESTROY(client);
9099064799SGarrett Wollman 	}
9199064799SGarrett Wollman 	address->sin_port = 0;
9299064799SGarrett Wollman 	return (head);
9399064799SGarrett Wollman }
94