data.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /* $Id: data.c,v 1.12 2002/07/25 09:51:42 dijkstra Exp $ */
  2. /*
  3. * Copyright (c) 2001-2002 Willem Dijkstra
  4. * All rights reserved.
  5. *
  6. * The crc routine is from Rob Warnock <rpw3@sgi.com>, from the
  7. * comp.compression FAQ.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials provided
  18. * with the distribution.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  30. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. * */
  33. /* Terminology:
  34. *
  35. * A host carrying a 'mon' is considered a 'source' of information. A single
  36. * data 'stream' of information has a particular type: <cpu|mem|if|io>. A
  37. * source can provide multiple 'streams' simultaniously. A source spools
  38. * information towards a 'mux'. A 'stream' that has been converted to network
  39. * representation is called a 'packedstream'.
  40. */
  41. #include <assert.h>
  42. #include <limits.h>
  43. #include <stdarg.h>
  44. #include <string.h>
  45. #include <stdio.h>
  46. #include <time.h>
  47. #include <unistd.h>
  48. #include "data.h"
  49. #include "error.h"
  50. #include "lex.h"
  51. #include "xmalloc.h"
  52. __BEGIN_DECLS
  53. int bytelenvar(char);
  54. int checklen(int, int, int);
  55. struct stream *create_stream(int, char *);
  56. char *formatstrvar(char);
  57. char *rrdstrvar(char);
  58. int strlenvar(char);
  59. __END_DECLS
  60. /* Stream formats
  61. *
  62. * Format specifications are strings of characters:
  63. *
  64. * L = u_int64
  65. * l = u_int32
  66. * c = 3.2f <= u_int14 <= u_int16 (used in percentages)
  67. */
  68. struct {
  69. char type;
  70. char *rrdformat;
  71. char *strformat;
  72. int strlen;
  73. int bytelen;
  74. u_int64_t max;
  75. } streamvar[] = {
  76. {'L', ":%qu", " %20qu", 22, sizeof(u_int64_t), (u_int64_t) 0xffffffffffffffff},
  77. {'l', ":%lu", " %10lu", 12, sizeof(u_int32_t), (u_int64_t) 0xffffffff},
  78. {'c', ":%3.2f", " %3.2f", 7, sizeof(u_int16_t), (u_int64_t) 100},
  79. {'\0', NULL, NULL, 0, 0, 0}
  80. };
  81. /* streams of <type> have the packedstream <form> */
  82. struct {
  83. int type;
  84. char *form;
  85. } streamform[] = {
  86. {MT_IO, "LLL"},
  87. {MT_CPU, "ccccc"},
  88. {MT_MEM, "lllll"},
  89. {MT_IF, "llllllllll"},
  90. {MT_EOT, ""}
  91. };
  92. struct {
  93. int type;
  94. int token;
  95. } streamtoken[] = {
  96. {MT_IO, LXT_IO},
  97. {MT_CPU, LXT_CPU},
  98. {MT_MEM, LXT_MEM},
  99. {MT_IF, LXT_IF},
  100. {MT_EOT, LXT_BADTOKEN}
  101. };
  102. /* parallel crc32 table */
  103. u_int32_t
  104. crc32_table[256];
  105. /* Convert lexical entities to stream entities */
  106. const int
  107. token2type(const int token)
  108. {
  109. int i;
  110. for (i=0; streamtoken[i].type < MT_EOT; i++)
  111. if (streamtoken[i].token == token)
  112. return streamtoken[i].type;
  113. fatal("%s:%d: internal error: token (%d) could not be translated into a stream type",
  114. __FILE__, __LINE__, token);
  115. /* NOT REACHED */
  116. return 0;
  117. }
  118. /* Convert stream entities to their ascii representation */
  119. const char *
  120. type2str(const int streamtype)
  121. {
  122. int i;
  123. for (i=0; streamtoken[i].type < MT_EOT; i++)
  124. if (streamtoken[i].type == streamtype)
  125. return parse_opcode(streamtoken[i].token);
  126. fatal("%s:%d: internal error: type (%d) could not be translated into ascii representation",
  127. __FILE__, __LINE__, streamtype);
  128. /* NOT REACHED */
  129. return 0;
  130. }
  131. /* Return the maximum lenght of the ascii representation of type <type> */
  132. int
  133. strlentype(int type)
  134. {
  135. int i = 0;
  136. int sum = 0;
  137. while (streamform[type].form[i])
  138. sum += strlenvar(streamform[type].form[i++]);
  139. return sum;
  140. }
  141. /* Return the maximum lenght of the ascii representation of streamvar <var> */
  142. int
  143. strlenvar(char var)
  144. {
  145. int i;
  146. for (i=0; streamvar[i].type > '\0'; i++)
  147. if (streamvar[i].type == var)
  148. return streamvar[i].strlen;
  149. fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
  150. __FILE__, __LINE__, var);
  151. /* NOT REACHED */
  152. return 0;
  153. }
  154. /* Return the maximum lenght of the network representation of streamvar <var> */
  155. int
  156. bytelenvar(char var)
  157. {
  158. int i;
  159. for (i=0; streamvar[i].type > '\0'; i++)
  160. if (streamvar[i].type == var)
  161. return streamvar[i].bytelen;
  162. fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
  163. __FILE__, __LINE__, var);
  164. /* NOT REACHED */
  165. return 0;
  166. }
  167. /* Return the ascii format string for streamvar <var> */
  168. char *
  169. formatstrvar(char var)
  170. {
  171. int i;
  172. for (i=0; streamvar[i].type > '\0'; i++)
  173. if (streamvar[i].type == var)
  174. return streamvar[i].strformat;
  175. fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
  176. __FILE__, __LINE__, var);
  177. /* NOT REACHED */
  178. return "";
  179. }
  180. /* Return the rrd format string for streamvar <var> */
  181. char *
  182. rrdstrvar(char var)
  183. {
  184. int i;
  185. for (i=0; streamvar[i].type > '\0'; i++)
  186. if (streamvar[i].type == var)
  187. return streamvar[i].rrdformat;
  188. fatal("internal error: type spefication for stream var '%c' not found", var);
  189. /* NOT REACHED */
  190. return "";
  191. }
  192. /* Check whether <extra> more bytes fit in <maxlen> when we are already at <start> */
  193. int
  194. checklen(int maxlen, int current, int extra)
  195. {
  196. if ((current + extra) < maxlen) {
  197. return 0;
  198. } else {
  199. warning("buffer overflow: max=%d, current=%d, extra=%d",
  200. maxlen, current, extra);
  201. return 1;
  202. }
  203. }
  204. /*
  205. * Pack multiple arguments of a MT_TYPE into a network order bytestream.
  206. * snpack returns the number of bytes actually stored.
  207. */
  208. int
  209. snpack(char *buf, int maxlen, char *id, int type, ...)
  210. {
  211. va_list ap;
  212. u_int16_t c;
  213. u_int32_t l;
  214. u_int64_t q;
  215. int i = 0;
  216. int offset = 0;
  217. if (type > MT_EOT) {
  218. warning("stream type (%d) out of range", type);
  219. return 0;
  220. }
  221. if ( maxlen < 2 ) {
  222. fatal("%s:%d: maxlen too small", __FILE__, __LINE__);
  223. } else {
  224. buf[offset++] = type & 0xff;
  225. }
  226. if (id) {
  227. if ((strlen(id) + 1) >= maxlen) {
  228. return 0;
  229. } else {
  230. strncpy(&buf[offset], id, maxlen-1);
  231. offset += strlen(id);
  232. }
  233. }
  234. buf[offset++] = '\0';
  235. va_start(ap, type);
  236. while (streamform[type].form[i] != '\0'){
  237. /* check for buffer overflow */
  238. if (checklen(maxlen, offset, bytelenvar(streamform[type].form[i])))
  239. return offset;
  240. switch (streamform[type].form[i]) {
  241. case 'c':
  242. c = va_arg(ap, u_int16_t);
  243. c = htons(c);
  244. bcopy(&c, buf + offset, sizeof(u_int16_t));
  245. offset += sizeof(u_int16_t);
  246. break;
  247. case 'l':
  248. l = va_arg(ap, u_int32_t);
  249. l = htonl(l);
  250. bcopy(&l, buf + offset, sizeof(u_int32_t));
  251. offset += sizeof(u_int32_t);
  252. break;
  253. case 'L':
  254. q = va_arg(ap, u_int64_t);
  255. q = htonq(q);
  256. bcopy(&q, buf + offset, sizeof(u_int64_t));
  257. offset += sizeof(u_int64_t);
  258. break;
  259. default:
  260. warning("unknown stream format identifier");
  261. return 0;
  262. }
  263. i++;
  264. }
  265. va_end(ap);
  266. return offset;
  267. }
  268. /*
  269. * Unpack a packedstream in buf into a struct packetstream. Returns the number
  270. * of bytes actually read.
  271. *
  272. * Note that this function does "automatic" bounds checking; it uses a
  273. * description of the packedstream (streamform) to parse the actual bytes. This
  274. * description corresponds to the amount of bytes that will fit inside the
  275. * packedstream structure. */
  276. int
  277. sunpack(char *buf, struct packedstream *ps)
  278. {
  279. char *in, *out;
  280. int i=0;
  281. int type;
  282. u_int16_t c;
  283. u_int32_t l;
  284. u_int64_t q;
  285. bzero(ps, sizeof(struct packedstream));
  286. in = buf;
  287. if ((*in) > MT_EOT) {
  288. warning("unpack failure: stream type (%d) out of range", (*in));
  289. return -1;
  290. }
  291. type = ps->type = (*in);
  292. in++;
  293. if ((*in) != '\0') {
  294. strncpy(ps->args, in, sizeof(ps->args));
  295. ps->args[sizeof(ps->args)-1]='\0';
  296. in += strlen(ps->args);
  297. } else {
  298. ps->args[0] = '\0';
  299. }
  300. in++;
  301. out = (char *)(&ps->data);
  302. while (streamform[type].form[i] != '\0') {
  303. switch (streamform[type].form[i]) {
  304. case 'c':
  305. c = *((u_int16_t *)in);
  306. c = ntohs(c);
  307. bcopy(&c, (void *)out, sizeof(u_int16_t));
  308. in += sizeof(u_int16_t);
  309. out += sizeof(u_int16_t);
  310. break;
  311. case 'l':
  312. l = *((u_int32_t *)in);
  313. l = ntohl(l);
  314. bcopy(&l, (void *)out, sizeof(u_int32_t));
  315. in += sizeof(u_int32_t);
  316. out += sizeof(u_int32_t);
  317. break;
  318. case 'L':
  319. q = *((u_int64_t *)in);
  320. q = ntohq(q);
  321. bcopy(&q, (void *)out, sizeof(u_int64_t));
  322. in += sizeof(u_int64_t);
  323. out += sizeof(u_int64_t);
  324. break;
  325. default:
  326. warning("unknown stream format identifier");
  327. return 0;
  328. }
  329. i++;
  330. }
  331. return (in - buf);
  332. }
  333. /* Get the RRD or 'pretty' ascii representation of packedstream */
  334. int
  335. ps2strn(struct packedstream *ps, char *buf, const int maxlen, int pretty)
  336. {
  337. float c;
  338. u_int64_t q;
  339. u_int32_t l;
  340. int i=0;
  341. char *formatstr;
  342. char *in, *out;
  343. char vartype;
  344. in = (char *)(&ps->data);
  345. out = (char *)buf;
  346. while ((vartype = streamform[ps->type].form[i]) != '\0') {
  347. /* check buffer overflow */
  348. if (checklen(maxlen, (out-buf), strlenvar(vartype)))
  349. return 0;
  350. switch (pretty) {
  351. case PS2STR_PRETTY:
  352. formatstr = formatstrvar(vartype);
  353. break;
  354. case PS2STR_RRD:
  355. formatstr = rrdstrvar(vartype);
  356. break;
  357. default:
  358. warning("%s:%d: unknown pretty identifier", __FILE__, __LINE__);
  359. return 0;
  360. }
  361. switch (vartype) {
  362. case 'c':
  363. c = (*((u_int16_t *)in) / 10);
  364. snprintf(out, strlenvar(vartype), formatstr, c);
  365. in += sizeof(u_int16_t);
  366. break;
  367. case 'l':
  368. l = *((u_int32_t *)in);
  369. snprintf(out, strlenvar(vartype), formatstr, l);
  370. in += sizeof(u_int32_t);
  371. break;
  372. case 'L':
  373. q = *((u_int64_t *)in);
  374. snprintf(out, strlenvar(vartype), formatstr, q);
  375. in += sizeof(u_int64_t);
  376. break;
  377. default:
  378. warning("Unknown stream format identifier");
  379. return 0;
  380. }
  381. out += strlen(out);
  382. i++;
  383. }
  384. return (out - buf);
  385. }
  386. struct stream *
  387. create_stream(int type, char *args)
  388. {
  389. struct stream *p;
  390. if (type < 0 || type >= MT_EOT)
  391. fatal("%s:%d: internal error: stream type unknown", __FILE__, __LINE__);
  392. p = (struct stream *)xmalloc(sizeof(struct stream));
  393. bzero(p, sizeof(struct stream));
  394. p->type = type;
  395. if (args != NULL)
  396. p->args = xstrdup(args);
  397. return p;
  398. }
  399. /* Find the stream handle in a source */
  400. struct stream *
  401. find_source_stream(struct source *source, int type, char *args)
  402. {
  403. struct stream *p;
  404. if (source == NULL)
  405. return NULL;
  406. SLIST_FOREACH(p, &source->sl, streams) {
  407. if ((p->type == type)
  408. && (((void *)args != (void *)p != NULL)
  409. && strncmp(args, p->args, _POSIX2_LINE_MAX) == 0))
  410. return p;
  411. }
  412. return NULL;
  413. }
  414. /* Add a stream to a source */
  415. struct stream *
  416. add_source_stream(struct source *source, int type, char *args)
  417. {
  418. struct stream *p;
  419. if (source == NULL)
  420. return NULL;
  421. if (find_source_stream(source, type, args) != NULL)
  422. return NULL;
  423. p = create_stream(type, args);
  424. SLIST_INSERT_HEAD(&source->sl, p, streams);
  425. return p;
  426. }
  427. /* Find a stream in a mux */
  428. struct stream *
  429. find_mux_stream(struct mux *mux, int type, char *args)
  430. {
  431. struct stream *p;
  432. if (mux == NULL)
  433. return NULL;
  434. SLIST_FOREACH(p, &mux->sl, streams) {
  435. if ((p->type == type)
  436. && (((void *)args != (void *)p != NULL)
  437. && strncmp(args, p->args, _POSIX2_LINE_MAX) == 0))
  438. return p;
  439. }
  440. return NULL;
  441. }
  442. /* Add a stream to a mux */
  443. struct stream *
  444. add_mux_stream(struct mux *mux, int type, char *args)
  445. {
  446. struct stream *p;
  447. if (mux == NULL)
  448. return NULL;
  449. if (find_mux_stream(mux, type, args) != NULL)
  450. return NULL;
  451. p = create_stream(type, args);
  452. SLIST_INSERT_HEAD(&mux->sl, p, streams);
  453. return p;
  454. }
  455. /* Find a source by name in a sourcelist */
  456. struct source *
  457. find_source(struct sourcelist *sol, char *name)
  458. {
  459. struct source *p;
  460. if (sol == NULL || SLIST_EMPTY(sol))
  461. return NULL;
  462. SLIST_FOREACH(p, sol, sources) {
  463. if (((void *)name != (void *)p != NULL)
  464. && strncmp(name, p->name, _POSIX2_LINE_MAX) == 0)
  465. return p;
  466. }
  467. return NULL;
  468. }
  469. /* Find a source by ip in a sourcelist */
  470. struct source *
  471. find_source_ip(struct sourcelist *sol, u_int32_t ip)
  472. {
  473. struct source *p;
  474. if (sol == NULL || SLIST_EMPTY(sol))
  475. return NULL;
  476. SLIST_FOREACH(p, sol, sources) {
  477. if (p->ip == ip)
  478. return p;
  479. }
  480. return NULL;
  481. }
  482. /* Add a source with to a sourcelist */
  483. struct source *
  484. add_source(struct sourcelist *sol, char *name)
  485. {
  486. struct source* p;
  487. if (sol == NULL)
  488. return NULL;
  489. if (find_source(sol, name) != NULL)
  490. return NULL;
  491. p = (struct source *)xmalloc(sizeof(struct source));
  492. bzero(p, sizeof(struct source));
  493. p->name = xstrdup(name);
  494. SLIST_INSERT_HEAD(sol, p, sources);
  495. return p;
  496. }
  497. /* Find a mux by name in a muxlist */
  498. struct mux *
  499. find_mux(struct muxlist *mul, char *name)
  500. {
  501. struct mux *p;
  502. if (mul == NULL || SLIST_EMPTY(mul))
  503. return NULL;
  504. SLIST_FOREACH(p, mul, muxes) {
  505. if (((void *)name != (void *)p != NULL)
  506. && strncmp(name, p->name, _POSIX2_LINE_MAX) == 0)
  507. return p;
  508. }
  509. return NULL;
  510. }
  511. /* Add a mux to a muxlist */
  512. struct mux *
  513. add_mux(struct muxlist *mul, char *name)
  514. {
  515. struct mux* p;
  516. if (mul == NULL)
  517. return NULL;
  518. if (find_mux(mul, name) != NULL)
  519. return NULL;
  520. p = (struct mux *)xmalloc(sizeof(struct mux));
  521. bzero(p, sizeof(struct mux));
  522. p->name = xstrdup(name);
  523. SLIST_INSERT_HEAD(mul, p, muxes);
  524. return p;
  525. }
  526. /* Rename a mux */
  527. struct mux *
  528. rename_mux(struct muxlist *mul, struct mux *mux, char *name)
  529. {
  530. if (mul == NULL || mux == NULL)
  531. return NULL;
  532. if (find_mux(mul, name) != NULL)
  533. return NULL;
  534. if (mux->name != NULL)
  535. xfree(mux->name);
  536. mux->name = xstrdup(name);
  537. return mux;
  538. }
  539. void
  540. free_muxlist(struct muxlist *mul)
  541. {
  542. struct mux *p, *np;
  543. if (mul == NULL || SLIST_EMPTY(mul))
  544. return;
  545. p = SLIST_FIRST(mul);
  546. while ( p ) {
  547. np = SLIST_NEXT(p, muxes);
  548. if (p->name != NULL) xfree(p->name);
  549. close(p->clientsocket);
  550. close(p->monsocket);
  551. free_streamlist(&p->sl);
  552. xfree(p);
  553. p = np;
  554. }
  555. }
  556. void
  557. free_streamlist(struct streamlist *sl)
  558. {
  559. struct stream *p, *np;
  560. if (sl == NULL || SLIST_EMPTY(sl))
  561. return;
  562. p = SLIST_FIRST(sl);
  563. while ( p ) {
  564. np = SLIST_NEXT(p, streams);
  565. if (p->args != NULL) xfree(p->args);
  566. if (p->file != NULL) xfree(p->file);
  567. xfree(p);
  568. p = np;
  569. }
  570. }
  571. void
  572. free_sourcelist(struct sourcelist *sol)
  573. {
  574. struct source *p, *np;
  575. if (sol == NULL || SLIST_EMPTY(sol))
  576. return;
  577. p = SLIST_FIRST(sol);
  578. while ( p ) {
  579. np = SLIST_NEXT(p, sources);
  580. if (p->name != NULL) xfree(p->name);
  581. free_streamlist(&p->sl);
  582. xfree(p);
  583. p = np;
  584. }
  585. }
  586. /* Calculate maximum buffer space needed for a single mon hit */
  587. int
  588. calculate_churnbuffer(struct sourcelist *sol) {
  589. struct source *source;
  590. struct stream *stream;
  591. int prefixlen;
  592. int maxlen;
  593. int len;
  594. int n;
  595. /* determine length of a timestamp + ip as strings */
  596. prefixlen = (sizeof(time_t)*3) + strlen(":") + 15 + strlen(":");
  597. len = n = 0;
  598. source = NULL;
  599. stream = NULL;
  600. maxlen = 0;
  601. /* determine maximum string size for a single source */
  602. SLIST_FOREACH(source, sol, sources) {
  603. len = prefixlen;
  604. SLIST_FOREACH(stream, &source->sl, streams) {
  605. len += strlen(type2str(stream->type)) + strlen(":");
  606. len += strlen(stream->args) + strlen(":");
  607. len += strlentype(stream->type);
  608. n++;
  609. }
  610. if (len > maxlen) maxlen = len;
  611. }
  612. return maxlen;
  613. }
  614. /* Big endian CRC32 */
  615. u_int32_t
  616. crc32(const void *buf, unsigned int len)
  617. {
  618. u_int8_t *p;
  619. u_int32_t crc;
  620. crc = 0xffffffff;
  621. for (p = (u_int8_t *) buf; len > 0; ++p, --len)
  622. crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
  623. return ~crc;
  624. }
  625. /* Init table for CRC32 */
  626. void
  627. init_crc32()
  628. {
  629. unsigned int i, j;
  630. u_int32_t c;
  631. for (i = 0; i < 256; ++i) {
  632. c = i << 24;
  633. for (j = 8; j > 0; --j)
  634. c = c & 0x80000000 ? (c << 1) ^ MON_CRCPOLY : (c << 1);
  635. crc32_table[i] = c;
  636. }
  637. }