clnt_udp.c 17 KB

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