2 * Copyright (c) 2009, Sun Microsystems, Inc.
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.
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.
31 * Client interface to pmap rpc service.
32 * remote call and broadcast service
34 * Copyright (C) 1984, Sun Microsystems, Inc.
38 #include <sys/types.h>
39 //#include <sys/ioctl.h>
40 //#include <sys/poll.h>
41 //#include <sys/socket.h>
44 //#include <netinet/in.h>
45 //#include <arpa/inet.h>
55 #include <rpc/pmap_prot.h>
56 #include <rpc/pmap_clnt.h>
57 #include <rpc/pmap_rmt.h>
59 // For the clnttcp_create function
60 //#include <clnt_soc.h>
63 static const struct timeval timeout
= { 3, 0 };
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.
73 pmap_rmtcall(addr
, prog
, vers
, proc
, xdrargs
, argsp
, xdrres
, resp
, tout
,
75 struct sockaddr_in
*addr
;
76 u_long prog
, vers
, proc
;
77 xdrproc_t xdrargs
, xdrres
;
89 assert(port_ptr
!= NULL
);
91 addr
->sin_port
= htons(PMAPPORT
);
92 client
= clntudp_create(addr
, PMAPPROG
, PMAPVERS
, timeout
, &sock
);
99 r
.port_ptr
= port_ptr
;
100 r
.results_ptr
= resp
;
101 r
.xdr_results
= xdrres
;
102 stat
= CLNT_CALL(client
, (rpcproc_t
)PMAPPROC_CALLIT
,
103 (xdrproc_t
)xdr_rmtcall_args
, &a
, (xdrproc_t
)xdr_rmtcallres
,
105 CLNT_DESTROY(client
);
115 * XDR remote call arguments
116 * written for XDR_ENCODE direction only
119 xdr_rmtcall_args(xdrs
, cap
)
121 struct rmtcallargs
*cap
;
123 u_int lenposition
, argposition
, position
;
125 assert(xdrs
!= NULL
);
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
)))
134 argposition
= XDR_GETPOS(xdrs
);
135 if (! (*(cap
->xdr_args
))(xdrs
, cap
->args_ptr
))
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
)))
142 XDR_SETPOS(xdrs
, position
);
149 * XDR remote call results
150 * written for XDR_DECODE direction only
153 xdr_rmtcallres(xdrs
, crp
)
155 struct rmtcallres
*crp
;
159 assert(xdrs
!= NULL
);
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
));