]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/clnt_udp.c
sunrpc: Always obtain AF_INET addresses from NSS [BZ #20964]
[thirdparty/glibc.git] / sunrpc / clnt_udp.c
CommitLineData
28f540f4 1/*
a7ab6ec8 2 * clnt_udp.c, Implements a UDP/IP based, client side RPC.
c4029823 3 *
a7ab6ec8 4 * Copyright (c) 2010, Oracle America, Inc.
c4029823 5 *
a7ab6ec8
UD
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
cb636bb2 9 *
a7ab6ec8
UD
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.
28f540f4 19 *
a7ab6ec8
UD
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.
28f540f4
RM
32 */
33
34#include <stdio.h>
e7fd8a39 35#include <unistd.h>
4360eafd 36#include <libintl.h>
28f540f4 37#include <rpc/rpc.h>
e7fd8a39
UD
38#include <rpc/xdr.h>
39#include <rpc/clnt.h>
099a6fbd 40#include <sys/poll.h>
28f540f4
RM
41#include <sys/socket.h>
42#include <sys/ioctl.h>
43#include <netdb.h>
44#include <errno.h>
e054f494 45#include <stdint.h>
28f540f4 46#include <rpc/pmap_clnt.h>
ea48e2c4 47#include <net/if.h>
412c954a 48#include <ifaddrs.h>
3ce1f295 49#include <wchar.h>
8ccf22f9 50#include <fcntl.h>
28f540f4 51
b1eab230
UD
52#ifdef IP_RECVERR
53#include <errqueue.h>
54#include <sys/uio.h>
55#endif
56
8ccf22f9
UD
57#include <kernel-features.h>
58
090ca000 59extern u_long _create_xid (void);
28f540f4
RM
60
61/*
62 * UDP bases client side rpc operations
63 */
e7fd8a39
UD
64static enum clnt_stat clntudp_call (CLIENT *, u_long, xdrproc_t, caddr_t,
65 xdrproc_t, caddr_t, struct timeval);
66static void clntudp_abort (void);
67static void clntudp_geterr (CLIENT *, struct rpc_err *);
68static bool_t clntudp_freeres (CLIENT *, xdrproc_t, caddr_t);
69static bool_t clntudp_control (CLIENT *, int, char *);
70static void clntudp_destroy (CLIENT *);
28f540f4 71
31d7b14c 72static const struct clnt_ops udp_ops =
e7fd8a39
UD
73{
74 clntudp_call,
75 clntudp_abort,
76 clntudp_geterr,
77 clntudp_freeres,
78 clntudp_destroy,
79 clntudp_control
28f540f4
RM
80};
81
c4029823 82/*
28f540f4
RM
83 * Private data kept per client handle
84 */
e7fd8a39
UD
85struct cu_data
86 {
87 int cu_sock;
88 bool_t cu_closeit;
89 struct sockaddr_in cu_raddr;
90 int cu_rlen;
91 struct timeval cu_wait;
92 struct timeval cu_total;
93 struct rpc_err cu_error;
94 XDR cu_outxdrs;
95 u_int cu_xdrpos;
96 u_int cu_sendsz;
97 char *cu_outbuf;
98 u_int cu_recvsz;
99 char cu_inbuf[1];
100 };
28f540f4
RM
101
102/*
103 * Create a UDP based client handle.
104 * If *sockp<0, *sockp is set to a newly created UPD socket.
105 * If raddr->sin_port is 0 a binder on the remote machine
106 * is consulted for the correct port number.
107 * NB: It is the clients responsibility to close *sockp.
108 * NB: The rpch->cl_auth is initialized to null authentication.
109 * Caller may wish to set this something more useful.
110 *
111 * wait is the amount of time used between retransmitting a call if
6d52618b 112 * no response has been heard; retransmission occurs until the actual
28f540f4
RM
113 * rpc call times out.
114 *
115 * sendsz and recvsz are the maximum allowable packet sizes that can be
116 * sent and received.
117 */
118CLIENT *
8ccf22f9
UD
119__libc_clntudp_bufcreate (struct sockaddr_in *raddr, u_long program,
120 u_long version, struct timeval wait, int *sockp,
121 u_int sendsz, u_int recvsz, int flags)
28f540f4 122{
e7fd8a39
UD
123 CLIENT *cl;
124 struct cu_data *cu = NULL;
e7fd8a39 125 struct rpc_msg call_msg;
28f540f4 126
e7fd8a39 127 cl = (CLIENT *) mem_alloc (sizeof (CLIENT));
e7fd8a39
UD
128 sendsz = ((sendsz + 3) / 4) * 4;
129 recvsz = ((recvsz + 3) / 4) * 4;
130 cu = (struct cu_data *) mem_alloc (sizeof (*cu) + sendsz + recvsz);
51028f34 131 if (cl == NULL || cu == NULL)
e7fd8a39 132 {
543cf8a9 133 struct rpc_createerr *ce = &get_rpc_createerr ();
1d20f7f8
UD
134 (void) __fxprintf (NULL, "%s: %s",
135 "clntudp_create", _("out of memory\n"));
543cf8a9 136 ce->cf_stat = RPC_SYSTEMERROR;
51028f34 137 ce->cf_error.re_errno = ENOMEM;
e7fd8a39
UD
138 goto fooy;
139 }
140 cu->cu_outbuf = &cu->cu_inbuf[recvsz];
28f540f4 141
e7fd8a39
UD
142 if (raddr->sin_port == 0)
143 {
144 u_short port;
145 if ((port =
146 pmap_getport (raddr, program, version, IPPROTO_UDP)) == 0)
147 {
148 goto fooy;
28f540f4 149 }
e7fd8a39
UD
150 raddr->sin_port = htons (port);
151 }
31d7b14c 152 cl->cl_ops = (struct clnt_ops *) &udp_ops;
e7fd8a39
UD
153 cl->cl_private = (caddr_t) cu;
154 cu->cu_raddr = *raddr;
155 cu->cu_rlen = sizeof (cu->cu_raddr);
156 cu->cu_wait = wait;
157 cu->cu_total.tv_sec = -1;
158 cu->cu_total.tv_usec = -1;
159 cu->cu_sendsz = sendsz;
160 cu->cu_recvsz = recvsz;
090ca000 161 call_msg.rm_xid = _create_xid ();
e7fd8a39
UD
162 call_msg.rm_direction = CALL;
163 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
164 call_msg.rm_call.cb_prog = program;
165 call_msg.rm_call.cb_vers = version;
7b57bfe5
UD
166 xdrmem_create (&(cu->cu_outxdrs), cu->cu_outbuf, sendsz, XDR_ENCODE);
167 if (!xdr_callhdr (&(cu->cu_outxdrs), &call_msg))
e7fd8a39
UD
168 {
169 goto fooy;
170 }
171 cu->cu_xdrpos = XDR_GETPOS (&(cu->cu_outxdrs));
172 if (*sockp < 0)
173 {
52fb79d6 174 *sockp = __socket (AF_INET, SOCK_DGRAM|SOCK_NONBLOCK|flags, IPPROTO_UDP);
a1ffb40e 175 if (__glibc_unlikely (*sockp < 0))
e7fd8a39 176 {
543cf8a9
UD
177 struct rpc_createerr *ce = &get_rpc_createerr ();
178 ce->cf_stat = RPC_SYSTEMERROR;
179 ce->cf_error.re_errno = errno;
e7fd8a39 180 goto fooy;
28f540f4 181 }
e7fd8a39 182 /* attempt to bind to prov port */
a585ba22 183 (void) bindresvport (*sockp, (struct sockaddr_in *) 0);
b1eab230
UD
184#ifdef IP_RECVERR
185 {
186 int on = 1;
b2bffca2 187 __setsockopt (*sockp, SOL_IP, IP_RECVERR, &on, sizeof(on));
b1eab230
UD
188 }
189#endif
e7fd8a39
UD
190 cu->cu_closeit = TRUE;
191 }
192 else
193 {
194 cu->cu_closeit = FALSE;
195 }
196 cu->cu_sock = *sockp;
7b57bfe5 197 cl->cl_auth = authnone_create ();
e7fd8a39 198 return cl;
28f540f4 199fooy:
e7fd8a39
UD
200 if (cu)
201 mem_free ((caddr_t) cu, sizeof (*cu) + sendsz + recvsz);
202 if (cl)
203 mem_free ((caddr_t) cl, sizeof (CLIENT));
204 return (CLIENT *) NULL;
28f540f4 205}
7b57bfe5
UD
206#ifdef EXPORT_RPC_SYMBOLS
207libc_hidden_def (__libc_clntudp_bufcreate)
208#else
021db4be 209libc_hidden_nolink_sunrpc (__libc_clntudp_bufcreate, GLIBC_PRIVATE)
7b57bfe5 210#endif
8ccf22f9
UD
211
212CLIENT *
213clntudp_bufcreate (struct sockaddr_in *raddr, u_long program, u_long version,
214 struct timeval wait, int *sockp, u_int sendsz,
215 u_int recvsz)
216{
7b57bfe5
UD
217 return __libc_clntudp_bufcreate (raddr, program, version, wait,
218 sockp, sendsz, recvsz, 0);
8ccf22f9 219}
021db4be 220libc_hidden_nolink_sunrpc (clntudp_bufcreate, GLIBC_2_0)
28f540f4
RM
221
222CLIENT *
f63f2bfd
JM
223clntudp_create (struct sockaddr_in *raddr, u_long program, u_long version,
224 struct timeval wait, int *sockp)
28f540f4 225{
7b57bfe5
UD
226 return __libc_clntudp_bufcreate (raddr, program, version, wait,
227 sockp, UDPMSGSIZE, UDPMSGSIZE, 0);
28f540f4 228}
7b57bfe5
UD
229#ifdef EXPORT_RPC_SYMBOLS
230libc_hidden_def (clntudp_create)
231#else
021db4be 232libc_hidden_nolink_sunrpc (clntudp_create, GLIBC_2_0)
7b57bfe5 233#endif
28f540f4 234
ea48e2c4
UD
235static int
236is_network_up (int sock)
237{
412c954a 238 struct ifaddrs *ifa;
ea48e2c4 239
412c954a
UD
240 if (getifaddrs (&ifa) != 0)
241 return 0;
242
243 struct ifaddrs *run = ifa;
244 while (run != NULL)
ea48e2c4 245 {
412c954a 246 if ((run->ifa_flags & IFF_UP) != 0
f7e7a396 247 && run->ifa_addr != NULL
412c954a
UD
248 && run->ifa_addr->sa_family == AF_INET)
249 break;
ea48e2c4 250
412c954a 251 run = run->ifa_next;
ea48e2c4 252 }
412c954a
UD
253
254 freeifaddrs (ifa);
255
256 return run != NULL;
ea48e2c4
UD
257}
258
c4029823 259static enum clnt_stat
85231522
JM
260clntudp_call (/* client handle */
261 CLIENT *cl,
262 /* procedure number */
263 u_long proc,
264 /* xdr routine for args */
265 xdrproc_t xargs,
266 /* pointer to args */
267 caddr_t argsp,
268 /* xdr routine for results */
269 xdrproc_t xresults,
270 /* pointer to results */
271 caddr_t resultsp,
272 /* seconds to wait before giving up */
273 struct timeval utimeout)
28f540f4 274{
e7fd8a39
UD
275 struct cu_data *cu = (struct cu_data *) cl->cl_private;
276 XDR *xdrs;
1522c368 277 int outlen = 0;
e7fd8a39 278 int inlen;
41df5ed4 279 socklen_t fromlen;
099a6fbd
UD
280 struct pollfd fd;
281 int milliseconds = (cu->cu_wait.tv_sec * 1000) +
282 (cu->cu_wait.tv_usec / 1000);
e7fd8a39
UD
283 struct sockaddr_in from;
284 struct rpc_msg reply_msg;
285 XDR reply_xdrs;
286 struct timeval time_waited;
287 bool_t ok;
288 int nrefreshes = 2; /* number of times to refresh cred */
289 struct timeval timeout;
ea48e2c4 290 int anyup; /* any network interface up */
28f540f4 291
e7fd8a39
UD
292 if (cu->cu_total.tv_usec == -1)
293 {
294 timeout = utimeout; /* use supplied timeout */
295 }
296 else
297 {
298 timeout = cu->cu_total; /* use default timeout */
299 }
28f540f4 300
e7fd8a39
UD
301 time_waited.tv_sec = 0;
302 time_waited.tv_usec = 0;
28f540f4 303call_again:
e7fd8a39 304 xdrs = &(cu->cu_outxdrs);
60c96635
UD
305 if (xargs == NULL)
306 goto get_reply;
e7fd8a39
UD
307 xdrs->x_op = XDR_ENCODE;
308 XDR_SETPOS (xdrs, cu->cu_xdrpos);
309 /*
310 * the transaction is the first thing in the out buffer
311 */
d6f6ffa1 312 (*(uint32_t *) (cu->cu_outbuf))++;
e7fd8a39
UD
313 if ((!XDR_PUTLONG (xdrs, (long *) &proc)) ||
314 (!AUTH_MARSHALL (cl->cl_auth, xdrs)) ||
315 (!(*xargs) (xdrs, argsp)))
316 return (cu->cu_error.re_status = RPC_CANTENCODEARGS);
317 outlen = (int) XDR_GETPOS (xdrs);
28f540f4
RM
318
319send_again:
b2bffca2
UD
320 if (__sendto (cu->cu_sock, cu->cu_outbuf, outlen, 0,
321 (struct sockaddr *) &(cu->cu_raddr), cu->cu_rlen)
e7fd8a39
UD
322 != outlen)
323 {
324 cu->cu_error.re_errno = errno;
325 return (cu->cu_error.re_status = RPC_CANTSEND);
326 }
28f540f4 327
e7fd8a39
UD
328 /*
329 * Hack to provide rpc-based message passing
330 */
331 if (timeout.tv_sec == 0 && timeout.tv_usec == 0)
332 {
333 return (cu->cu_error.re_status = RPC_TIMEDOUT);
334 }
60c96635 335 get_reply:
e7fd8a39
UD
336 /*
337 * sub-optimal code appears here because we have
338 * some clock time to spare while the packets are in flight.
339 * (We assume that this is actually only executed once.)
340 */
341 reply_msg.acpted_rply.ar_verf = _null_auth;
342 reply_msg.acpted_rply.ar_results.where = resultsp;
343 reply_msg.acpted_rply.ar_results.proc = xresults;
099a6fbd
UD
344 fd.fd = cu->cu_sock;
345 fd.events = POLLIN;
c556351f 346 anyup = 0;
e7fd8a39
UD
347 for (;;)
348 {
ea48e2c4 349 switch (__poll (&fd, 1, milliseconds))
e7fd8a39 350 {
28f540f4 351
e7fd8a39 352 case 0:
ea48e2c4
UD
353 if (anyup == 0)
354 {
355 anyup = is_network_up (cu->cu_sock);
356 if (!anyup)
357 return (cu->cu_error.re_status = RPC_CANTRECV);
358 }
359
e7fd8a39
UD
360 time_waited.tv_sec += cu->cu_wait.tv_sec;
361 time_waited.tv_usec += cu->cu_wait.tv_usec;
362 while (time_waited.tv_usec >= 1000000)
363 {
364 time_waited.tv_sec++;
365 time_waited.tv_usec -= 1000000;
366 }
367 if ((time_waited.tv_sec < timeout.tv_sec) ||
368 ((time_waited.tv_sec == timeout.tv_sec) &&
369 (time_waited.tv_usec < timeout.tv_usec)))
370 goto send_again;
371 return (cu->cu_error.re_status = RPC_TIMEDOUT);
28f540f4 372
e7fd8a39
UD
373 /*
374 * buggy in other cases because time_waited is not being
375 * updated.
376 */
377 case -1:
378 if (errno == EINTR)
379 continue;
380 cu->cu_error.re_errno = errno;
381 return (cu->cu_error.re_status = RPC_CANTRECV);
28f540f4 382 }
b1eab230
UD
383#ifdef IP_RECVERR
384 if (fd.revents & POLLERR)
385 {
386 struct msghdr msg;
387 struct cmsghdr *cmsg;
388 struct sock_extended_err *e;
389 struct sockaddr_in err_addr;
390 struct iovec iov;
bc779a1a 391 char *cbuf = malloc (outlen + 256);
b1eab230
UD
392 int ret;
393
bc779a1a
FW
394 if (cbuf == NULL)
395 {
396 cu->cu_error.re_errno = errno;
397 return (cu->cu_error.re_status = RPC_CANTRECV);
398 }
399
b1eab230
UD
400 iov.iov_base = cbuf + 256;
401 iov.iov_len = outlen;
402 msg.msg_name = (void *) &err_addr;
403 msg.msg_namelen = sizeof (err_addr);
404 msg.msg_iov = &iov;
405 msg.msg_iovlen = 1;
406 msg.msg_flags = 0;
407 msg.msg_control = cbuf;
408 msg.msg_controllen = 256;
b2bffca2 409 ret = __recvmsg (cu->cu_sock, &msg, MSG_ERRQUEUE);
b1eab230
UD
410 if (ret >= 0
411 && memcmp (cbuf + 256, cu->cu_outbuf, ret) == 0
412 && (msg.msg_flags & MSG_ERRQUEUE)
413 && ((msg.msg_namelen == 0
414 && ret >= 12)
415 || (msg.msg_namelen == sizeof (err_addr)
416 && err_addr.sin_family == AF_INET
417 && memcmp (&err_addr.sin_addr, &cu->cu_raddr.sin_addr,
418 sizeof (err_addr.sin_addr)) == 0
419 && err_addr.sin_port == cu->cu_raddr.sin_port)))
420 for (cmsg = CMSG_FIRSTHDR (&msg); cmsg;
421 cmsg = CMSG_NXTHDR (&msg, cmsg))
422 if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR)
423 {
bc779a1a 424 free (cbuf);
b1eab230
UD
425 e = (struct sock_extended_err *) CMSG_DATA(cmsg);
426 cu->cu_error.re_errno = e->ee_errno;
427 return (cu->cu_error.re_status = RPC_CANTRECV);
428 }
bc779a1a 429 free (cbuf);
b1eab230
UD
430 }
431#endif
e7fd8a39
UD
432 do
433 {
434 fromlen = sizeof (struct sockaddr);
b2bffca2 435 inlen = __recvfrom (cu->cu_sock, cu->cu_inbuf,
7e9f348f 436 (int) cu->cu_recvsz, MSG_DONTWAIT,
b2bffca2 437 (struct sockaddr *) &from, &fromlen);
e7fd8a39
UD
438 }
439 while (inlen < 0 && errno == EINTR);
440 if (inlen < 0)
441 {
442 if (errno == EWOULDBLOCK)
443 continue;
444 cu->cu_error.re_errno = errno;
445 return (cu->cu_error.re_status = RPC_CANTRECV);
28f540f4 446 }
e7fd8a39
UD
447 if (inlen < 4)
448 continue;
4c66860c
UD
449
450 /* see if reply transaction id matches sent id.
7b57bfe5 451 Don't do this if we only wait for a replay */
4c66860c 452 if (xargs != NULL
4efbd5cb 453 && memcmp (cu->cu_inbuf, cu->cu_outbuf, sizeof (u_int32_t)) != 0)
e7fd8a39
UD
454 continue;
455 /* we now assume we have the proper reply */
456 break;
457 }
458
459 /*
460 * now decode and validate the response
461 */
7b57bfe5
UD
462 xdrmem_create (&reply_xdrs, cu->cu_inbuf, (u_int) inlen, XDR_DECODE);
463 ok = xdr_replymsg (&reply_xdrs, &reply_msg);
e7fd8a39
UD
464 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
465 if (ok)
466 {
467 _seterr_reply (&reply_msg, &(cu->cu_error));
468 if (cu->cu_error.re_status == RPC_SUCCESS)
469 {
470 if (!AUTH_VALIDATE (cl->cl_auth,
471 &reply_msg.acpted_rply.ar_verf))
472 {
473 cu->cu_error.re_status = RPC_AUTHERROR;
474 cu->cu_error.re_why = AUTH_INVALIDRESP;
475 }
476 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL)
477 {
478 xdrs->x_op = XDR_FREE;
7b57bfe5 479 (void) xdr_opaque_auth (xdrs, &(reply_msg.acpted_rply.ar_verf));
e7fd8a39
UD
480 }
481 } /* end successful completion */
482 else
483 {
484 /* maybe our credentials need to be refreshed ... */
485 if (nrefreshes > 0 && AUTH_REFRESH (cl->cl_auth))
486 {
487 nrefreshes--;
488 goto call_again;
489 }
490 } /* end of unsuccessful completion */
491 } /* end of valid reply message */
492 else
493 {
494 cu->cu_error.re_status = RPC_CANTDECODERES;
495 }
496 return cu->cu_error.re_status;
28f540f4
RM
497}
498
499static void
e7fd8a39 500clntudp_geterr (CLIENT *cl, struct rpc_err *errp)
28f540f4 501{
e7fd8a39 502 struct cu_data *cu = (struct cu_data *) cl->cl_private;
28f540f4 503
e7fd8a39 504 *errp = cu->cu_error;
28f540f4
RM
505}
506
507
508static bool_t
e7fd8a39 509clntudp_freeres (CLIENT *cl, xdrproc_t xdr_res, caddr_t res_ptr)
28f540f4 510{
e7fd8a39
UD
511 struct cu_data *cu = (struct cu_data *) cl->cl_private;
512 XDR *xdrs = &(cu->cu_outxdrs);
28f540f4 513
e7fd8a39
UD
514 xdrs->x_op = XDR_FREE;
515 return (*xdr_res) (xdrs, res_ptr);
28f540f4
RM
516}
517
c4029823 518static void
e7fd8a39 519clntudp_abort (void)
28f540f4
RM
520{
521}
522
523static bool_t
e7fd8a39 524clntudp_control (CLIENT *cl, int request, char *info)
28f540f4 525{
e7fd8a39 526 struct cu_data *cu = (struct cu_data *) cl->cl_private;
fb1ae1ee
JM
527 u_long ul;
528 u_int32_t ui32;
28f540f4 529
e7fd8a39
UD
530 switch (request)
531 {
26a60f90
UD
532 case CLSET_FD_CLOSE:
533 cu->cu_closeit = TRUE;
534 break;
535 case CLSET_FD_NCLOSE:
536 cu->cu_closeit = FALSE;
537 break;
e7fd8a39
UD
538 case CLSET_TIMEOUT:
539 cu->cu_total = *(struct timeval *) info;
540 break;
541 case CLGET_TIMEOUT:
542 *(struct timeval *) info = cu->cu_total;
543 break;
544 case CLSET_RETRY_TIMEOUT:
545 cu->cu_wait = *(struct timeval *) info;
546 break;
547 case CLGET_RETRY_TIMEOUT:
548 *(struct timeval *) info = cu->cu_wait;
549 break;
550 case CLGET_SERVER_ADDR:
551 *(struct sockaddr_in *) info = cu->cu_raddr;
552 break;
26a60f90
UD
553 case CLGET_FD:
554 *(int *)info = cu->cu_sock;
555 break;
556 case CLGET_XID:
557 /*
558 * use the knowledge that xid is the
559 * first element in the call structure *.
560 * This will get the xid of the PREVIOUS call
561 */
fb1ae1ee
JM
562 memcpy (&ui32, cu->cu_outbuf, sizeof (ui32));
563 ul = ntohl (ui32);
564 memcpy (info, &ul, sizeof (ul));
26a60f90
UD
565 break;
566 case CLSET_XID:
567 /* This will set the xid of the NEXT call */
fb1ae1ee
JM
568 memcpy (&ul, info, sizeof (ul));
569 ui32 = htonl (ul - 1);
570 memcpy (cu->cu_outbuf, &ui32, sizeof (ui32));
26a60f90 571 /* decrement by 1 as clntudp_call() increments once */
f0ccf6ea 572 break;
26a60f90
UD
573 case CLGET_VERS:
574 /*
575 * This RELIES on the information that, in the call body,
576 * the version number field is the fifth field from the
6f65e668 577 * beginning of the RPC header. MUST be changed if the
26a60f90
UD
578 * call_struct is changed
579 */
fb1ae1ee
JM
580 memcpy (&ui32, cu->cu_outbuf + 4 * BYTES_PER_XDR_UNIT, sizeof (ui32));
581 ul = ntohl (ui32);
582 memcpy (info, &ul, sizeof (ul));
26a60f90
UD
583 break;
584 case CLSET_VERS:
fb1ae1ee
JM
585 memcpy (&ul, info, sizeof (ul));
586 ui32 = htonl (ul);
587 memcpy (cu->cu_outbuf + 4 * BYTES_PER_XDR_UNIT, &ui32, sizeof (ui32));
26a60f90
UD
588 break;
589 case CLGET_PROG:
590 /*
591 * This RELIES on the information that, in the call body,
592 * the program number field is the field from the
6f65e668 593 * beginning of the RPC header. MUST be changed if the
26a60f90
UD
594 * call_struct is changed
595 */
fb1ae1ee
JM
596 memcpy (&ui32, cu->cu_outbuf + 3 * BYTES_PER_XDR_UNIT, sizeof (ui32));
597 ul = ntohl (ui32);
598 memcpy (info, &ul, sizeof (ul));
26a60f90
UD
599 break;
600 case CLSET_PROG:
fb1ae1ee
JM
601 memcpy (&ul, info, sizeof (ul));
602 ui32 = htonl (ul);
603 memcpy (cu->cu_outbuf + 3 * BYTES_PER_XDR_UNIT, &ui32, sizeof (ui32));
26a60f90
UD
604 break;
605 /* The following are only possible with TI-RPC */
606 case CLGET_SVC_ADDR:
607 case CLSET_SVC_ADDR:
608 case CLSET_PUSH_TIMOD:
609 case CLSET_POP_TIMOD:
e7fd8a39
UD
610 default:
611 return FALSE;
612 }
613 return TRUE;
28f540f4 614}
c4029823 615
28f540f4 616static void
e7fd8a39 617clntudp_destroy (CLIENT *cl)
28f540f4 618{
e7fd8a39 619 struct cu_data *cu = (struct cu_data *) cl->cl_private;
28f540f4 620
e7fd8a39
UD
621 if (cu->cu_closeit)
622 {
50304ef0 623 (void) __close (cu->cu_sock);
e7fd8a39
UD
624 }
625 XDR_DESTROY (&(cu->cu_outxdrs));
626 mem_free ((caddr_t) cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
627 mem_free ((caddr_t) cl, sizeof (CLIENT));
28f540f4 628}