clnt_udp.c 17 KB

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