1 /* $NetBSD: pmap_rmt.c,v 1.30 2010/03/23 20:28:59 drochner Exp $ */
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.
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.
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.
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.
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.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
35 static char *sccsid
= "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
36 static char *sccsid
= "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";
38 __RCSID("$NetBSD: pmap_rmt.c,v 1.30 2010/03/23 20:28:59 drochner Exp $");
44 * Client interface to pmap rpc service.
45 * remote call and broadcast service
47 * Copyright (C) 1984, Sun Microsystems, Inc.
50 #include "namespace.h"
52 #include <sys/types.h>
53 #include <sys/ioctl.h>
55 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <arpa/inet.h>
69 #include <rpc/pmap_prot.h>
70 #include <rpc/pmap_clnt.h>
71 #include <rpc/pmap_rmt.h>
74 __weak_alias(xdr_rmtcall_args
,_xdr_rmtcall_args
)
75 __weak_alias(xdr_rmtcallres
,_xdr_rmtcallres
)
78 static const struct timeval timeout
= { 3, 0 };
81 * pmapper remote-call-service interface.
82 * This routine is used to call the pmapper remote call service
83 * which will look up a service program in the port maps, and then
84 * remotely call that routine with the given parameters. This allows
85 * programs to do a lookup and call in one step.
88 pmap_rmtcall(addr
, prog
, vers
, proc
, xdrargs
, argsp
, xdrres
, resp
, tout
,
90 struct sockaddr_in
*addr
;
91 u_long prog
, vers
, proc
;
92 xdrproc_t xdrargs
, xdrres
;
103 _DIAGASSERT(addr
!= NULL
);
104 _DIAGASSERT(port_ptr
!= NULL
);
106 addr
->sin_port
= htons(PMAPPORT
);
107 client
= clntudp_create(addr
, PMAPPROG
, PMAPVERS
, timeout
, &sock
);
108 if (client
!= NULL
) {
113 a
.xdr_args
= xdrargs
;
114 r
.port_ptr
= port_ptr
;
115 r
.results_ptr
= resp
;
116 r
.xdr_results
= xdrres
;
117 stat
= CLNT_CALL(client
, (rpcproc_t
)PMAPPROC_CALLIT
,
118 (xdrproc_t
)xdr_rmtcall_args
, &a
, (xdrproc_t
)xdr_rmtcallres
,
120 CLNT_DESTROY(client
);
130 * XDR remote call arguments
131 * written for XDR_ENCODE direction only
134 xdr_rmtcall_args(xdrs
, cap
)
136 struct rmtcallargs
*cap
;
138 u_int lenposition
, argposition
, position
;
140 _DIAGASSERT(xdrs
!= NULL
);
141 _DIAGASSERT(cap
!= NULL
);
143 if (xdr_u_long(xdrs
, &(cap
->prog
)) &&
144 xdr_u_long(xdrs
, &(cap
->vers
)) &&
145 xdr_u_long(xdrs
, &(cap
->proc
))) {
146 lenposition
= XDR_GETPOS(xdrs
);
147 if (! xdr_u_long(xdrs
, &(cap
->arglen
)))
149 argposition
= XDR_GETPOS(xdrs
);
150 if (! (*(cap
->xdr_args
))(xdrs
, cap
->args_ptr
))
152 position
= XDR_GETPOS(xdrs
);
153 cap
->arglen
= (u_long
)position
- (u_long
)argposition
;
154 XDR_SETPOS(xdrs
, lenposition
);
155 if (! xdr_u_long(xdrs
, &(cap
->arglen
)))
157 XDR_SETPOS(xdrs
, position
);
164 * XDR remote call results
165 * written for XDR_DECODE direction only
168 xdr_rmtcallres(xdrs
, crp
)
170 struct rmtcallres
*crp
;
174 _DIAGASSERT(xdrs
!= NULL
);
175 _DIAGASSERT(crp
!= NULL
);
177 port_ptr
= (caddr_t
)(void *)crp
->port_ptr
;
178 if (xdr_reference(xdrs
, &port_ptr
, sizeof (u_long
),
179 (xdrproc_t
)xdr_u_long
) && xdr_u_long(xdrs
, &crp
->resultslen
)) {
180 crp
->port_ptr
= (u_long
*)(void *)port_ptr
;
181 return ((*(crp
->xdr_results
))(xdrs
, crp
->results_ptr
));