clnt_udp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /* @(#)clnt_udp.c 2.2 88/08/01 4.0 RPCSRC */
  2. /*
  3. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4. * unrestricted use provided that this legend is included on all tape
  5. * media and as a part of the software program in whole or part. Users
  6. * may copy or modify Sun RPC without charge, but are not authorized
  7. * to license or distribute it to anyone else except as part of a product or
  8. * program developed by the user.
  9. *
  10. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13. *
  14. * Sun RPC is provided with no support and without any obligation on the
  15. * part of Sun Microsystems, Inc. to assist in its use, correction,
  16. * modification or enhancement.
  17. *
  18. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20. * OR ANY PART THEREOF.
  21. *
  22. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23. * or profits or other special, indirect and consequential damages, even if
  24. * Sun has been advised of the possibility of such damages.
  25. *
  26. * Sun Microsystems, Inc.
  27. * 2550 Garcia Avenue
  28. * Mountain View, California 94043
  29. */
  30. #if 0
  31. static char sccsid[] = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";
  32. #endif
  33. /*
  34. * clnt_udp.c, Implements a UDP/IP based, client side RPC.
  35. *
  36. * Copyright (C) 1984, Sun Microsystems, Inc.
  37. */
  38. /* CMSG_NXTHDR is using it */
  39. #define __cmsg_nxthdr __cmsg_nxthdr_internal
  40. #define authnone_create __authnone_create
  41. #define xdrmem_create __xdrmem_create
  42. #define xdr_callhdr __xdr_callhdr
  43. #define xdr_replymsg __xdr_replymsg
  44. #define xdr_opaque_auth __xdr_opaque_auth
  45. #define pmap_getport __pmap_getport
  46. #define _seterr_reply __seterr_reply
  47. #define setsockopt __setsockopt
  48. #define bindresvport __bindresvport
  49. #define recvfrom __recvfrom
  50. #define sendto __sendto
  51. #define recvmsg __recvmsg
  52. #define poll __poll
  53. #define fputs __fputs
  54. #define __FORCE_GLIBC
  55. #include <features.h>
  56. #include <stdio.h>
  57. #include <unistd.h>
  58. #include <rpc/rpc.h>
  59. #include <rpc/xdr.h>
  60. #include <rpc/clnt.h>
  61. #include <sys/poll.h>
  62. #include <sys/socket.h>
  63. #include <sys/ioctl.h>
  64. #include <netdb.h>
  65. #include <errno.h>
  66. #include <rpc/pmap_clnt.h>
  67. #include <net/if.h>
  68. #ifdef USE_IN_LIBIO
  69. # include <wchar.h>
  70. #endif
  71. #ifdef IP_RECVERR
  72. #include "errqueue.h"
  73. #include <sys/uio.h>
  74. #endif
  75. extern u_long _create_xid (void) attribute_hidden;
  76. #undef get_rpc_createerr
  77. extern struct rpc_createerr *__rpc_thread_createerr_internal (void)
  78. __attribute__ ((__const__)) attribute_hidden;
  79. #define get_rpc_createerr() (*__rpc_thread_createerr_internal ())
  80. /*
  81. * UDP bases client side rpc operations
  82. */
  83. static enum clnt_stat clntudp_call (CLIENT *, u_long, xdrproc_t, caddr_t,
  84. xdrproc_t, caddr_t, struct timeval);
  85. static void clntudp_abort (void);
  86. static void clntudp_geterr (CLIENT *, struct rpc_err *);
  87. static bool_t clntudp_freeres (CLIENT *, xdrproc_t, caddr_t);
  88. static bool_t clntudp_control (CLIENT *, int, char *);
  89. static void clntudp_destroy (CLIENT *);
  90. static struct clnt_ops udp_ops =
  91. {
  92. clntudp_call,
  93. clntudp_abort,
  94. clntudp_geterr,
  95. clntudp_freeres,
  96. clntudp_destroy,
  97. clntudp_control
  98. };
  99. /*
  100. * Private data kept per client handle
  101. */
  102. struct cu_data
  103. {
  104. int cu_sock;
  105. bool_t cu_closeit;
  106. struct sockaddr_in cu_raddr;
  107. int cu_rlen;
  108. struct timeval cu_wait;
  109. struct timeval cu_total;
  110. struct rpc_err cu_error;
  111. XDR cu_outxdrs;
  112. u_int cu_xdrpos;
  113. u_int cu_sendsz;
  114. char *cu_outbuf;
  115. u_int cu_recvsz;
  116. char cu_inbuf[1];
  117. };
  118. /*
  119. * Create a UDP based client handle.
  120. * If *sockp<0, *sockp is set to a newly created UPD socket.
  121. * If raddr->sin_port is 0 a binder on the remote machine
  122. * is consulted for the correct port number.
  123. * NB: It is the clients responsibility to close *sockp.
  124. * NB: The rpch->cl_auth is initialized to null authentication.
  125. * Caller may wish to set this something more useful.
  126. *
  127. * wait is the amount of time used between retransmitting a call if
  128. * no response has been heard; retransmission occurs until the actual
  129. * rpc call times out.
  130. *
  131. * sendsz and recvsz are the maximum allowable packet sizes that can be
  132. * sent and received.
  133. */
  134. CLIENT attribute_hidden *
  135. __clntudp_bufcreate (struct sockaddr_in *raddr, u_long program, u_long version,
  136. struct timeval wait, int *sockp, u_int sendsz,
  137. u_int recvsz)
  138. {
  139. CLIENT *cl;
  140. struct cu_data *cu = NULL;
  141. struct rpc_msg call_msg;
  142. cl = (CLIENT *) mem_alloc (sizeof (CLIENT));
  143. sendsz = ((sendsz + 3) / 4) * 4;
  144. recvsz = ((recvsz + 3) / 4) * 4;
  145. cu = (struct cu_data *) mem_alloc (sizeof (*cu) + sendsz + recvsz);
  146. if (cl == NULL || cu == NULL)
  147. {
  148. struct rpc_createerr *ce = &get_rpc_createerr ();
  149. #ifdef USE_IN_LIBIO
  150. if (_IO_fwide (stderr, 0) > 0)
  151. (void) __fwprintf (stderr, L"%s",
  152. _("clntudp_create: out of memory\n"));
  153. else
  154. #endif
  155. (void) fputs (_("clntudp_create: out of memory\n"), stderr);
  156. ce->cf_stat = RPC_SYSTEMERROR;
  157. ce->cf_error.re_errno = ENOMEM;
  158. goto fooy;
  159. }
  160. cu->cu_outbuf = &cu->cu_inbuf[recvsz];
  161. if (raddr->sin_port == 0)
  162. {
  163. u_short port;
  164. if ((port =
  165. pmap_getport (raddr, program, version, IPPROTO_UDP)) == 0)
  166. {
  167. goto fooy;
  168. }
  169. raddr->sin_port = htons (port);
  170. }
  171. cl->cl_ops = &udp_ops;
  172. cl->cl_private = (caddr_t) cu;
  173. cu->cu_raddr = *raddr;
  174. cu->cu_rlen = sizeof (cu->cu_raddr);
  175. cu->cu_wait = wait;
  176. cu->cu_total.tv_sec = -1;
  177. cu->cu_total.tv_usec = -1;
  178. cu->cu_sendsz = sendsz;
  179. cu->cu_recvsz = recvsz;
  180. call_msg.rm_xid = _create_xid ();
  181. call_msg.rm_direction = CALL;
  182. call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  183. call_msg.rm_call.cb_prog = program;
  184. call_msg.rm_call.cb_vers = version;
  185. xdrmem_create (&(cu->cu_outxdrs), cu->cu_outbuf,
  186. sendsz, XDR_ENCODE);
  187. if (!xdr_callhdr (&(cu->cu_outxdrs), &call_msg))
  188. {
  189. goto fooy;
  190. }
  191. cu->cu_xdrpos = XDR_GETPOS (&(cu->cu_outxdrs));
  192. if (*sockp < 0)
  193. {
  194. int dontblock = 1;
  195. *sockp = __socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  196. if (*sockp < 0)
  197. {
  198. struct rpc_createerr *ce = &get_rpc_createerr ();
  199. ce->cf_stat = RPC_SYSTEMERROR;
  200. ce->cf_error.re_errno = errno;
  201. goto fooy;
  202. }
  203. /* attempt to bind to prov port */
  204. (void) bindresvport (*sockp, (struct sockaddr_in *) 0);
  205. /* the sockets rpc controls are non-blocking */
  206. (void) __ioctl (*sockp, FIONBIO, (char *) &dontblock);
  207. #ifdef IP_RECVERR
  208. {
  209. int on = 1;
  210. setsockopt(*sockp, SOL_IP, IP_RECVERR, &on, sizeof(on));
  211. }
  212. #endif
  213. cu->cu_closeit = TRUE;
  214. }
  215. else
  216. {
  217. cu->cu_closeit = FALSE;
  218. }
  219. cu->cu_sock = *sockp;
  220. cl->cl_auth = authnone_create ();
  221. return cl;
  222. fooy:
  223. if (cu)
  224. mem_free ((caddr_t) cu, sizeof (*cu) + sendsz + recvsz);
  225. if (cl)
  226. mem_free ((caddr_t) cl, sizeof (CLIENT));
  227. return (CLIENT *) NULL;
  228. }
  229. strong_alias(__clntudp_bufcreate,clntudp_bufcreate)
  230. CLIENT attribute_hidden *
  231. __clntudp_create (struct sockaddr_in *raddr, u_long program, u_long version, struct timeval wait, int *sockp)
  232. {
  233. return __clntudp_bufcreate (raddr, program, version, wait, sockp,
  234. UDPMSGSIZE, UDPMSGSIZE);
  235. }
  236. strong_alias(__clntudp_create,clntudp_create)
  237. static int
  238. is_network_up (int sock)
  239. {
  240. struct ifconf ifc;
  241. char buf[UDPMSGSIZE];
  242. struct ifreq ifreq, *ifr;
  243. int n;
  244. ifc.ifc_len = sizeof (buf);
  245. ifc.ifc_buf = buf;
  246. if (__ioctl(sock, SIOCGIFCONF, (char *) &ifc) == 0)
  247. {
  248. ifr = ifc.ifc_req;
  249. for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++)
  250. {
  251. ifreq = *ifr;
  252. if (__ioctl (sock, SIOCGIFFLAGS, (char *) &ifreq) < 0)
  253. break;
  254. if ((ifreq.ifr_flags & IFF_UP)
  255. && ifr->ifr_addr.sa_family == AF_INET)
  256. return 1;
  257. }
  258. }
  259. return 0;
  260. }
  261. static enum clnt_stat
  262. clntudp_call (cl, proc, xargs, argsp, xresults, resultsp, utimeout)
  263. CLIENT *cl; /* client handle */
  264. u_long proc; /* procedure number */
  265. xdrproc_t xargs; /* xdr routine for args */
  266. caddr_t argsp; /* pointer to args */
  267. xdrproc_t xresults; /* xdr routine for results */
  268. caddr_t resultsp; /* pointer to results */
  269. struct timeval utimeout; /* seconds to wait before giving up */
  270. {
  271. struct cu_data *cu = (struct cu_data *) cl->cl_private;
  272. XDR *xdrs;
  273. int outlen = 0;
  274. int inlen;
  275. socklen_t fromlen;
  276. struct pollfd fd;
  277. int milliseconds = (cu->cu_wait.tv_sec * 1000) +
  278. (cu->cu_wait.tv_usec / 1000);
  279. struct sockaddr_in from;
  280. struct rpc_msg reply_msg;
  281. XDR reply_xdrs;
  282. struct timeval time_waited;
  283. bool_t ok;
  284. int nrefreshes = 2; /* number of times to refresh cred */
  285. struct timeval timeout;
  286. int anyup; /* any network interface up */
  287. if (cu->cu_total.tv_usec == -1)
  288. {
  289. timeout = utimeout; /* use supplied timeout */
  290. }
  291. else
  292. {
  293. timeout = cu->cu_total; /* use default timeout */
  294. }
  295. time_waited.tv_sec = 0;
  296. time_waited.tv_usec = 0;
  297. call_again:
  298. xdrs = &(cu->cu_outxdrs);
  299. if (xargs == NULL)
  300. goto get_reply;
  301. xdrs->x_op = XDR_ENCODE;
  302. XDR_SETPOS (xdrs, cu->cu_xdrpos);
  303. /*
  304. * the transaction is the first thing in the out buffer
  305. */
  306. (*(uint32_t *) (cu->cu_outbuf))++;
  307. if ((!XDR_PUTLONG (xdrs, (long *) &proc)) ||
  308. (!AUTH_MARSHALL (cl->cl_auth, xdrs)) ||
  309. (!(*xargs) (xdrs, argsp)))
  310. return (cu->cu_error.re_status = RPC_CANTENCODEARGS);
  311. outlen = (int) XDR_GETPOS (xdrs);
  312. send_again:
  313. if (sendto (cu->cu_sock, cu->cu_outbuf, outlen, 0,
  314. (struct sockaddr *) &(cu->cu_raddr), cu->cu_rlen)
  315. != outlen)
  316. {
  317. cu->cu_error.re_errno = errno;
  318. return (cu->cu_error.re_status = RPC_CANTSEND);
  319. }
  320. /*
  321. * Hack to provide rpc-based message passing
  322. */
  323. if (timeout.tv_sec == 0 && timeout.tv_usec == 0)
  324. {
  325. return (cu->cu_error.re_status = RPC_TIMEDOUT);
  326. }
  327. get_reply:
  328. /*
  329. * sub-optimal code appears here because we have
  330. * some clock time to spare while the packets are in flight.
  331. * (We assume that this is actually only executed once.)
  332. */
  333. reply_msg.acpted_rply.ar_verf = _null_auth;
  334. reply_msg.acpted_rply.ar_results.where = resultsp;
  335. reply_msg.acpted_rply.ar_results.proc = xresults;
  336. fd.fd = cu->cu_sock;
  337. fd.events = POLLIN;
  338. anyup = 0;
  339. for (;;)
  340. {
  341. switch (poll (&fd, 1, milliseconds))
  342. {
  343. case 0:
  344. if (anyup == 0)
  345. {
  346. anyup = is_network_up (cu->cu_sock);
  347. if (!anyup)
  348. return (cu->cu_error.re_status = RPC_CANTRECV);
  349. }
  350. time_waited.tv_sec += cu->cu_wait.tv_sec;
  351. time_waited.tv_usec += cu->cu_wait.tv_usec;
  352. while (time_waited.tv_usec >= 1000000)
  353. {
  354. time_waited.tv_sec++;
  355. time_waited.tv_usec -= 1000000;
  356. }
  357. if ((time_waited.tv_sec < timeout.tv_sec) ||
  358. ((time_waited.tv_sec == timeout.tv_sec) &&
  359. (time_waited.tv_usec < timeout.tv_usec)))
  360. goto send_again;
  361. return (cu->cu_error.re_status = RPC_TIMEDOUT);
  362. /*
  363. * buggy in other cases because time_waited is not being
  364. * updated.
  365. */
  366. case -1:
  367. if (errno == EINTR)
  368. continue;
  369. cu->cu_error.re_errno = errno;
  370. return (cu->cu_error.re_status = RPC_CANTRECV);
  371. }
  372. #ifdef IP_RECVERR
  373. if (fd.revents & POLLERR)
  374. {
  375. struct msghdr msg;
  376. struct cmsghdr *cmsg;
  377. struct sock_extended_err *e;
  378. struct sockaddr_in err_addr;
  379. struct iovec iov;
  380. char *cbuf = (char *) alloca (outlen + 256);
  381. int ret;
  382. iov.iov_base = cbuf + 256;
  383. iov.iov_len = outlen;
  384. msg.msg_name = (void *) &err_addr;
  385. msg.msg_namelen = sizeof (err_addr);
  386. msg.msg_iov = &iov;
  387. msg.msg_iovlen = 1;
  388. msg.msg_flags = 0;
  389. msg.msg_control = cbuf;
  390. msg.msg_controllen = 256;
  391. ret = recvmsg (cu->cu_sock, &msg, MSG_ERRQUEUE);
  392. if (ret >= 0
  393. && __memcmp (cbuf + 256, cu->cu_outbuf, ret) == 0
  394. && (msg.msg_flags & MSG_ERRQUEUE)
  395. && ((msg.msg_namelen == 0
  396. && ret >= 12)
  397. || (msg.msg_namelen == sizeof (err_addr)
  398. && err_addr.sin_family == AF_INET
  399. && __memcmp (&err_addr.sin_addr, &cu->cu_raddr.sin_addr,
  400. sizeof (err_addr.sin_addr)) == 0
  401. && err_addr.sin_port == cu->cu_raddr.sin_port)))
  402. for (cmsg = CMSG_FIRSTHDR (&msg); cmsg;
  403. cmsg = CMSG_NXTHDR (&msg, cmsg))
  404. if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR)
  405. {
  406. e = (struct sock_extended_err *) CMSG_DATA(cmsg);
  407. cu->cu_error.re_errno = e->ee_errno;
  408. return (cu->cu_error.re_status = RPC_CANTRECV);
  409. }
  410. }
  411. #endif
  412. do
  413. {
  414. fromlen = sizeof (struct sockaddr);
  415. inlen = recvfrom (cu->cu_sock, cu->cu_inbuf,
  416. (int) cu->cu_recvsz, 0,
  417. (struct sockaddr *) &from, &fromlen);
  418. }
  419. while (inlen < 0 && errno == EINTR);
  420. if (inlen < 0)
  421. {
  422. if (errno == EWOULDBLOCK)
  423. continue;
  424. cu->cu_error.re_errno = errno;
  425. return (cu->cu_error.re_status = RPC_CANTRECV);
  426. }
  427. if (inlen < 4)
  428. continue;
  429. /* see if reply transaction id matches sent id.
  430. Don't do this if we only wait for a replay */
  431. if (xargs != NULL
  432. && (*((u_int32_t *) (cu->cu_inbuf))
  433. != *((u_int32_t *) (cu->cu_outbuf))))
  434. continue;
  435. /* we now assume we have the proper reply */
  436. break;
  437. }
  438. /*
  439. * now decode and validate the response
  440. */
  441. xdrmem_create (&reply_xdrs, cu->cu_inbuf, (u_int) inlen, XDR_DECODE);
  442. ok = xdr_replymsg (&reply_xdrs, &reply_msg);
  443. /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
  444. if (ok)
  445. {
  446. _seterr_reply (&reply_msg, &(cu->cu_error));
  447. if (cu->cu_error.re_status == RPC_SUCCESS)
  448. {
  449. if (!AUTH_VALIDATE (cl->cl_auth,
  450. &reply_msg.acpted_rply.ar_verf))
  451. {
  452. cu->cu_error.re_status = RPC_AUTHERROR;
  453. cu->cu_error.re_why = AUTH_INVALIDRESP;
  454. }
  455. if (reply_msg.acpted_rply.ar_verf.oa_base != NULL)
  456. {
  457. xdrs->x_op = XDR_FREE;
  458. (void) xdr_opaque_auth (xdrs,
  459. &(reply_msg.acpted_rply.ar_verf));
  460. }
  461. } /* end successful completion */
  462. else
  463. {
  464. /* maybe our credentials need to be refreshed ... */
  465. if (nrefreshes > 0 && AUTH_REFRESH (cl->cl_auth))
  466. {
  467. nrefreshes--;
  468. goto call_again;
  469. }
  470. } /* end of unsuccessful completion */
  471. } /* end of valid reply message */
  472. else
  473. {
  474. cu->cu_error.re_status = RPC_CANTDECODERES;
  475. }
  476. return cu->cu_error.re_status;
  477. }
  478. static void
  479. clntudp_geterr (CLIENT *cl, struct rpc_err *errp)
  480. {
  481. struct cu_data *cu = (struct cu_data *) cl->cl_private;
  482. *errp = cu->cu_error;
  483. }
  484. static bool_t
  485. clntudp_freeres (CLIENT *cl, xdrproc_t xdr_res, caddr_t res_ptr)
  486. {
  487. struct cu_data *cu = (struct cu_data *) cl->cl_private;
  488. XDR *xdrs = &(cu->cu_outxdrs);
  489. xdrs->x_op = XDR_FREE;
  490. return (*xdr_res) (xdrs, res_ptr);
  491. }
  492. static void
  493. clntudp_abort (void)
  494. {
  495. }
  496. static bool_t
  497. clntudp_control (CLIENT *cl, int request, char *info)
  498. {
  499. struct cu_data *cu = (struct cu_data *) cl->cl_private;
  500. switch (request)
  501. {
  502. case CLSET_FD_CLOSE:
  503. cu->cu_closeit = TRUE;
  504. break;
  505. case CLSET_FD_NCLOSE:
  506. cu->cu_closeit = FALSE;
  507. break;
  508. case CLSET_TIMEOUT:
  509. cu->cu_total = *(struct timeval *) info;
  510. break;
  511. case CLGET_TIMEOUT:
  512. *(struct timeval *) info = cu->cu_total;
  513. break;
  514. case CLSET_RETRY_TIMEOUT:
  515. cu->cu_wait = *(struct timeval *) info;
  516. break;
  517. case CLGET_RETRY_TIMEOUT:
  518. *(struct timeval *) info = cu->cu_wait;
  519. break;
  520. case CLGET_SERVER_ADDR:
  521. *(struct sockaddr_in *) info = cu->cu_raddr;
  522. break;
  523. case CLGET_FD:
  524. *(int *)info = cu->cu_sock;
  525. break;
  526. case CLGET_XID:
  527. /*
  528. * use the knowledge that xid is the
  529. * first element in the call structure *.
  530. * This will get the xid of the PREVIOUS call
  531. */
  532. *(u_long *)info = ntohl(*(u_long *)cu->cu_outbuf);
  533. break;
  534. case CLSET_XID:
  535. /* This will set the xid of the NEXT call */
  536. *(u_long *)cu->cu_outbuf = htonl(*(u_long *)info - 1);
  537. /* decrement by 1 as clntudp_call() increments once */
  538. case CLGET_VERS:
  539. /*
  540. * This RELIES on the information that, in the call body,
  541. * the version number field is the fifth field from the
  542. * begining of the RPC header. MUST be changed if the
  543. * call_struct is changed
  544. */
  545. *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf +
  546. 4 * BYTES_PER_XDR_UNIT));
  547. break;
  548. case CLSET_VERS:
  549. *(u_long *)(cu->cu_outbuf + 4 * BYTES_PER_XDR_UNIT)
  550. = htonl(*(u_long *)info);
  551. break;
  552. case CLGET_PROG:
  553. /*
  554. * This RELIES on the information that, in the call body,
  555. * the program number field is the field from the
  556. * begining of the RPC header. MUST be changed if the
  557. * call_struct is changed
  558. */
  559. *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf +
  560. 3 * BYTES_PER_XDR_UNIT));
  561. break;
  562. case CLSET_PROG:
  563. *(u_long *)(cu->cu_outbuf + 3 * BYTES_PER_XDR_UNIT)
  564. = htonl(*(u_long *)info);
  565. break;
  566. /* The following are only possible with TI-RPC */
  567. case CLGET_SVC_ADDR:
  568. case CLSET_SVC_ADDR:
  569. case CLSET_PUSH_TIMOD:
  570. case CLSET_POP_TIMOD:
  571. default:
  572. return FALSE;
  573. }
  574. return TRUE;
  575. }
  576. static void
  577. clntudp_destroy (CLIENT *cl)
  578. {
  579. struct cu_data *cu = (struct cu_data *) cl->cl_private;
  580. if (cu->cu_closeit)
  581. {
  582. (void) __close (cu->cu_sock);
  583. }
  584. XDR_DESTROY (&(cu->cu_outxdrs));
  585. mem_free ((caddr_t) cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
  586. mem_free ((caddr_t) cl, sizeof (CLIENT));
  587. }