ReactOS  0.4.14-dev-323-g6fe6a88
pmap_rmt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, Sun Microsystems, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * - Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Sun Microsystems, Inc. nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * pmap_rmt.c
31  * Client interface to pmap rpc service.
32  * remote call and broadcast service
33  *
34  * Copyright (C) 1984, Sun Microsystems, Inc.
35  */
36 
37 #include <wintirpc.h>
38 #include <sys/types.h>
39 //#include <sys/ioctl.h>
40 //#include <sys/poll.h>
41 //#include <sys/socket.h>
42 
43 //#include <net/if.h>
44 //#include <netinet/in.h>
45 //#include <arpa/inet.h>
46 
47 #include <assert.h>
48 //#include <err.h>
49 #include <errno.h>
50 #include <stdio.h>
51 #include <string.h>
52 //#include <unistd.h>
53 
54 #include <rpc/rpc.h>
55 #include <rpc/pmap_prot.h>
56 #include <rpc/pmap_clnt.h>
57 #include <rpc/pmap_rmt.h>
58 
59 // For the clnttcp_create function
60 //#include <clnt_soc.h>
61 
62 
63 static const struct timeval timeout = { 3, 0 };
64 
65 /*
66  * pmapper remote-call-service interface.
67  * This routine is used to call the pmapper remote call service
68  * which will look up a service program in the port maps, and then
69  * remotely call that routine with the given parameters. This allows
70  * programs to do a lookup and call in one step.
71 */
72 enum clnt_stat
73 pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
74  port_ptr)
75  struct sockaddr_in *addr;
76  u_long prog, vers, proc;
77  xdrproc_t xdrargs, xdrres;
78  caddr_t argsp, resp;
79  struct timeval tout;
80  u_long *port_ptr;
81 {
82  int sock = -1;
83  CLIENT *client;
84  struct rmtcallargs a;
85  struct rmtcallres r;
86  enum clnt_stat stat;
87 
88  assert(addr != NULL);
89  assert(port_ptr != NULL);
90 
91  addr->sin_port = htons(PMAPPORT);
93  if (client != NULL) {
94  a.prog = prog;
95  a.vers = vers;
96  a.proc = proc;
97  a.args_ptr = argsp;
98  a.xdr_args = xdrargs;
99  r.port_ptr = port_ptr;
100  r.results_ptr = resp;
101  r.xdr_results = xdrres;
104  &r, tout);
106  } else {
107  stat = RPC_FAILED;
108  }
109  addr->sin_port = 0;
110  return (stat);
111 }
112 
113 
114 /*
115  * XDR remote call arguments
116  * written for XDR_ENCODE direction only
117  */
118 bool_t
120  XDR *xdrs;
121  struct rmtcallargs *cap;
122 {
123  u_int lenposition, argposition, position;
124 
125  assert(xdrs != NULL);
126  assert(cap != NULL);
127 
128  if (xdr_u_long(xdrs, &(cap->prog)) &&
129  xdr_u_long(xdrs, &(cap->vers)) &&
130  xdr_u_long(xdrs, &(cap->proc))) {
131  lenposition = XDR_GETPOS(xdrs);
132  if (! xdr_u_long(xdrs, &(cap->arglen)))
133  return (FALSE);
134  argposition = XDR_GETPOS(xdrs);
135  if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
136  return (FALSE);
137  position = XDR_GETPOS(xdrs);
138  cap->arglen = (u_long)position - (u_long)argposition;
139  XDR_SETPOS(xdrs, lenposition);
140  if (! xdr_u_long(xdrs, &(cap->arglen)))
141  return (FALSE);
142  XDR_SETPOS(xdrs, position);
143  return (TRUE);
144  }
145  return (FALSE);
146 }
147 
148 /*
149  * XDR remote call results
150  * written for XDR_DECODE direction only
151  */
152 bool_t
153 xdr_rmtcallres(xdrs, crp)
154  XDR *xdrs;
155  struct rmtcallres *crp;
156 {
158 
159  assert(xdrs != NULL);
160  assert(crp != NULL);
161 
162  port_ptr = (caddr_t)(void *)crp->port_ptr;
163  if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
164  (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
165  crp->port_ptr = (u_long *)(void *)port_ptr;
166  return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
167  }
168  return (FALSE);
169 }
u_int32_t rpcproc_t
Definition: types.h:106
#define PMAPPROG
Definition: pmap_prot.h:77
#define TRUE
Definition: types.h:120
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
unsigned long u_long
Definition: linux.h:269
bool_t xdr_reference(XDR *xdrs, caddr_t *pp, u_int size, xdrproc_t proc)
Definition: xdr_reference.c:62
int32_t bool_t
Definition: types.h:101
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
char * prog
Definition: isohybrid.c:47
__END_DECLS __BEGIN_DECLS CLIENT * clntudp_create(struct sockaddr_in *, u_long, u_long, struct timeval, int *)
#define PMAPPROC_CALLIT
Definition: pmap_prot.h:86
#define assert(x)
Definition: debug.h:53
Definition: dhcpd.h:245
static HANDLE proc()
Definition: pdb.c:32
u_long resultslen
Definition: pmap_rmt.h:54
char * caddr_t
Definition: rosdhcp.h:36
caddr_t results_ptr
Definition: pmap_rmt.h:55
Definition: xdr.h:103
bool_t xdr_rmtcallres(XDR *xdrs, struct rmtcallres *crp)
Definition: pmap_rmt.c:153
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
GLenum cap
Definition: glext.h:9639
#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)
Definition: clnt.h:199
smooth NULL
Definition: ftsmooth.c:416
#define PMAPVERS
Definition: pmap_prot.h:78
bool_t xdr_rmtcall_args(XDR *xdrs, struct rmtcallargs *cap)
Definition: pmap_rmt.c:119
#define PMAPPORT
Definition: pmap_prot.h:76
static FILE * client
Definition: client.c:41
GLenum const GLvoid * addr
Definition: glext.h:9621
Definition: stat.h:55
bool_t xdr_u_long(XDR *xdrs, u_long *ulp)
Definition: xdr.c:186
#define cap
Definition: glfuncs.h:226
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
u_long * port_ptr
Definition: pmap_rmt.h:53
#define CLNT_DESTROY(rh)
Definition: clnt.h:275
#define caddr_t
Definition: ftp.c:24
UINT32 u_int
Definition: types.h:82
xdrproc_t xdr_results
Definition: pmap_rmt.h:56
Definition: tcpcore.h:1455
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define htons(x)
Definition: module.h:213
enum clnt_stat pmap_rmtcall(struct sockaddr_in *addr, u_long prog, u_long vers, u_long proc, xdrproc_t xdrargs, caddr_t argsp, xdrproc_t xdrres, caddr_t resp, struct timeval tout, u_long *port_ptr)
Definition: pmap_rmt.c:73
clnt_stat
Definition: clnt_stat.h:21