Back to index

glibc  2.9
pm_getmaps.c
Go to the documentation of this file.
00001 /* @(#)pmap_getmaps.c       2.2 88/08/01 4.0 RPCSRC */
00002 /*
00003  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00004  * unrestricted use provided that this legend is included on all tape
00005  * media and as a part of the software program in whole or part.  Users
00006  * may copy or modify Sun RPC without charge, but are not authorized
00007  * to license or distribute it to anyone else except as part of a product or
00008  * program developed by the user.
00009  *
00010  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00011  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00012  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00013  *
00014  * Sun RPC is provided with no support and without any obligation on the
00015  * part of Sun Microsystems, Inc. to assist in its use, correction,
00016  * modification or enhancement.
00017  *
00018  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00019  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00020  * OR ANY PART THEREOF.
00021  *
00022  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00023  * or profits or other special, indirect and consequential damages, even if
00024  * Sun has been advised of the possibility of such damages.
00025  *
00026  * Sun Microsystems, Inc.
00027  * 2550 Garcia Avenue
00028  * Mountain View, California  94043
00029  */
00030 #if !defined(lint) && defined(SCCSIDS)
00031 static char sccsid[] = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
00032 #endif
00033 
00034 /*
00035  * pmap_getmap.c
00036  * Client interface to pmap rpc service.
00037  * contains pmap_getmaps, which is only tcp service involved
00038  *
00039  * Copyright (C) 1984, Sun Microsystems, Inc.
00040  */
00041 
00042 #include <rpc/rpc.h>
00043 #include <rpc/pmap_prot.h>
00044 #include <rpc/pmap_clnt.h>
00045 #include <sys/socket.h>
00046 #include <netdb.h>
00047 #include <stdbool.h>
00048 #include <stdio.h>
00049 #include <errno.h>
00050 #include <libintl.h>
00051 #include <unistd.h>
00052 
00053 
00054 /*
00055  * Get a copy of the current port maps.
00056  * Calls the pmap service remotely to do get the maps.
00057  */
00058 struct pmaplist *
00059 pmap_getmaps (struct sockaddr_in *address)
00060 {
00061   struct pmaplist *head = (struct pmaplist *) NULL;
00062   struct timeval minutetimeout;
00063   CLIENT *client;
00064   bool closeit = false;
00065 
00066   minutetimeout.tv_sec = 60;
00067   minutetimeout.tv_usec = 0;
00068   address->sin_port = htons (PMAPPORT);
00069 
00070   /* Don't need a reserved port to get ports from the portmapper.  */
00071   int socket = __get_socket (address);
00072   if (socket != -1)
00073     closeit = true;
00074 
00075   client = INTUSE(clnttcp_create) (address, PMAPPROG,
00076                                PMAPVERS, &socket, 50, 500);
00077   if (client != (CLIENT *) NULL)
00078     {
00079       if (CLNT_CALL (client, PMAPPROC_DUMP, (xdrproc_t)INTUSE(xdr_void), NULL,
00080                    (xdrproc_t)INTUSE(xdr_pmaplist), (caddr_t)&head,
00081                    minutetimeout) != RPC_SUCCESS)
00082        {
00083          clnt_perror (client, _("pmap_getmaps.c: rpc problem"));
00084        }
00085       CLNT_DESTROY (client);
00086     }
00087   /* We only need to close the socket here if we opened  it.  */
00088   if (closeit)
00089     (void) __close (socket);
00090   address->sin_port = 0;
00091   return head;
00092 }