1 /* $NetBSD: pmap_rmt.c,v 1.34 2013/03/11 20:19:29 tron Exp $ */
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 #if defined(LIBC_SCCS) && !defined(lint)
37 static char *sccsid
= "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
38 static char *sccsid
= "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";
40 __RCSID("$NetBSD: pmap_rmt.c,v 1.34 2013/03/11 20:19:29 tron Exp $");
46 * Client interface to pmap rpc service.
47 * remote call and broadcast service
49 * Copyright (C) 1984, Sun Microsystems, Inc.
52 #include "namespace.h"
54 #include <sys/types.h>
55 #include <sys/ioctl.h>
57 #include <sys/socket.h>
60 #include <netinet/in.h>
61 #include <arpa/inet.h>
71 #include <rpc/pmap_prot.h>
72 #include <rpc/pmap_clnt.h>
73 #include <rpc/pmap_rmt.h>
76 __weak_alias(xdr_rmtcall_args
,_xdr_rmtcall_args
)
77 __weak_alias(xdr_rmtcallres
,_xdr_rmtcallres
)
80 static const struct timeval timeout
= { 3, 0 };
83 * pmapper remote-call-service interface.
84 * This routine is used to call the pmapper remote call service
85 * which will look up a service program in the port maps, and then
86 * remotely call that routine with the given parameters. This allows
87 * programs to do a lookup and call in one step.
90 pmap_rmtcall(struct sockaddr_in
*addr
, u_long prog
, u_long vers
, u_long proc
,
91 xdrproc_t xdrargs
, caddr_t argsp
, xdrproc_t xdrres
, caddr_t resp
,
92 struct timeval tout
, u_long
*port_ptr
)
100 _DIAGASSERT(addr
!= NULL
);
101 _DIAGASSERT(port_ptr
!= NULL
);
103 addr
->sin_port
= htons(PMAPPORT
);
104 client
= clntudp_create(addr
, PMAPPROG
, PMAPVERS
, timeout
, &sock
);
105 if (client
!= NULL
) {
110 a
.xdr_args
= xdrargs
;
111 r
.port_ptr
= port_ptr
;
112 r
.results_ptr
= resp
;
113 r
.xdr_results
= xdrres
;
114 stat
= CLNT_CALL(client
, (rpcproc_t
)PMAPPROC_CALLIT
,
115 (xdrproc_t
)xdr_rmtcall_args
, &a
, (xdrproc_t
)xdr_rmtcallres
,
117 CLNT_DESTROY(client
);
127 * XDR remote call arguments
128 * written for XDR_ENCODE direction only
131 xdr_rmtcall_args(XDR
*xdrs
, struct rmtcallargs
*cap
)
133 u_int lenposition
, argposition
, position
;
135 _DIAGASSERT(xdrs
!= NULL
);
136 _DIAGASSERT(cap
!= NULL
);
138 if (xdr_u_long(xdrs
, &(cap
->prog
)) &&
139 xdr_u_long(xdrs
, &(cap
->vers
)) &&
140 xdr_u_long(xdrs
, &(cap
->proc
))) {
141 lenposition
= XDR_GETPOS(xdrs
);
142 if (! xdr_u_long(xdrs
, &(cap
->arglen
)))
144 argposition
= XDR_GETPOS(xdrs
);
145 if (! (*(cap
->xdr_args
))(xdrs
, cap
->args_ptr
))
147 position
= XDR_GETPOS(xdrs
);
148 cap
->arglen
= (u_long
)position
- (u_long
)argposition
;
149 XDR_SETPOS(xdrs
, lenposition
);
150 if (! xdr_u_long(xdrs
, &(cap
->arglen
)))
152 XDR_SETPOS(xdrs
, position
);
159 * XDR remote call results
160 * written for XDR_DECODE direction only
163 xdr_rmtcallres(XDR
*xdrs
, struct rmtcallres
*crp
)
167 _DIAGASSERT(xdrs
!= NULL
);
168 _DIAGASSERT(crp
!= NULL
);
170 port_ptr
= (caddr_t
)(void *)crp
->port_ptr
;
171 if (xdr_reference(xdrs
, &port_ptr
, (u_int
)sizeof(u_long
),
172 (xdrproc_t
)xdr_u_long
) && xdr_u_long(xdrs
, &crp
->resultslen
)) {
173 crp
->port_ptr
= (u_long
*)(void *)port_ptr
;
174 return ((*(crp
->xdr_results
))(xdrs
, crp
->results_ptr
));