Example 3. Checking CRC Values: check_crc.c

#include <stdio.h> #include <crc_tbl.h> /* gen_crc() - computes the CRC value of data using the CRC algorithm ID */ /* specified. Found in ref_crc.c */ unsigned long gen_crc(int id, const unsigned char *data, size_t len); unsigned int my_check_CRC(CRC_TABLE *tp) { int i; unsigned int ret_val = 1; uint32_t my_crc; printf("\n\nTABLE INFO: rec size=%d, num_rec=%d.", tp->rec_size, tp->num_recs); for (i = 0; i < tp->num_recs; i++) { CRC_RECORD crc_rec = tp->recs[i]; /* COMPUTE CRC OF DATA STARTING AT crc_rec.addr */ /* FOR crc_rec.size UNITS. USE */ /* crc_rec.crc_alg_ID to select algorithm. */ /* COMPARE COMPUTED VALUE TO crc_rec.crc_value. */ my_crc = gen_crc(crc_rec.crc_alg_ID, (unsigned char *)crc_rec.addr, crc_rec.size); #if defined(__LARGE_CODE_MODEL__) && !defined(__LARGE_DATA_MODEL__) printf("\nCRC record: alg=%x, addr=%lx, size=%lx, crc=%lx, my_crc=%x.", crc_rec.crc_alg_ID, crc_rec.addr, crc_rec.size, crc_rec.crc_value, my_crc); #else printf("\nCRC record: alg=%x, addr=%x, size=%x, crc=%lx, my_crc=%lx.", crc_rec.crc_alg_ID, crc_rec.addr, crc_rec.size, crc_rec.crc_value, my_crc); #endif if (my_crc == crc_rec.crc_value) printf("\nCRCs match for record %d.\n", i); else { ret_val = 0; printf("\nCRCs DO NOT match for record %d.\n", i); } } return ret_val; }