clnt_udp.c 17 KB

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