18360efbdSAlfred Perlstein /* $NetBSD: pmap_getmaps.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */ 28360efbdSAlfred Perlstein 3*2e322d37SHiroki Sato /*- 4*2e322d37SHiroki Sato * Copyright (c) 2009, Sun Microsystems, Inc. 5*2e322d37SHiroki Sato * All rights reserved. 699064799SGarrett Wollman * 7*2e322d37SHiroki Sato * Redistribution and use in source and binary forms, with or without 8*2e322d37SHiroki Sato * modification, are permitted provided that the following conditions are met: 9*2e322d37SHiroki Sato * - Redistributions of source code must retain the above copyright notice, 10*2e322d37SHiroki Sato * this list of conditions and the following disclaimer. 11*2e322d37SHiroki Sato * - Redistributions in binary form must reproduce the above copyright notice, 12*2e322d37SHiroki Sato * this list of conditions and the following disclaimer in the documentation 13*2e322d37SHiroki Sato * and/or other materials provided with the distribution. 14*2e322d37SHiroki Sato * - Neither the name of Sun Microsystems, Inc. nor the names of its 15*2e322d37SHiroki Sato * contributors may be used to endorse or promote products derived 16*2e322d37SHiroki Sato * from this software without specific prior written permission. 1799064799SGarrett Wollman * 18*2e322d37SHiroki Sato * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*2e322d37SHiroki Sato * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*2e322d37SHiroki Sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*2e322d37SHiroki Sato * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*2e322d37SHiroki Sato * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*2e322d37SHiroki Sato * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*2e322d37SHiroki Sato * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*2e322d37SHiroki Sato * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*2e322d37SHiroki Sato * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*2e322d37SHiroki Sato * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*2e322d37SHiroki Sato * POSSIBILITY OF SUCH DAMAGE. 2999064799SGarrett Wollman */ 3099064799SGarrett Wollman 3199064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint) 32a986ef57SDavid E. O'Brien static char *sccsid2 = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro"; 33d3d20c82SDavid E. O'Brien static char *sccsid = "@(#)pmap_getmaps.c 2.2 88/08/01 4.0 RPCSRC"; 3499064799SGarrett Wollman #endif 35d3d20c82SDavid E. O'Brien #include <sys/cdefs.h> 36d3d20c82SDavid E. O'Brien __FBSDID("$FreeBSD$"); 3799064799SGarrett Wollman 3899064799SGarrett Wollman /* 3999064799SGarrett Wollman * pmap_getmap.c 4099064799SGarrett Wollman * Client interface to pmap rpc service. 4199064799SGarrett Wollman * contains pmap_getmaps, which is only tcp service involved 4299064799SGarrett Wollman * 4399064799SGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc. 4499064799SGarrett Wollman */ 4599064799SGarrett Wollman 46d201fe46SDaniel Eischen #include "namespace.h" 478360efbdSAlfred Perlstein #include <sys/types.h> 4899064799SGarrett Wollman #include <sys/socket.h> 498360efbdSAlfred Perlstein #include <sys/ioctl.h> 508360efbdSAlfred Perlstein 51fd8e4ebcSMike Barcroft #include <arpa/inet.h> 528360efbdSAlfred Perlstein #include <net/if.h> 538360efbdSAlfred Perlstein 548360efbdSAlfred Perlstein #include <assert.h> 558360efbdSAlfred Perlstein #include <errno.h> 5699064799SGarrett Wollman #include <netdb.h> 5799064799SGarrett Wollman #include <stdio.h> 584c3af266SPoul-Henning Kamp #include <unistd.h> 598360efbdSAlfred Perlstein 608360efbdSAlfred Perlstein #include <rpc/rpc.h> 618360efbdSAlfred Perlstein #include <rpc/pmap_prot.h> 628360efbdSAlfred Perlstein #include <rpc/pmap_clnt.h> 63d201fe46SDaniel Eischen #include "un-namespace.h" 64d201fe46SDaniel Eischen 6599064799SGarrett Wollman #define NAMELEN 255 6699064799SGarrett Wollman #define MAX_BROADCAST_SIZE 1400 6799064799SGarrett Wollman 6899064799SGarrett Wollman /* 6999064799SGarrett Wollman * Get a copy of the current port maps. 7099064799SGarrett Wollman * Calls the pmap service remotely to do get the maps. 7199064799SGarrett Wollman */ 7299064799SGarrett Wollman struct pmaplist * 7399064799SGarrett Wollman pmap_getmaps(address) 7499064799SGarrett Wollman struct sockaddr_in *address; 7599064799SGarrett Wollman { 768360efbdSAlfred Perlstein struct pmaplist *head = NULL; 778360efbdSAlfred Perlstein int sock = -1; 7899064799SGarrett Wollman struct timeval minutetimeout; 798360efbdSAlfred Perlstein CLIENT *client; 808360efbdSAlfred Perlstein 818360efbdSAlfred Perlstein assert(address != NULL); 8299064799SGarrett Wollman 8399064799SGarrett Wollman minutetimeout.tv_sec = 60; 8499064799SGarrett Wollman minutetimeout.tv_usec = 0; 8599064799SGarrett Wollman address->sin_port = htons(PMAPPORT); 8699064799SGarrett Wollman client = clnttcp_create(address, PMAPPROG, 878360efbdSAlfred Perlstein PMAPVERS, &sock, 50, 500); 888360efbdSAlfred Perlstein if (client != NULL) { 898360efbdSAlfred Perlstein if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_DUMP, 908360efbdSAlfred Perlstein (xdrproc_t)xdr_void, NULL, 918360efbdSAlfred Perlstein (xdrproc_t)xdr_pmaplist, &head, minutetimeout) != 928360efbdSAlfred Perlstein RPC_SUCCESS) { 9399064799SGarrett Wollman clnt_perror(client, "pmap_getmaps rpc problem"); 9499064799SGarrett Wollman } 9599064799SGarrett Wollman CLNT_DESTROY(client); 9699064799SGarrett Wollman } 9799064799SGarrett Wollman address->sin_port = 0; 9899064799SGarrett Wollman return (head); 9999064799SGarrett Wollman } 100