int main(int argc, char * const *argv) { if (argc == 2) { return do_crc(argv[1], 0); } else if ((argc == 4) && (strcmp(argv[1], "-v") == 0)) { char *endptr, *nptr = argv[2]; unsigned ver = strtoul(nptr, &endptr, 0); if (*nptr != '\0' && *endptr == '\0') return do_crc(argv[3], ver); } fprintf(stderr, "Usage: crcit [-v version] <image>\n"); return EXIT_FAILURE; }
int main() { const size_t data_size = (char *)main_end - (char *)main; CRC_BYTE buffer[data_size + sizeof (CRC_STATE)]; printf(DEB("data_size = 0x%x\n"), data_size); memcpy(buffer, main, data_size); add_crc(0, buffer, sizeof buffer, crc32ieee8023); fprintbuf(stdout, sizeof buffer, buffer, DEB("")); printf(DEB("do_crc(buffer) -> 0x%08x\n"), do_crc(0, buffer, data_size, crc32ieee8023)); printf(DEB("do_crc(buffer + CRC) -> 0x%08x\n"), do_crc(0, buffer, sizeof buffer, crc32ieee8023)); }
static void packet_finalize(void) { u16 crc16; crc16 = do_crc(0, packet.buffer, packet_size - sizeof(u16)); if(flags.hanmode){ packet.han.crc16 = crc16; } else{ packet.pbl.crc16 = crc16; } }
unsigned short crc_16(unsigned char* ptr, int length, unsigned short start) { unsigned short crc; crc = start; while (length) { crc = do_crc(crc, *ptr); ptr++; length--; } return crc; }
static int packet_check() { u16 rcrc16, crc16 = do_crc(0, (u8 *) packet.buffer, packet_size - sizeof(u16)); rcrc16 = (flags.hanmode) ? packet.han.crc16 : packet.pbl.crc16; debug(DEBUG_ACTION, "Rx CRC: 0x%04X, Calc CRC 0x%04X", rcrc16, crc16); if(crc16 == rcrc16) return PASS; else return FAIL; }