source: rtems/cpukit/librpc/src/rpc/pmap_clnt.c @ e069f7fe

5
Last change on this file since e069f7fe was e069f7fe, checked in by Sebastian Huber <sebastian.huber@…>, on 09/10/18 at 04:27:10

rpc: Use configuration header file

Update #3375.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1#include "rtems-rpc-config.h"
2
3/*
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part.  Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
10 *
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 *
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
18 *
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
22 *
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
26 *
27 * Sun Microsystems, Inc.
28 * 2550 Garcia Avenue
29 * Mountain View, California  94043
30 */
31
32#if defined(LIBC_SCCS) && !defined(lint)
33/*static char *sccsid = "from: @(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";*/
34/*static char *sccsid = "from: @(#)pmap_clnt.c  2.2 88/08/01 4.0 RPCSRC";*/
35static char *rcsid = "$FreeBSD: src/lib/libc/rpc/pmap_clnt.c,v 1.11 2000/01/27 23:06:39 jasone Exp $";
36#endif
37
38/*
39 * pmap_clnt.c
40 * Client interface to pmap rpc service.
41 *
42 * Copyright (C) 1984, Sun Microsystems, Inc.
43 */
44
45#ifdef HAVE_CONFIG_H
46#include "config.h"
47#endif
48
49#include <sys/types.h>
50#include <sys/stat.h>
51#include <unistd.h>
52#include <rpc/rpc.h>
53#include <rpc/pmap_prot.h>
54#include <rpc/pmap_clnt.h>
55#include <netinet/in.h>
56
57static struct timeval timeout = { 5, 0 };
58static struct timeval tottimeout = { 60, 0 };
59
60#ifndef PORTMAPSOCK
61#define PORTMAPSOCK "/var/run/portmapsock"
62#endif
63
64/*
65 * Set a mapping between program,version and port.
66 * Calls the pmap service remotely to do the mapping.
67 */
68bool_t
69pmap_set(
70        u_long program,
71        u_long version,
72        int protocol,
73        int port)    /* was u_short but changed to match prototype */
74{
75        struct sockaddr_in myaddress;
76        int socket = -1;
77        CLIENT *client;
78        struct pmap parms;
79        bool_t rslt;
80        struct stat st;
81
82        /*
83         * Temporary hack for backwards compatibility. Eventually
84         * this test will go away and we'll use only the "unix" transport.
85         */
86        if (stat(PORTMAPSOCK, &st) == 0 && st.st_mode & S_IFSOCK)
87                client = clnt_create(PORTMAPSOCK, PMAPPROG, PMAPVERS, "unix");
88        else  {
89                if (get_myaddress(&myaddress) != 0)
90                        return (FALSE);
91                myaddress.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
92                client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
93                        timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
94        }
95
96        if (client == (CLIENT *)NULL)
97                return (FALSE);
98        parms.pm_prog = program;
99        parms.pm_vers = version;
100        parms.pm_prot = protocol;
101        parms.pm_port = port;
102        if (CLNT_CALL(client, PMAPPROC_SET, (xdrproc_t)xdr_pmap, &parms, (xdrproc_t)xdr_bool, &rslt,
103            tottimeout) != RPC_SUCCESS) {
104                clnt_perror(client, "Cannot register service");
105                return (FALSE);
106        }
107        CLNT_DESTROY(client);
108        if (socket != -1)
109                (void)_RPC_close(socket);
110        return (rslt);
111}
112
113/*
114 * Remove the mapping between program, version and port.
115 * Calls the pmap service remotely to do the un-mapping.
116 */
117bool_t
118pmap_unset(
119        u_long program,
120        u_long version)
121{
122        struct sockaddr_in myaddress;
123        int socket = -1;
124        register CLIENT *client;
125        struct pmap parms;
126        bool_t rslt;
127        struct stat st;
128
129        /*
130         * Temporary hack for backwards compatibility. Eventually
131         * this test will go away and we'll use only the "unix" transport.
132         */
133        if (stat(PORTMAPSOCK, &st) == 0 && st.st_mode & S_IFSOCK)
134                client = clnt_create(PORTMAPSOCK, PMAPPROG, PMAPVERS, "unix");
135        else {
136                if (get_myaddress(&myaddress) != 0)
137                        return (FALSE);
138                myaddress.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
139                client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
140                        timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
141        }
142        if (client == (CLIENT *)NULL)
143                return (FALSE);
144        parms.pm_prog = program;
145        parms.pm_vers = version;
146        parms.pm_port = parms.pm_prot = 0;
147        CLNT_CALL(client, PMAPPROC_UNSET, (xdrproc_t)xdr_pmap, &parms, (xdrproc_t)xdr_bool, &rslt,
148            tottimeout);
149        CLNT_DESTROY(client);
150        if (socket != -1)
151                (void)_RPC_close(socket);
152        return (rslt);
153}
Note: See TracBrowser for help on using the repository browser.