Home | History | Annotate | Line # | Download | only in rpc
      1  1.18      tron /*	$NetBSD: pmap_getmaps.c,v 1.18 2013/03/11 20:19:29 tron Exp $	*/
      2   1.3       cgd 
      3   1.1       cgd /*
      4  1.18      tron  * Copyright (c) 2010, Oracle America, Inc.
      5  1.18      tron  *
      6  1.18      tron  * Redistribution and use in source and binary forms, with or without
      7  1.18      tron  * modification, are permitted provided that the following conditions are
      8  1.18      tron  * met:
      9  1.18      tron  *
     10  1.18      tron  *     * Redistributions of source code must retain the above copyright
     11  1.18      tron  *       notice, this list of conditions and the following disclaimer.
     12  1.18      tron  *     * Redistributions in binary form must reproduce the above
     13  1.18      tron  *       copyright notice, this list of conditions and the following
     14  1.18      tron  *       disclaimer in the documentation and/or other materials
     15  1.18      tron  *       provided with the distribution.
     16  1.18      tron  *     * Neither the name of the "Oracle America, Inc." nor the names of its
     17  1.18      tron  *       contributors may be used to endorse or promote products derived
     18  1.18      tron  *       from this software without specific prior written permission.
     19  1.18      tron  *
     20  1.18      tron  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  1.18      tron  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22  1.18      tron  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     23  1.18      tron  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     24  1.18      tron  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     25  1.18      tron  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.18      tron  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     27  1.18      tron  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  1.18      tron  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  1.18      tron  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     30  1.18      tron  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     31  1.18      tron  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1       cgd  */
     33   1.1       cgd 
     34   1.4  christos #include <sys/cdefs.h>
     35   1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     36   1.4  christos #if 0
     37   1.4  christos static char *sccsid = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
     38   1.4  christos static char *sccsid = "@(#)pmap_getmaps.c	2.2 88/08/01 4.0 RPCSRC";
     39   1.4  christos #else
     40  1.18      tron __RCSID("$NetBSD: pmap_getmaps.c,v 1.18 2013/03/11 20:19:29 tron Exp $");
     41   1.4  christos #endif
     42   1.1       cgd #endif
     43   1.1       cgd 
     44   1.1       cgd /*
     45   1.1       cgd  * pmap_getmap.c
     46   1.1       cgd  * Client interface to pmap rpc service.
     47   1.1       cgd  * contains pmap_getmaps, which is only tcp service involved
     48   1.1       cgd  *
     49   1.1       cgd  * Copyright (C) 1984, Sun Microsystems, Inc.
     50   1.1       cgd  */
     51   1.1       cgd 
     52   1.5       jtc #include "namespace.h"
     53   1.8     lukem 
     54   1.8     lukem #include <sys/types.h>
     55   1.8     lukem #include <sys/ioctl.h>
     56   1.1       cgd #include <sys/socket.h>
     57   1.8     lukem 
     58   1.8     lukem #include <net/if.h>
     59   1.8     lukem 
     60  1.13     lukem #include <assert.h>
     61   1.8     lukem #include <errno.h>
     62   1.1       cgd #include <netdb.h>
     63   1.1       cgd #include <stdio.h>
     64   1.4  christos #include <unistd.h>
     65   1.8     lukem 
     66   1.8     lukem #include <rpc/rpc.h>
     67   1.8     lukem #include <rpc/pmap_prot.h>
     68   1.8     lukem #include <rpc/pmap_clnt.h>
     69   1.5       jtc 
     70   1.5       jtc #ifdef __weak_alias
     71  1.15   mycroft __weak_alias(pmap_getmaps,_pmap_getmaps)
     72   1.5       jtc #endif
     73   1.5       jtc 
     74   1.1       cgd #define NAMELEN 255
     75   1.1       cgd #define MAX_BROADCAST_SIZE 1400
     76   1.1       cgd 
     77   1.1       cgd /*
     78   1.1       cgd  * Get a copy of the current port maps.
     79   1.1       cgd  * Calls the pmap service remotely to do get the maps.
     80   1.1       cgd  */
     81   1.1       cgd struct pmaplist *
     82  1.17      matt pmap_getmaps(struct sockaddr_in *address)
     83   1.1       cgd {
     84  1.16  christos 	struct pmaplist *head = NULL;
     85   1.9  christos 	int sock = -1;
     86   1.1       cgd 	struct timeval minutetimeout;
     87   1.8     lukem 	CLIENT *client;
     88  1.13     lukem 
     89  1.13     lukem 	_DIAGASSERT(address != NULL);
     90   1.1       cgd 
     91   1.1       cgd 	minutetimeout.tv_sec = 60;
     92   1.1       cgd 	minutetimeout.tv_usec = 0;
     93   1.1       cgd 	address->sin_port = htons(PMAPPORT);
     94   1.1       cgd 	client = clnttcp_create(address, PMAPPROG,
     95   1.9  christos 	    PMAPVERS, &sock, 50, 500);
     96  1.16  christos 	if (client != NULL) {
     97  1.16  christos 		if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_DUMP,
     98  1.16  christos 		    (xdrproc_t)xdr_void, NULL,
     99  1.11  christos 		    (xdrproc_t)xdr_pmaplist, &head, minutetimeout) !=
    100  1.11  christos 		    RPC_SUCCESS) {
    101   1.1       cgd 			clnt_perror(client, "pmap_getmaps rpc problem");
    102   1.1       cgd 		}
    103   1.1       cgd 		CLNT_DESTROY(client);
    104   1.1       cgd 	}
    105   1.1       cgd 	address->sin_port = 0;
    106   1.1       cgd 	return (head);
    107   1.1       cgd }
    108