clnt_udp.c 18 KB

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