clnt_udp.c 17 KB

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