static int calc_and_compare_checksum(const unsigned char *buf, size_t len, uint16_t expected) { uint16_t result = fletcher16(buf, len); return result == expected; }
bool Packet::checkHeader() { bool ok = false; quint16 headerChecksum = header_.head_checksum; header_.head_checksum = 0; quint16 hchk = fletcher16((quint8*)&header_,HEADER_LENGTH); ok = hchk == headerChecksum; header_.head_checksum = headerChecksum; return ok; }
int main (int argc, char** argv) { int n = 200; double p = .05; const char* ifname = NULL; const char* ofname = NULL; //args extern char* optarg; const char* optstring = "hn:d:p:o:i:"; int c; while ((c = getopt(argc, argv, optstring)) != -1) { switch (c) { case 'h': fprintf(stderr, "%s", usage); return -1; case 'n': n = atoi(optarg); break; case 'p': p = atof(optarg); break; case 'o': ofname = optarg; break; case 'i': ifname = optarg; break; } } //make graph + output int* l = gen_graph(n,p); if(ifname) write_matrix(ifname, n, l); double start = omp_get_wtime(); infinitize(n,l); floyd(l,n); deinfinitize(n,l); double end = omp_get_wtime(); printf("== OpenMP with %d threads\n", omp_get_max_threads()); printf("n: %d\n", n); printf("p: %g\n", p); printf("Time: %g sec\n", (end-start)); printf("Check: %X\n", fletcher16(l, n*n)); //output if(ofname) write_matrix(ofname,n,l); free(l); return 0; }
static void test_checksum_fletcher16_0to1_undetected(void) { /* fletcher cannot distinguish between all 0 and all 1 segments */ unsigned char buf0[16] = { 0xA1, 0xA1, 0xA1, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x1A, 0x1A, 0x1A, }; uint32_t expect = fletcher16(buf0, sizeof(buf0)); unsigned char buf1[16] = { 0xA1, 0xA1, 0xA1, 0xA1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0x1A, 0x1A, 0x1A, }; TEST_ASSERT(calc_and_compare_checksum(buf1, sizeof(buf1), expect)); }