xref: /openbsd-src/lib/libc/rpc/pmap_getmaps.c (revision 484854185150d40a092d9e7d24e2c43710eb6a83)
1*48485418Sderaadt /*	$OpenBSD: pmap_getmaps.c,v 1.13 2015/09/02 06:47:19 deraadt Exp $ */
2cb7760d1Smillert 
3df930be7Sderaadt /*
4cb7760d1Smillert  * Copyright (c) 2010, Oracle America, Inc.
5df930be7Sderaadt  *
6cb7760d1Smillert  * Redistribution and use in source and binary forms, with or without
7cb7760d1Smillert  * modification, are permitted provided that the following conditions are
8cb7760d1Smillert  * met:
9df930be7Sderaadt  *
10cb7760d1Smillert  *     * Redistributions of source code must retain the above copyright
11cb7760d1Smillert  *       notice, this list of conditions and the following disclaimer.
12cb7760d1Smillert  *     * Redistributions in binary form must reproduce the above
13cb7760d1Smillert  *       copyright notice, this list of conditions and the following
14cb7760d1Smillert  *       disclaimer in the documentation and/or other materials
15cb7760d1Smillert  *       provided with the distribution.
16cb7760d1Smillert  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17cb7760d1Smillert  *       contributors may be used to endorse or promote products derived
18cb7760d1Smillert  *       from this software without specific prior written permission.
19df930be7Sderaadt  *
20cb7760d1Smillert  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21cb7760d1Smillert  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22cb7760d1Smillert  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23cb7760d1Smillert  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24cb7760d1Smillert  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25cb7760d1Smillert  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26cb7760d1Smillert  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27cb7760d1Smillert  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28cb7760d1Smillert  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29cb7760d1Smillert  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30cb7760d1Smillert  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31cb7760d1Smillert  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32df930be7Sderaadt  */
33df930be7Sderaadt 
34df930be7Sderaadt /*
35df930be7Sderaadt  * pmap_getmap.c
36df930be7Sderaadt  * Client interface to pmap rpc service.
37df930be7Sderaadt  * contains pmap_getmaps, which is only tcp service involved
38df930be7Sderaadt  */
39df930be7Sderaadt 
40df930be7Sderaadt #include <rpc/rpc.h>
41df930be7Sderaadt #include <rpc/pmap_prot.h>
42df930be7Sderaadt #include <rpc/pmap_clnt.h>
43df930be7Sderaadt #include <sys/socket.h>
44df930be7Sderaadt #include <netdb.h>
45df930be7Sderaadt #include <stdio.h>
46df930be7Sderaadt #include <errno.h>
478e26201bSmillert #include <unistd.h>
48df930be7Sderaadt #include <net/if.h>
49df930be7Sderaadt #include <sys/ioctl.h>
50df930be7Sderaadt #define NAMELEN 255
51df930be7Sderaadt #define MAX_BROADCAST_SIZE 1400
52df930be7Sderaadt 
53df930be7Sderaadt /*
54df930be7Sderaadt  * Get a copy of the current port maps.
55df930be7Sderaadt  * Calls the pmap service remotely to do get the maps.
56df930be7Sderaadt  */
57df930be7Sderaadt struct pmaplist *
pmap_getmaps(struct sockaddr_in * address)58384ec30aSotto pmap_getmaps(struct sockaddr_in *address)
59df930be7Sderaadt {
603f820ea1Skrw 	struct pmaplist *head = NULL;
6179a9d2e3Sderaadt 	int sock = -1;
62df930be7Sderaadt 	struct timeval minutetimeout;
6341aa8645Sderaadt 	CLIENT *client;
64df930be7Sderaadt 
65df930be7Sderaadt 	minutetimeout.tv_sec = 60;
66df930be7Sderaadt 	minutetimeout.tv_usec = 0;
67df930be7Sderaadt 	address->sin_port = htons(PMAPPORT);
68df930be7Sderaadt 	client = clnttcp_create(address, PMAPPROG,
6979a9d2e3Sderaadt 	    PMAPVERS, &sock, 50, 500);
703f820ea1Skrw 	if (client != NULL) {
71df930be7Sderaadt 		if (CLNT_CALL(client, PMAPPROC_DUMP, xdr_void, NULL, xdr_pmaplist,
72df930be7Sderaadt 		    &head, minutetimeout) != RPC_SUCCESS) {
73*48485418Sderaadt 			CLNT_DESTROY(client);
74*48485418Sderaadt 			return (NULL);
75df930be7Sderaadt 		}
76df930be7Sderaadt 		CLNT_DESTROY(client);
77df930be7Sderaadt 	}
78df930be7Sderaadt 	address->sin_port = 0;
79df930be7Sderaadt 	return (head);
80df930be7Sderaadt }
81