| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#include <sys/types.h> |
| 38 |
#include <sys/ioctl.h> |
| 39 |
#include <poll.h> |
| 40 |
#include <sys/socket.h> |
| 41 |
|
| 42 |
#include <net/if.h> |
| 43 |
#include <netinet/in.h> |
| 44 |
#include <arpa/inet.h> |
| 45 |
|
| 46 |
#include <assert.h> |
| 47 |
#include <err.h> |
| 48 |
#include <errno.h> |
| 49 |
#include <stdio.h> |
| 50 |
#include <string.h> |
| 51 |
#include <unistd.h> |
| 52 |
|
| 53 |
#include <rpc/rpc.h> |
| 54 |
#include <rpc/pmap_prot.h> |
| 55 |
#include <rpc/pmap_clnt.h> |
| 56 |
#include <rpc/pmap_rmt.h> |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
static const struct timeval timeout = { 3, 0 }; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
enum clnt_stat |
| 72 |
pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, |
| 73 |
port_ptr) |
| 74 |
struct sockaddr_in *addr; |
| 75 |
u_long prog, vers, proc; |
| 76 |
xdrproc_t xdrargs, xdrres; |
| 77 |
caddr_t argsp, resp; |
| 78 |
struct timeval tout; |
| 79 |
u_long *port_ptr; |
| 80 |
{ |
| 81 |
int sock = -1; |
| 82 |
CLIENT *client; |
| 83 |
struct rmtcallargs a; |
| 84 |
struct rmtcallres r; |
| 85 |
enum clnt_stat stat; |
| 86 |
|
| 87 |
assert(addr != NULL); |
| 88 |
assert(port_ptr != NULL); |
| 89 |
|
| 90 |
addr->sin_port = htons(PMAPPORT); |
| 91 |
client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock); |
| 92 |
if (client != NULL) { |
| 93 |
a.prog = prog; |
| 94 |
a.vers = vers; |
| 95 |
a.proc = proc; |
| 96 |
a.args_ptr = argsp; |
| 97 |
a.xdr_args = xdrargs; |
| 98 |
r.port_ptr = port_ptr; |
| 99 |
r.results_ptr = resp; |
| 100 |
r.xdr_results = xdrres; |
| 101 |
stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT, |
| 102 |
(xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres, |
| 103 |
&r, tout); |
| 104 |
CLNT_DESTROY(client); |
| 105 |
} else { |
| 106 |
stat = RPC_FAILED; |
| 107 |
} |
| 108 |
addr->sin_port = 0; |
| 109 |
return (stat); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
bool_t |
| 118 |
xdr_rmtcall_args(xdrs, cap) |
| 119 |
XDR *xdrs; |
| 120 |
struct rmtcallargs *cap; |
| 121 |
{ |
| 122 |
u_int lenposition, argposition, position; |
| 123 |
|
| 124 |
assert(xdrs != NULL); |
| 125 |
assert(cap != NULL); |
| 126 |
|
| 127 |
if (xdr_u_long(xdrs, &(cap->prog)) && |
| 128 |
xdr_u_long(xdrs, &(cap->vers)) && |
| 129 |
xdr_u_long(xdrs, &(cap->proc))) { |
| 130 |
lenposition = XDR_GETPOS(xdrs); |
| 131 |
if (! xdr_u_long(xdrs, &(cap->arglen))) |
| 132 |
return (FALSE); |
| 133 |
argposition = XDR_GETPOS(xdrs); |
| 134 |
if (! (*(cap->xdr_args))(xdrs, cap->args_ptr)) |
| 135 |
return (FALSE); |
| 136 |
position = XDR_GETPOS(xdrs); |
| 137 |
cap->arglen = (u_long)position - (u_long)argposition; |
| 138 |
XDR_SETPOS(xdrs, lenposition); |
| 139 |
if (! xdr_u_long(xdrs, &(cap->arglen))) |
| 140 |
return (FALSE); |
| 141 |
XDR_SETPOS(xdrs, position); |
| 142 |
return (TRUE); |
| 143 |
} |
| 144 |
return (FALSE); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
bool_t |
| 152 |
xdr_rmtcallres(xdrs, crp) |
| 153 |
XDR *xdrs; |
| 154 |
struct rmtcallres *crp; |
| 155 |
{ |
| 156 |
caddr_t port_ptr; |
| 157 |
|
| 158 |
assert(xdrs != NULL); |
| 159 |
assert(crp != NULL); |
| 160 |
|
| 161 |
port_ptr = (caddr_t)(void *)crp->port_ptr; |
| 162 |
if (xdr_reference(xdrs, &port_ptr, sizeof (u_long), |
| 163 |
(xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) { |
| 164 |
crp->port_ptr = (u_long *)(void *)port_ptr; |
| 165 |
return ((*(crp->xdr_results))(xdrs, crp->results_ptr)); |
| 166 |
} |
| 167 |
return (FALSE); |
| 168 |
} |