xref: /netbsd-src/lib/libc/rpc/pmap_getmaps.c (revision 47c0e0c312cd964546204bd0febab9a56fa11df9)
1*47c0e0c3Stron /*	$NetBSD: pmap_getmaps.c,v 1.18 2013/03/11 20:19:29 tron Exp $	*/
29e15c989Scgd 
363d7b677Scgd /*
4*47c0e0c3Stron  * Copyright (c) 2010, Oracle America, Inc.
563d7b677Scgd  *
6*47c0e0c3Stron  * Redistribution and use in source and binary forms, with or without
7*47c0e0c3Stron  * modification, are permitted provided that the following conditions are
8*47c0e0c3Stron  * met:
963d7b677Scgd  *
10*47c0e0c3Stron  *     * Redistributions of source code must retain the above copyright
11*47c0e0c3Stron  *       notice, this list of conditions and the following disclaimer.
12*47c0e0c3Stron  *     * Redistributions in binary form must reproduce the above
13*47c0e0c3Stron  *       copyright notice, this list of conditions and the following
14*47c0e0c3Stron  *       disclaimer in the documentation and/or other materials
15*47c0e0c3Stron  *       provided with the distribution.
16*47c0e0c3Stron  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17*47c0e0c3Stron  *       contributors may be used to endorse or promote products derived
18*47c0e0c3Stron  *       from this software without specific prior written permission.
1963d7b677Scgd  *
20*47c0e0c3Stron  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*47c0e0c3Stron  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*47c0e0c3Stron  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*47c0e0c3Stron  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24*47c0e0c3Stron  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25*47c0e0c3Stron  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*47c0e0c3Stron  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27*47c0e0c3Stron  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*47c0e0c3Stron  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29*47c0e0c3Stron  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30*47c0e0c3Stron  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31*47c0e0c3Stron  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3263d7b677Scgd  */
3363d7b677Scgd 
34c63c52b2Schristos #include <sys/cdefs.h>
3563d7b677Scgd #if defined(LIBC_SCCS) && !defined(lint)
36c63c52b2Schristos #if 0
37c63c52b2Schristos static char *sccsid = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
38c63c52b2Schristos static char *sccsid = "@(#)pmap_getmaps.c	2.2 88/08/01 4.0 RPCSRC";
39c63c52b2Schristos #else
40*47c0e0c3Stron __RCSID("$NetBSD: pmap_getmaps.c,v 1.18 2013/03/11 20:19:29 tron Exp $");
41c63c52b2Schristos #endif
4263d7b677Scgd #endif
4363d7b677Scgd 
4463d7b677Scgd /*
4563d7b677Scgd  * pmap_getmap.c
4663d7b677Scgd  * Client interface to pmap rpc service.
4763d7b677Scgd  * contains pmap_getmaps, which is only tcp service involved
4863d7b677Scgd  *
4963d7b677Scgd  * Copyright (C) 1984, Sun Microsystems, Inc.
5063d7b677Scgd  */
5163d7b677Scgd 
5243fa6fe3Sjtc #include "namespace.h"
5346e6c5e8Slukem 
5446e6c5e8Slukem #include <sys/types.h>
5546e6c5e8Slukem #include <sys/ioctl.h>
5646e6c5e8Slukem #include <sys/socket.h>
5746e6c5e8Slukem 
5846e6c5e8Slukem #include <net/if.h>
5946e6c5e8Slukem 
60b48252f3Slukem #include <assert.h>
6146e6c5e8Slukem #include <errno.h>
6246e6c5e8Slukem #include <netdb.h>
6346e6c5e8Slukem #include <stdio.h>
6446e6c5e8Slukem #include <unistd.h>
6546e6c5e8Slukem 
6663d7b677Scgd #include <rpc/rpc.h>
6763d7b677Scgd #include <rpc/pmap_prot.h>
6863d7b677Scgd #include <rpc/pmap_clnt.h>
6943fa6fe3Sjtc 
7043fa6fe3Sjtc #ifdef __weak_alias
__weak_alias(pmap_getmaps,_pmap_getmaps)7160549036Smycroft __weak_alias(pmap_getmaps,_pmap_getmaps)
7243fa6fe3Sjtc #endif
7343fa6fe3Sjtc 
7463d7b677Scgd #define NAMELEN 255
7563d7b677Scgd #define MAX_BROADCAST_SIZE 1400
7663d7b677Scgd 
7763d7b677Scgd /*
7863d7b677Scgd  * Get a copy of the current port maps.
7963d7b677Scgd  * Calls the pmap service remotely to do get the maps.
8063d7b677Scgd  */
8163d7b677Scgd struct pmaplist *
82adb74221Smatt pmap_getmaps(struct sockaddr_in *address)
8363d7b677Scgd {
84deb154d2Schristos 	struct pmaplist *head = NULL;
851325a26dSchristos 	int sock = -1;
8663d7b677Scgd 	struct timeval minutetimeout;
8746e6c5e8Slukem 	CLIENT *client;
8863d7b677Scgd 
89b48252f3Slukem 	_DIAGASSERT(address != NULL);
90b48252f3Slukem 
9163d7b677Scgd 	minutetimeout.tv_sec = 60;
9263d7b677Scgd 	minutetimeout.tv_usec = 0;
9363d7b677Scgd 	address->sin_port = htons(PMAPPORT);
9463d7b677Scgd 	client = clnttcp_create(address, PMAPPROG,
951325a26dSchristos 	    PMAPVERS, &sock, 50, 500);
96deb154d2Schristos 	if (client != NULL) {
97deb154d2Schristos 		if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_DUMP,
98deb154d2Schristos 		    (xdrproc_t)xdr_void, NULL,
99caaf1528Schristos 		    (xdrproc_t)xdr_pmaplist, &head, minutetimeout) !=
100caaf1528Schristos 		    RPC_SUCCESS) {
10163d7b677Scgd 			clnt_perror(client, "pmap_getmaps rpc problem");
10263d7b677Scgd 		}
10363d7b677Scgd 		CLNT_DESTROY(client);
10463d7b677Scgd 	}
10563d7b677Scgd 	address->sin_port = 0;
10663d7b677Scgd 	return (head);
10763d7b677Scgd }
108