xdr_rec.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3. * unrestricted use provided that this legend is included on all tape
  4. * media and as a part of the software program in whole or part. Users
  5. * may copy or modify Sun RPC without charge, but are not authorized
  6. * to license or distribute it to anyone else except as part of a product or
  7. * program developed by the user.
  8. *
  9. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12. *
  13. * Sun RPC is provided with no support and without any obligation on the
  14. * part of Sun Microsystems, Inc. to assist in its use, correction,
  15. * modification or enhancement.
  16. *
  17. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19. * OR ANY PART THEREOF.
  20. *
  21. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22. * or profits or other special, indirect and consequential damages, even if
  23. * Sun has been advised of the possibility of such damages.
  24. *
  25. * Sun Microsystems, Inc.
  26. * 2550 Garcia Avenue
  27. * Mountain View, California 94043
  28. */
  29. /*
  30. * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
  31. * layer above tcp (for rpc's use).
  32. *
  33. * Copyright (C) 1984, Sun Microsystems, Inc.
  34. *
  35. * These routines interface XDRSTREAMS to a tcp/ip connection.
  36. * There is a record marking layer between the xdr stream
  37. * and the tcp transport level. A record is composed on one or more
  38. * record fragments. A record fragment is a thirty-two bit header followed
  39. * by n bytes of data, where n is contained in the header. The header
  40. * is represented as a htonl(u_long). The high order bit encodes
  41. * whether or not the fragment is the last fragment of the record
  42. * (1 => fragment is last, 0 => more fragments to follow.
  43. * The other 31 bits encode the byte length of the fragment.
  44. */
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <unistd.h>
  48. #include "rpc_private.h"
  49. static bool_t xdrrec_getbytes (XDR *, caddr_t, u_int);
  50. static bool_t xdrrec_putbytes (XDR *, const char *, u_int);
  51. static bool_t xdrrec_getint32 (XDR *, int32_t *);
  52. static bool_t xdrrec_putint32 (XDR *, const int32_t *);
  53. #if ULONG_MAX != 0xffffffff
  54. static bool_t xdrrec_getlong (XDR *, long *);
  55. static bool_t xdrrec_putlong (XDR *, const long *);
  56. #endif
  57. static u_int xdrrec_getpos (const XDR *);
  58. static bool_t xdrrec_setpos (XDR *, u_int);
  59. static int32_t *xdrrec_inline (XDR *, u_int);
  60. static void xdrrec_destroy (XDR *);
  61. static const struct xdr_ops xdrrec_ops = {
  62. #if ULONG_MAX == 0xffffffff
  63. (bool_t (*)(XDR *, long *)) xdrrec_getint32,
  64. (bool_t (*)(XDR *, const long *)) xdrrec_putint32,
  65. #else
  66. xdrrec_getlong,
  67. xdrrec_putlong,
  68. #endif
  69. xdrrec_getbytes,
  70. xdrrec_putbytes,
  71. xdrrec_getpos,
  72. xdrrec_setpos,
  73. xdrrec_inline,
  74. xdrrec_destroy,
  75. xdrrec_getint32,
  76. xdrrec_putint32
  77. };
  78. /*
  79. * A record is composed of one or more record fragments.
  80. * A record fragment is a two-byte header followed by zero to
  81. * 2**32-1 bytes. The header is treated as a long unsigned and is
  82. * encode/decoded to the network via htonl/ntohl. The low order 31 bits
  83. * are a byte count of the fragment. The highest order bit is a boolean:
  84. * 1 => this fragment is the last fragment of the record,
  85. * 0 => this fragment is followed by more fragment(s).
  86. *
  87. * The fragment/record machinery is not general; it is constructed to
  88. * meet the needs of xdr and rpc based on tcp.
  89. */
  90. #define LAST_FRAG (1UL << 31)
  91. typedef struct rec_strm
  92. {
  93. caddr_t tcp_handle;
  94. caddr_t the_buffer;
  95. /*
  96. * out-going bits
  97. */
  98. int (*writeit) (char *, char *, int);
  99. caddr_t out_base; /* output buffer (points to frag header) */
  100. caddr_t out_finger; /* next output position */
  101. caddr_t out_boundry; /* data cannot up to this address */
  102. u_int32_t *frag_header; /* beginning of curren fragment */
  103. bool_t frag_sent; /* true if buffer sent in middle of record */
  104. /*
  105. * in-coming bits
  106. */
  107. int (*readit) (char *, char *, int);
  108. u_long in_size; /* fixed size of the input buffer */
  109. caddr_t in_base;
  110. caddr_t in_finger; /* location of next byte to be had */
  111. caddr_t in_boundry; /* can read up to this location */
  112. long fbtbc; /* fragment bytes to be consumed */
  113. bool_t last_frag;
  114. u_int sendsize;
  115. u_int recvsize;
  116. }
  117. RECSTREAM;
  118. static u_int fix_buf_size (u_int) internal_function;
  119. static bool_t skip_input_bytes (RECSTREAM *, long) internal_function;
  120. static bool_t flush_out (RECSTREAM *, bool_t) internal_function;
  121. static bool_t set_input_fragment (RECSTREAM *) internal_function;
  122. static bool_t get_input_bytes (RECSTREAM *, caddr_t, int) internal_function;
  123. /*
  124. * Create an xdr handle for xdrrec
  125. * xdrrec_create fills in xdrs. Sendsize and recvsize are
  126. * send and recv buffer sizes (0 => use default).
  127. * tcp_handle is an opaque handle that is passed as the first parameter to
  128. * the procedures readit and writeit. Readit and writeit are read and
  129. * write respectively. They are like the system
  130. * calls expect that they take an opaque handle rather than an fd.
  131. */
  132. void
  133. xdrrec_create (XDR *xdrs, u_int sendsize,
  134. u_int recvsize, caddr_t tcp_handle,
  135. int (*readit) (char *, char *, int),
  136. int (*writeit) (char *, char *, int))
  137. {
  138. RECSTREAM *rstrm = (RECSTREAM *) mem_alloc (sizeof (RECSTREAM));
  139. caddr_t tmp;
  140. char *buf;
  141. sendsize = fix_buf_size (sendsize);
  142. recvsize = fix_buf_size (recvsize);
  143. buf = mem_alloc (sendsize + recvsize + BYTES_PER_XDR_UNIT);
  144. if (rstrm == NULL || buf == NULL)
  145. {
  146. (void) fputs (_("xdrrec_create: out of memory\n"), stderr);
  147. mem_free (rstrm, sizeof (RECSTREAM));
  148. mem_free (buf, sendsize + recvsize + BYTES_PER_XDR_UNIT);
  149. /*
  150. * This is bad. Should rework xdrrec_create to
  151. * return a handle, and in this case return NULL
  152. */
  153. return;
  154. }
  155. /*
  156. * adjust sizes and allocate buffer quad byte aligned
  157. */
  158. rstrm->sendsize = sendsize;
  159. rstrm->recvsize = recvsize;
  160. rstrm->the_buffer = buf;
  161. tmp = rstrm->the_buffer;
  162. if ((size_t)tmp % BYTES_PER_XDR_UNIT)
  163. tmp += BYTES_PER_XDR_UNIT - (size_t)tmp % BYTES_PER_XDR_UNIT;
  164. rstrm->out_base = tmp;
  165. rstrm->in_base = tmp + sendsize;
  166. /*
  167. * now the rest ...
  168. */
  169. xdrs->x_ops = &xdrrec_ops;
  170. xdrs->x_private = (caddr_t) rstrm;
  171. rstrm->tcp_handle = tcp_handle;
  172. rstrm->readit = readit;
  173. rstrm->writeit = writeit;
  174. rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
  175. rstrm->frag_header = (u_int32_t *) rstrm->out_base;
  176. rstrm->out_finger += 4;
  177. rstrm->out_boundry += sendsize;
  178. rstrm->frag_sent = FALSE;
  179. rstrm->in_size = recvsize;
  180. rstrm->in_boundry = rstrm->in_base;
  181. rstrm->in_finger = (rstrm->in_boundry += recvsize);
  182. rstrm->fbtbc = 0;
  183. rstrm->last_frag = TRUE;
  184. }
  185. libc_hidden_def(xdrrec_create)
  186. /*
  187. * The routines defined below are the xdr ops which will go into the
  188. * xdr handle filled in by xdrrec_create.
  189. */
  190. static bool_t
  191. xdrrec_getint32 (XDR *xdrs, int32_t *ip)
  192. {
  193. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  194. int32_t *bufip = (int32_t *) rstrm->in_finger;
  195. int32_t mylong;
  196. /* first try the inline, fast case */
  197. if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
  198. rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT)
  199. {
  200. *ip = ntohl (*bufip);
  201. rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
  202. rstrm->in_finger += BYTES_PER_XDR_UNIT;
  203. }
  204. else
  205. {
  206. if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong,
  207. BYTES_PER_XDR_UNIT))
  208. return FALSE;
  209. *ip = ntohl (mylong);
  210. }
  211. return TRUE;
  212. }
  213. #if ULONG_MAX != 0xffffffff
  214. static bool_t
  215. xdrrec_getlong (XDR *xdrs, long *lp)
  216. {
  217. int32_t v;
  218. bool_t r = xdrrec_getint32 (xdrs, &v);
  219. *lp = v;
  220. return r;
  221. }
  222. #endif
  223. static bool_t
  224. xdrrec_putint32 (XDR *xdrs, const int32_t *ip)
  225. {
  226. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  227. int32_t *dest_ip = (int32_t *) rstrm->out_finger;
  228. if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry)
  229. {
  230. /*
  231. * this case should almost never happen so the code is
  232. * inefficient
  233. */
  234. rstrm->out_finger -= BYTES_PER_XDR_UNIT;
  235. rstrm->frag_sent = TRUE;
  236. if (!flush_out (rstrm, FALSE))
  237. return FALSE;
  238. dest_ip = (int32_t *) rstrm->out_finger;
  239. rstrm->out_finger += BYTES_PER_XDR_UNIT;
  240. }
  241. *dest_ip = htonl (*ip);
  242. return TRUE;
  243. }
  244. #if ULONG_MAX != 0xffffffff
  245. static bool_t
  246. xdrrec_putlong (XDR *xdrs, const long *lp)
  247. {
  248. int32_t v = *lp;
  249. return xdrrec_putint32 (xdrs, &v);
  250. }
  251. #endif
  252. static bool_t /* must manage buffers, fragments, and records */
  253. xdrrec_getbytes (XDR *xdrs, caddr_t addr, u_int len)
  254. {
  255. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  256. u_int current;
  257. while (len > 0)
  258. {
  259. current = rstrm->fbtbc;
  260. if (current == 0)
  261. {
  262. if (rstrm->last_frag)
  263. return FALSE;
  264. if (!set_input_fragment (rstrm))
  265. return FALSE;
  266. continue;
  267. }
  268. current = (len < current) ? len : current;
  269. if (!get_input_bytes (rstrm, addr, current))
  270. return FALSE;
  271. addr += current;
  272. rstrm->fbtbc -= current;
  273. len -= current;
  274. }
  275. return TRUE;
  276. }
  277. static bool_t
  278. xdrrec_putbytes (XDR *xdrs, const char *addr, u_int len)
  279. {
  280. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  281. u_int current;
  282. while (len > 0)
  283. {
  284. current = rstrm->out_boundry - rstrm->out_finger;
  285. current = (len < current) ? len : current;
  286. memcpy (rstrm->out_finger, addr, current);
  287. rstrm->out_finger += current;
  288. addr += current;
  289. len -= current;
  290. if (rstrm->out_finger == rstrm->out_boundry && len > 0)
  291. {
  292. rstrm->frag_sent = TRUE;
  293. if (!flush_out (rstrm, FALSE))
  294. return FALSE;
  295. }
  296. }
  297. return TRUE;
  298. }
  299. static u_int
  300. xdrrec_getpos (const XDR *xdrs)
  301. {
  302. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  303. long pos;
  304. pos = lseek ((int) (long) rstrm->tcp_handle, (long) 0, 1);
  305. if (pos != -1)
  306. switch (xdrs->x_op)
  307. {
  308. case XDR_ENCODE:
  309. pos += rstrm->out_finger - rstrm->out_base;
  310. break;
  311. case XDR_DECODE:
  312. pos -= rstrm->in_boundry - rstrm->in_finger;
  313. break;
  314. default:
  315. pos = (u_int) - 1;
  316. break;
  317. }
  318. return (u_int) pos;
  319. }
  320. static bool_t
  321. xdrrec_setpos (XDR *xdrs, u_int pos)
  322. {
  323. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  324. u_int currpos = xdrrec_getpos (xdrs);
  325. int delta = currpos - pos;
  326. caddr_t newpos;
  327. if ((int) currpos != -1)
  328. switch (xdrs->x_op)
  329. {
  330. case XDR_ENCODE:
  331. newpos = rstrm->out_finger - delta;
  332. if (newpos > (caddr_t) rstrm->frag_header &&
  333. newpos < rstrm->out_boundry)
  334. {
  335. rstrm->out_finger = newpos;
  336. return TRUE;
  337. }
  338. break;
  339. case XDR_DECODE:
  340. newpos = rstrm->in_finger - delta;
  341. if ((delta < (int) (rstrm->fbtbc)) &&
  342. (newpos <= rstrm->in_boundry) &&
  343. (newpos >= rstrm->in_base))
  344. {
  345. rstrm->in_finger = newpos;
  346. rstrm->fbtbc -= delta;
  347. return TRUE;
  348. }
  349. break;
  350. default:
  351. break;
  352. }
  353. return FALSE;
  354. }
  355. static int32_t *
  356. xdrrec_inline (XDR *xdrs, u_int len)
  357. {
  358. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  359. int32_t *buf = NULL;
  360. switch (xdrs->x_op)
  361. {
  362. case XDR_ENCODE:
  363. if ((rstrm->out_finger + len) <= rstrm->out_boundry)
  364. {
  365. buf = (int32_t *) rstrm->out_finger;
  366. rstrm->out_finger += len;
  367. }
  368. break;
  369. case XDR_DECODE:
  370. if ((len <= rstrm->fbtbc) &&
  371. ((rstrm->in_finger + len) <= rstrm->in_boundry))
  372. {
  373. buf = (int32_t *) rstrm->in_finger;
  374. rstrm->fbtbc -= len;
  375. rstrm->in_finger += len;
  376. }
  377. break;
  378. default:
  379. break;
  380. }
  381. return buf;
  382. }
  383. static void
  384. xdrrec_destroy (XDR *xdrs)
  385. {
  386. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  387. mem_free (rstrm->the_buffer,
  388. rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
  389. mem_free ((caddr_t) rstrm, sizeof (RECSTREAM));
  390. }
  391. /*
  392. * Exported routines to manage xdr records
  393. */
  394. /*
  395. * Before reading (deserializing from the stream, one should always call
  396. * this procedure to guarantee proper record alignment.
  397. */
  398. bool_t
  399. xdrrec_skiprecord (XDR *xdrs)
  400. {
  401. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  402. while (rstrm->fbtbc > 0 || (!rstrm->last_frag))
  403. {
  404. if (!skip_input_bytes (rstrm, rstrm->fbtbc))
  405. return FALSE;
  406. rstrm->fbtbc = 0;
  407. if ((!rstrm->last_frag) && (!set_input_fragment (rstrm)))
  408. return FALSE;
  409. }
  410. rstrm->last_frag = FALSE;
  411. return TRUE;
  412. }
  413. libc_hidden_def(xdrrec_skiprecord)
  414. /*
  415. * Lookahead function.
  416. * Returns TRUE iff there is no more input in the buffer
  417. * after consuming the rest of the current record.
  418. */
  419. bool_t
  420. xdrrec_eof (XDR *xdrs)
  421. {
  422. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  423. while (rstrm->fbtbc > 0 || (!rstrm->last_frag))
  424. {
  425. if (!skip_input_bytes (rstrm, rstrm->fbtbc))
  426. return TRUE;
  427. rstrm->fbtbc = 0;
  428. if ((!rstrm->last_frag) && (!set_input_fragment (rstrm)))
  429. return TRUE;
  430. }
  431. if (rstrm->in_finger == rstrm->in_boundry)
  432. return TRUE;
  433. return FALSE;
  434. }
  435. libc_hidden_def(xdrrec_eof)
  436. /*
  437. * The client must tell the package when an end-of-record has occurred.
  438. * The second parameter tells whether the record should be flushed to the
  439. * (output) tcp stream. (This lets the package support batched or
  440. * pipelined procedure calls.) TRUE => immediate flush to tcp connection.
  441. */
  442. bool_t
  443. xdrrec_endofrecord (XDR *xdrs, bool_t sendnow)
  444. {
  445. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  446. u_long len; /* fragment length */
  447. if (sendnow || rstrm->frag_sent
  448. || rstrm->out_finger + BYTES_PER_XDR_UNIT >= rstrm->out_boundry)
  449. {
  450. rstrm->frag_sent = FALSE;
  451. return flush_out (rstrm, TRUE);
  452. }
  453. len = (rstrm->out_finger - (char *) rstrm->frag_header
  454. - BYTES_PER_XDR_UNIT);
  455. *rstrm->frag_header = htonl ((u_long) len | LAST_FRAG);
  456. rstrm->frag_header = (u_int32_t *) rstrm->out_finger;
  457. rstrm->out_finger += BYTES_PER_XDR_UNIT;
  458. return TRUE;
  459. }
  460. libc_hidden_def(xdrrec_endofrecord)
  461. /*
  462. * Internal useful routines
  463. */
  464. static bool_t
  465. internal_function
  466. flush_out (RECSTREAM *rstrm, bool_t eor)
  467. {
  468. u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
  469. u_long len = (rstrm->out_finger - (char *) rstrm->frag_header
  470. - BYTES_PER_XDR_UNIT);
  471. *rstrm->frag_header = htonl (len | eormask);
  472. len = rstrm->out_finger - rstrm->out_base;
  473. if ((*(rstrm->writeit)) (rstrm->tcp_handle, rstrm->out_base, (int) len)
  474. != (int) len)
  475. return FALSE;
  476. rstrm->frag_header = (u_int32_t *) rstrm->out_base;
  477. rstrm->out_finger = (caddr_t) rstrm->out_base + BYTES_PER_XDR_UNIT;
  478. return TRUE;
  479. }
  480. static bool_t /* knows nothing about records! Only about input buffers */
  481. fill_input_buf (RECSTREAM *rstrm)
  482. {
  483. caddr_t where;
  484. size_t i;
  485. int len;
  486. where = rstrm->in_base;
  487. i = (size_t) rstrm->in_boundry % BYTES_PER_XDR_UNIT;
  488. where += i;
  489. len = rstrm->in_size - i;
  490. if ((len = (*(rstrm->readit)) (rstrm->tcp_handle, where, len)) == -1)
  491. return FALSE;
  492. rstrm->in_finger = where;
  493. where += len;
  494. rstrm->in_boundry = where;
  495. return TRUE;
  496. }
  497. static bool_t /* knows nothing about records! Only about input buffers */
  498. internal_function
  499. get_input_bytes (RECSTREAM *rstrm, caddr_t addr, int len)
  500. {
  501. int current;
  502. while (len > 0)
  503. {
  504. current = rstrm->in_boundry - rstrm->in_finger;
  505. if (current == 0)
  506. {
  507. if (!fill_input_buf (rstrm))
  508. return FALSE;
  509. continue;
  510. }
  511. current = (len < current) ? len : current;
  512. memcpy (addr, rstrm->in_finger, current);
  513. rstrm->in_finger += current;
  514. addr += current;
  515. len -= current;
  516. }
  517. return TRUE;
  518. }
  519. static bool_t /* next two bytes of the input stream are treated as a header */
  520. internal_function
  521. set_input_fragment (RECSTREAM *rstrm)
  522. {
  523. uint32_t header;
  524. if (! get_input_bytes (rstrm, (caddr_t)&header, BYTES_PER_XDR_UNIT))
  525. return FALSE;
  526. header = ntohl (header);
  527. rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
  528. /*
  529. * Sanity check. Try not to accept wildly incorrect fragment
  530. * sizes. Unfortunately, only a size of zero can be identified as
  531. * 'wildely incorrect', and this only, if it is not the last
  532. * fragment of a message. Ridiculously large fragment sizes may look
  533. * wrong, but we don't have any way to be certain that they aren't
  534. * what the client actually intended to send us. Many existing RPC
  535. * implementations may sent a fragment of size zero as the last
  536. * fragment of a message.
  537. */
  538. if (header == 0)
  539. return FALSE;
  540. rstrm->fbtbc = header & ~LAST_FRAG;
  541. return TRUE;
  542. }
  543. static bool_t /* consumes input bytes; knows nothing about records! */
  544. internal_function
  545. skip_input_bytes (RECSTREAM *rstrm, long cnt)
  546. {
  547. int current;
  548. while (cnt > 0)
  549. {
  550. current = rstrm->in_boundry - rstrm->in_finger;
  551. if (current == 0)
  552. {
  553. if (!fill_input_buf (rstrm))
  554. return FALSE;
  555. continue;
  556. }
  557. current = (cnt < current) ? cnt : current;
  558. rstrm->in_finger += current;
  559. cnt -= current;
  560. }
  561. return TRUE;
  562. }
  563. static u_int
  564. internal_function
  565. fix_buf_size (u_int s)
  566. {
  567. if (s < 100)
  568. s = 4000;
  569. return RNDUP (s);
  570. }